Line -... |
Line 1... |
- |
|
1 |
/*
|
- |
|
2 |
* Copyright (c) 2002-2006 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 50... |
Line 80... |
50 |
* in this directory, but all files outside of this directory should get the
|
80 |
* in this directory, but all files outside of this directory should get the
|
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(CStringP cstring)
|
56 |
* PROTO_S ((CStringP cstring))
|
- |
|
57 |
** Exceptions: XX_dalloc_no_memory
|
86 |
** Exceptions: XX_dalloc_no_memory
|
58 |
*
|
87 |
*
|
59 |
* This function returns a dynamically allocated copy of the specified
|
88 |
* This function returns a dynamically allocated copy of the specified
|
60 |
* cstring.
|
89 |
* cstring.
|
61 |
*
|
90 |
*
|
62 |
** Function: CStringP cstring_duplicate_prefix
|
91 |
** Function: CStringP cstring_duplicate_prefix(CStringP cstring,
|
63 |
* PROTO_S ((CStringP cstring, unsigned prefix))
|
92 |
* unsigned prefix)
|
64 |
** Exceptions: XX_dalloc_no_memory
|
93 |
** Exceptions: XX_dalloc_no_memory
|
65 |
*
|
94 |
*
|
66 |
* This function returns a dynamically allocated copy of the specified prefix
|
95 |
* This function returns a dynamically allocated copy of the specified prefix
|
67 |
* of the specified cstring. If the cstring is shorter than the prefix
|
96 |
* of the specified cstring. If the cstring is shorter than the prefix
|
68 |
* length, then only the cstring is used.
|
97 |
* length, then only the cstring is used.
|
69 |
*
|
98 |
*
|
70 |
** Function: unsigned cstring_hash_value
|
99 |
** Function: unsigned cstring_hash_value(CStringP cstring)
|
71 |
* PROTO_S ((CStringP cstring))
|
- |
|
72 |
** Exceptions:
|
100 |
** Exceptions:
|
73 |
*
|
101 |
*
|
74 |
* This function returns the hash value associated with the specified
|
102 |
* This function returns the hash value associated with the specified
|
75 |
* cstring. This value is guaranteed to be identical for all cstrings
|
103 |
* cstring. This value is guaranteed to be identical for all cstrings
|
76 |
* with the same content.
|
104 |
* with the same content.
|
77 |
*
|
105 |
*
|
78 |
** Function: unsigned cstring_length
|
106 |
** Function: unsigned cstring_length(CStringP cstring)
|
79 |
* PROTO_S ((CStringP cstring))
|
- |
|
80 |
** Exceptions:
|
107 |
** Exceptions:
|
81 |
*
|
108 |
*
|
82 |
* This function returns the length of the specified cstring.
|
109 |
* This function returns the length of the specified cstring.
|
83 |
*
|
110 |
*
|
84 |
** Function: BoolT cstring_equal
|
- |
|
85 |
* PROTO_S ((CStringP cstring1, CStringP cstring2))
|
111 |
** Function: BoolT cstring_equal(CStringP cstring1, CStringP cstring2)
|
86 |
** Exceptions:
|
112 |
** Exceptions:
|
87 |
*
|
113 |
*
|
88 |
* This function returns true if the specified cstrings have the same
|
114 |
* This function returns true if the specified cstrings have the same
|
89 |
* content, and false otherwise.
|
115 |
* content, and false otherwise.
|
90 |
*
|
116 |
*
|
91 |
** Function: BoolT cstring_ci_equal
|
- |
|
92 |
* PROTO_S ((CStringP cstring1, CStringP cstring2))
|
117 |
** Function: BoolT cstring_ci_equal(CStringP cstring1, CStringP cstring2)
|
93 |
** Exceptions:
|
118 |
** Exceptions:
|
94 |
*
|
119 |
*
|
95 |
* This function returns true if the specified cstrings have the same
|
120 |
* This function returns true if the specified cstrings have the same
|
96 |
* content (ignoring differences in case), and false otherwise.
|
121 |
* content (ignoring differences in case), and false otherwise.
|
97 |
*
|
122 |
*
|
98 |
** Function: BoolT cstring_to_unsigned
|
- |
|
99 |
* PROTO_S ((CStringP cstring, unsigned *num_ref))
|
123 |
** Function: BoolT cstring_to_unsigned(CStringP cstring, unsigned *num_ref)
|
100 |
** Exceptions:
|
124 |
** Exceptions:
|
101 |
*
|
125 |
*
|
102 |
* This function parses an unsigned number in cstring. If there is a valid
|
126 |
* 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,
|
127 |
* 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
|
128 |
* 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
|
129 |
* function checks for overflow; it will return false if the number is too
|
106 |
* big.
|
130 |
* big.
|
107 |
*
|
131 |
*
|
108 |
** Function: BoolT cstring_contains
|
132 |
** Function: BoolT cstring_contains(CStringP cstring, char c)
|
109 |
* PROTO_S ((CStringP cstring, char c))
|
- |
|
110 |
** Exceptions:
|
133 |
** Exceptions:
|
111 |
*
|
134 |
*
|
112 |
* This function returns true if the specified cstring contains the character
|
135 |
* This function returns true if the specified cstring contains the character
|
113 |
* c, and false if it doesn't.
|
136 |
* c, and false if it doesn't.
|
114 |
*
|
137 |
*
|
115 |
** Function: CStringP cstring_find
|
138 |
** Function: CStringP cstring_find(CStringP cstring, char c)
|
116 |
* PROTO_S ((CStringP cstring, char c))
|
- |
|
117 |
** Exceptions:
|
139 |
** Exceptions:
|
118 |
*
|
140 |
*
|
119 |
* This function returns a pointer to the first occurrence of the specified
|
141 |
* 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.
|
142 |
* character in the specified cstring, or nil if there is no occurrence.
|
121 |
*
|
143 |
*
|
122 |
** Function: CStringP cstring_find_reverse
|
144 |
** Function: CStringP cstring_find_reverse(CStringP cstring, char c)
|
123 |
* PROTO_S ((CStringP cstring, char c))
|
- |
|
124 |
** Exceptions:
|
145 |
** Exceptions:
|
125 |
*
|
146 |
*
|
126 |
* This function returns a pointer to the last occurrence of the specified
|
147 |
* 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.
|
148 |
* character in the specified cstring, or nil if there is no occurrence.
|
128 |
*
|
149 |
*
|
Line 149... |
Line 170... |
149 |
#include "dalloc.h"
|
170 |
#include "dalloc.h"
|
150 |
|
171 |
|
151 |
/*--------------------------------------------------------------------------*/
|
172 |
/*--------------------------------------------------------------------------*/
|
152 |
|
173 |
|
153 |
extern CStringP cstring_duplicate
|
174 |
extern CStringP cstring_duplicate
|
154 |
PROTO_S ((CStringP));
|
175 |
(CStringP);
|
155 |
extern CStringP cstring_duplicate_prefix
|
176 |
extern CStringP cstring_duplicate_prefix
|
156 |
PROTO_S ((CStringP, unsigned));
|
177 |
(CStringP, unsigned);
|
157 |
extern unsigned cstring_hash_value
|
178 |
extern unsigned cstring_hash_value
|
158 |
PROTO_S ((CStringP));
|
179 |
(CStringP);
|
159 |
extern unsigned cstring_length
|
180 |
extern unsigned cstring_length
|
160 |
PROTO_S ((CStringP));
|
181 |
(CStringP);
|
161 |
extern BoolT cstring_equal
|
182 |
extern BoolT cstring_equal
|
162 |
PROTO_S ((CStringP, CStringP));
|
183 |
(CStringP, CStringP);
|
163 |
extern BoolT cstring_ci_equal
|
184 |
extern BoolT cstring_ci_equal
|
164 |
PROTO_S ((CStringP, CStringP));
|
185 |
(CStringP, CStringP);
|
165 |
extern BoolT cstring_to_unsigned
|
186 |
extern BoolT cstring_to_unsigned
|
166 |
PROTO_S ((CStringP, unsigned *));
|
187 |
(CStringP, unsigned *);
|
167 |
extern BoolT cstring_contains
|
188 |
extern BoolT cstring_contains
|
168 |
PROTO_S ((CStringP, char));
|
189 |
(CStringP, char);
|
169 |
extern CStringP cstring_find
|
190 |
extern CStringP cstring_find
|
170 |
PROTO_S ((CStringP, char));
|
191 |
(CStringP, char);
|
171 |
extern CStringP cstring_find_reverse
|
192 |
extern CStringP cstring_find_reverse
|
172 |
PROTO_S ((CStringP, char));
|
193 |
(CStringP, char);
|
173 |
|
194 |
|
174 |
/*--------------------------------------------------------------------------*/
|
195 |
/*--------------------------------------------------------------------------*/
|
175 |
|
196 |
|
176 |
#ifdef FS_FAST
|
197 |
#ifdef FS_FAST
|
177 |
#define cstring_length(s) ((unsigned) strlen (s))
|
198 |
#define cstring_length(s) ((unsigned)strlen(s))
|
178 |
#define cstring_equal(s1, s2) (strcmp ((s1), (s2)) == 0)
|
199 |
#define cstring_equal(s1, s2) (strcmp((s1), (s2)) == 0)
|
179 |
#define cstring_contains(s, c) (strchr ((s), (c)) != NIL (CStringP))
|
200 |
#define cstring_contains(s, c) (strchr((s), (c)) != NIL(CStringP))
|
180 |
#define cstring_find(s, c) (strchr ((s), (c)))
|
201 |
#define cstring_find(s, c) (strchr((s), (c)))
|
181 |
#define cstring_find_reverse(s, c) (strrchr ((s), (c)))
|
202 |
#define cstring_find_reverse(s, c) (strrchr((s), (c)))
|
182 |
#endif /* defined (FS_FAST) */
|
203 |
#endif /* defined (FS_FAST) */
|
183 |
|
204 |
|
184 |
#endif /* !defined (H_CSTRING) */
|
205 |
#endif /* !defined (H_CSTRING) */
|