Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 51... Line 81...
51
 * type definition by including this file.
81
 * type definition by including this file.
52
 *
82
 *
53
 ***=== FUNCTIONS ============================================================
83
 ***=== FUNCTIONS ============================================================
54
 *
84
 *
55
 ** Function:	CStringP		cstring_duplicate
85
 ** Function:	CStringP		cstring_duplicate
56
 *			PROTO_S ((CStringP cstring))
86
 *			(CStringP cstring)
57
 ** Exceptions:	XX_dalloc_no_memory
87
 ** Exceptions:	XX_dalloc_no_memory
58
 *
88
 *
59
 * This function returns a dynamically allocated copy of the specified
89
 * This function returns a dynamically allocated copy of the specified
60
 * cstring.
90
 * cstring.
61
 *
91
 *
62
 ** Function:	CStringP		cstring_duplicate_prefix
92
 ** Function:	CStringP		cstring_duplicate_prefix
63
 *			PROTO_S ((CStringP cstring, unsigned prefix))
93
 *			(CStringP cstring, unsigned prefix)
64
 ** Exceptions:	XX_dalloc_no_memory
94
 ** Exceptions:	XX_dalloc_no_memory
65
 *
95
 *
66
 * This function returns a dynamically allocated copy of the specified prefix
96
 * This function returns a dynamically allocated copy of the specified prefix
67
 * of the specified cstring.  If the cstring is shorter than the prefix
97
 * of the specified cstring.  If the cstring is shorter than the prefix
68
 * length, then only the cstring is used.
98
 * length, then only the cstring is used.
69
 *
99
 *
70
 ** Function:	unsigned		cstring_hash_value
100
 ** Function:	unsigned		cstring_hash_value
71
 *			PROTO_S ((CStringP cstring))
101
 *			(CStringP cstring)
72
 ** Exceptions:
102
 ** Exceptions:
73
 *
103
 *
74
 * This function returns the hash value associated with the specified
104
 * This function returns the hash value associated with the specified
75
 * cstring.  This value is guaranteed to be identical for all cstrings
105
 * cstring.  This value is guaranteed to be identical for all cstrings
76
 * with the same content.
106
 * with the same content.
77
 *
107
 *
78
 ** Function:	unsigned		cstring_length
108
 ** Function:	unsigned		cstring_length
79
 *			PROTO_S ((CStringP cstring))
109
 *			(CStringP cstring)
80
 ** Exceptions:
110
 ** Exceptions:
81
 *
111
 *
82
 * This function returns the length of the specified cstring.
112
 * This function returns the length of the specified cstring.
83
 *
113
 *
84
 ** Function:	BoolT			cstring_equal
114
 ** Function:	BoolT			cstring_equal
85
 *			PROTO_S ((CStringP cstring1, CStringP cstring2))
115
 *			(CStringP cstring1, CStringP cstring2)
86
 ** Exceptions:
116
 ** Exceptions:
87
 *
117
 *
88
 * This function returns true if the specified cstrings have the same
118
 * This function returns true if the specified cstrings have the same
89
 * content, and false otherwise.
119
 * content, and false otherwise.
90
 *
120
 *
91
 ** Function:	BoolT			cstring_ci_equal
121
 ** Function:	BoolT			cstring_ci_equal
92
 *			PROTO_S ((CStringP cstring1, CStringP cstring2))
122
 *			(CStringP cstring1, CStringP cstring2)
93
 ** Exceptions:
123
 ** Exceptions:
94
 *
124
 *
95
 * This function returns true if the specified cstrings have the same
125
 * This function returns true if the specified cstrings have the same
96
 * content (ignoring differences in case), and false otherwise.
126
 * content (ignoring differences in case), and false otherwise.
97
 *
127
 *
98
 ** Function:	BoolT			cstring_to_unsigned
128
 ** Function:	BoolT			cstring_to_unsigned
99
 *			PROTO_S ((CStringP cstring, unsigned *num_ref))
129
 *			(CStringP cstring, unsigned *num_ref)
100
 ** Exceptions:
130
 ** Exceptions:
101
 *
131
 *
102
 * This function parses an unsigned number in cstring.  If there is a valid
132
 * This function parses an unsigned number in cstring.  If there is a valid
103
 * number in the string, it is assigned to the number pointed to by num_ref,
133
 * number in the string, it is assigned to the number pointed to by num_ref,
104
 * and the function returns true; otherwise the function returns false.  The
134
 * and the function returns true; otherwise the function returns false.  The
105
 * function checks for overflow; it will return false if the number is too
135
 * function checks for overflow; it will return false if the number is too
106
 * big.
136
 * big.
107
 *
137
 *
108
 ** Function:	BoolT			cstring_contains
138
 ** Function:	BoolT			cstring_contains
109
 *			PROTO_S ((CStringP cstring, char c))
139
 *			(CStringP cstring, char c)
110
 ** Exceptions:
140
 ** Exceptions:
111
 *
141
 *
112
 * This function returns true if the specified cstring contains the character
142
 * This function returns true if the specified cstring contains the character
113
 * c, and false if it doesn't.
143
 * c, and false if it doesn't.
114
 *
144
 *
115
 ** Function:	CStringP		cstring_find
145
 ** Function:	CStringP		cstring_find
116
 *			PROTO_S ((CStringP cstring, char c))
146
 *			(CStringP cstring, char c)
117
 ** Exceptions:
147
 ** Exceptions:
118
 *
148
 *
119
 * This function returns a pointer to the first occurrence of the specified
149
 * This function returns a pointer to the first occurrence of the specified
120
 * character in the specified cstring, or nil if there is no occurrence.
150
 * character in the specified cstring, or nil if there is no occurrence.
121
 *
151
 *
122
 ** Function:	CStringP		cstring_find_reverse
152
 ** Function:	CStringP		cstring_find_reverse
123
 *			PROTO_S ((CStringP cstring, char c))
153
 *			(CStringP cstring, char c)
124
 ** Exceptions:
154
 ** Exceptions:
125
 *
155
 *
126
 * This function returns a pointer to the last occurrence of the specified
156
 * This function returns a pointer to the last occurrence of the specified
127
 * character in the specified cstring, or nil if there is no occurrence.
157
 * character in the specified cstring, or nil if there is no occurrence.
128
 *
158
 *
Line 151... Line 181...
151
#include "os-interface.h"
181
#include "os-interface.h"
152
#include "dalloc.h"
182
#include "dalloc.h"
153
 
183
 
154
/*--------------------------------------------------------------------------*/
184
/*--------------------------------------------------------------------------*/
155
 
185
 
156
extern CStringP			cstring_duplicate
186
extern CStringP			cstring_duplicate(CStringP);
157
	PROTO_S ((CStringP));
-
 
158
extern CStringP			cstring_duplicate_prefix
187
extern CStringP			cstring_duplicate_prefix(CStringP, unsigned);
159
	PROTO_S ((CStringP, unsigned));
-
 
160
extern unsigned			cstring_hash_value
188
extern unsigned			cstring_hash_value(CStringP);
161
	PROTO_S ((CStringP));
-
 
162
extern unsigned			cstring_length
189
extern unsigned			cstring_length(CStringP);
163
	PROTO_S ((CStringP));
-
 
164
extern BoolT			cstring_equal
190
extern BoolT			cstring_equal(CStringP, CStringP);
165
	PROTO_S ((CStringP, CStringP));
-
 
166
extern BoolT			cstring_ci_equal
191
extern BoolT			cstring_ci_equal(CStringP, CStringP);
167
	PROTO_S ((CStringP, CStringP));
-
 
168
extern BoolT			cstring_to_unsigned
192
extern BoolT			cstring_to_unsigned(CStringP, unsigned *);
169
	PROTO_S ((CStringP, unsigned *));
-
 
170
extern BoolT			cstring_starts
193
extern BoolT			cstring_starts(CStringP, CStringP);
171
	PROTO_S ((CStringP, CStringP));
-
 
172
extern BoolT			cstring_contains
194
extern BoolT			cstring_contains(CStringP, char);
173
	PROTO_S ((CStringP, char));
-
 
174
extern CStringP			cstring_find
195
extern CStringP			cstring_find(CStringP, char);
175
	PROTO_S ((CStringP, char));
-
 
176
extern CStringP			cstring_find_reverse
196
extern CStringP			cstring_find_reverse(CStringP, char);
177
	PROTO_S ((CStringP, char));
-
 
178
extern CStringP			cstring_find_basename
197
extern CStringP			cstring_find_basename(CStringP);
179
	PROTO_S ((CStringP));
-
 
180
 
198
 
181
/*--------------------------------------------------------------------------*/
199
/*--------------------------------------------------------------------------*/
182
 
200
 
183
#ifdef FS_FAST
201
#ifdef FS_FAST
184
#define cstring_length(s) ((unsigned) strlen (s))
202
#define cstring_length(s)		((unsigned)strlen(s))
185
#define cstring_equal(s1, s2) (strcmp ((s1), (s2)) == 0)
203
#define cstring_equal(s1, s2)		(strcmp((s1), (s2)) == 0)
186
#define cstring_contains(s, c) (strchr ((s), (c)) != NIL (CStringP))
204
#define cstring_contains(s, c)		(strchr((s), (c)) != NIL(CStringP))
187
#define cstring_find(s, c) (strchr ((s), (c)))
205
#define cstring_find(s, c)		(strchr((s), (c)))
188
#define cstring_find_reverse(s, c) (strrchr ((s), (c)))
206
#define cstring_find_reverse(s, c)	(strrchr((s), (c)))
189
#endif /* defined (FS_FAST) */
207
#endif /* defined (FS_FAST) */
190
 
208
 
191
#endif /* !defined (H_CSTRING) */
209
#endif /* !defined (H_CSTRING) */