2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**** cstring.h --- C string manipulation.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
**** Commentary:
|
|
|
36 |
*
|
|
|
37 |
***=== INTRODUCTION =========================================================
|
|
|
38 |
*
|
|
|
39 |
* This file defines the C string type and specifies some functions that can
|
|
|
40 |
* be used to manipulate C strings.
|
|
|
41 |
*
|
|
|
42 |
***=== TYPES ================================================================
|
|
|
43 |
*
|
|
|
44 |
** Type: CStringP
|
|
|
45 |
** Repr: char *
|
|
|
46 |
*
|
|
|
47 |
* This is the C string type. It should be used for objects that are
|
|
|
48 |
* strings, not for references to character objects. It is actually defined
|
|
|
49 |
* in the file "os-interface.h" to avoid a circularity in the header files
|
|
|
50 |
* in this directory, but all files outside of this directory should get the
|
|
|
51 |
* type definition by including this file.
|
|
|
52 |
*
|
|
|
53 |
***=== FUNCTIONS ============================================================
|
|
|
54 |
*
|
|
|
55 |
** Function: CStringP cstring_duplicate
|
|
|
56 |
* PROTO_S ((CStringP cstring))
|
|
|
57 |
** Exceptions: XX_dalloc_no_memory
|
|
|
58 |
*
|
|
|
59 |
* This function returns a dynamically allocated copy of the specified
|
|
|
60 |
* cstring.
|
|
|
61 |
*
|
|
|
62 |
** Function: CStringP cstring_duplicate_prefix
|
|
|
63 |
* PROTO_S ((CStringP cstring, unsigned prefix))
|
|
|
64 |
** Exceptions: XX_dalloc_no_memory
|
|
|
65 |
*
|
|
|
66 |
* This function returns a dynamically allocated copy of the specified prefix
|
|
|
67 |
* of the specified cstring. If the cstring is shorter than the prefix
|
|
|
68 |
* length, then only the cstring is used.
|
|
|
69 |
*
|
|
|
70 |
** Function: unsigned cstring_hash_value
|
|
|
71 |
* PROTO_S ((CStringP cstring))
|
|
|
72 |
** Exceptions:
|
|
|
73 |
*
|
|
|
74 |
* This function returns the hash value associated with the specified
|
|
|
75 |
* cstring. This value is guaranteed to be identical for all cstrings
|
|
|
76 |
* with the same content.
|
|
|
77 |
*
|
|
|
78 |
** Function: unsigned cstring_length
|
|
|
79 |
* PROTO_S ((CStringP cstring))
|
|
|
80 |
** Exceptions:
|
|
|
81 |
*
|
|
|
82 |
* This function returns the length of the specified cstring.
|
|
|
83 |
*
|
|
|
84 |
** Function: BoolT cstring_equal
|
|
|
85 |
* PROTO_S ((CStringP cstring1, CStringP cstring2))
|
|
|
86 |
** Exceptions:
|
|
|
87 |
*
|
|
|
88 |
* This function returns true if the specified cstrings have the same
|
|
|
89 |
* content, and false otherwise.
|
|
|
90 |
*
|
|
|
91 |
** Function: BoolT cstring_ci_equal
|
|
|
92 |
* PROTO_S ((CStringP cstring1, CStringP cstring2))
|
|
|
93 |
** Exceptions:
|
|
|
94 |
*
|
|
|
95 |
* This function returns true if the specified cstrings have the same
|
|
|
96 |
* content (ignoring differences in case), and false otherwise.
|
|
|
97 |
*
|
|
|
98 |
** Function: BoolT cstring_to_unsigned
|
|
|
99 |
* PROTO_S ((CStringP cstring, unsigned *num_ref))
|
|
|
100 |
** Exceptions:
|
|
|
101 |
*
|
|
|
102 |
* 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,
|
|
|
104 |
* 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
|
|
|
106 |
* big.
|
|
|
107 |
*
|
|
|
108 |
** Function: BoolT cstring_contains
|
|
|
109 |
* PROTO_S ((CStringP cstring, char c))
|
|
|
110 |
** Exceptions:
|
|
|
111 |
*
|
|
|
112 |
* This function returns true if the specified cstring contains the character
|
|
|
113 |
* c, and false if it doesn't.
|
|
|
114 |
*
|
|
|
115 |
** Function: CStringP cstring_find
|
|
|
116 |
* PROTO_S ((CStringP cstring, char c))
|
|
|
117 |
** Exceptions:
|
|
|
118 |
*
|
|
|
119 |
* 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.
|
|
|
121 |
*
|
|
|
122 |
** Function: CStringP cstring_find_reverse
|
|
|
123 |
* PROTO_S ((CStringP cstring, char c))
|
|
|
124 |
** Exceptions:
|
|
|
125 |
*
|
|
|
126 |
* 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.
|
|
|
128 |
*
|
|
|
129 |
**** Change Log:
|
|
|
130 |
* $Log: cstring.h,v $
|
|
|
131 |
* Revision 1.2 1998/03/16 11:26:34 release
|
|
|
132 |
* Modifications prior to version 4.1.2.
|
|
|
133 |
*
|
|
|
134 |
* Revision 1.1.1.1 1998/01/17 15:57:45 release
|
|
|
135 |
* First version to be checked into rolling release.
|
|
|
136 |
*
|
|
|
137 |
* Revision 1.2 1994/12/12 11:45:26 smf
|
|
|
138 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
139 |
* OSSG C Coding Standards.
|
|
|
140 |
*
|
|
|
141 |
* Revision 1.1.1.1 1994/07/25 16:06:09 smf
|
|
|
142 |
* Initial import of os-interface shared files.
|
|
|
143 |
*
|
|
|
144 |
**/
|
|
|
145 |
|
|
|
146 |
/****************************************************************************/
|
|
|
147 |
|
|
|
148 |
#ifndef H_CSTRING
|
|
|
149 |
#define H_CSTRING
|
|
|
150 |
|
|
|
151 |
#include "os-interface.h"
|
|
|
152 |
#include "dalloc.h"
|
|
|
153 |
|
|
|
154 |
/*--------------------------------------------------------------------------*/
|
|
|
155 |
|
|
|
156 |
extern CStringP cstring_duplicate
|
|
|
157 |
PROTO_S ((CStringP));
|
|
|
158 |
extern CStringP cstring_duplicate_prefix
|
|
|
159 |
PROTO_S ((CStringP, unsigned));
|
|
|
160 |
extern unsigned cstring_hash_value
|
|
|
161 |
PROTO_S ((CStringP));
|
|
|
162 |
extern unsigned cstring_length
|
|
|
163 |
PROTO_S ((CStringP));
|
|
|
164 |
extern BoolT cstring_equal
|
|
|
165 |
PROTO_S ((CStringP, CStringP));
|
|
|
166 |
extern BoolT cstring_ci_equal
|
|
|
167 |
PROTO_S ((CStringP, CStringP));
|
|
|
168 |
extern BoolT cstring_to_unsigned
|
|
|
169 |
PROTO_S ((CStringP, unsigned *));
|
|
|
170 |
extern BoolT cstring_starts
|
|
|
171 |
PROTO_S ((CStringP, CStringP));
|
|
|
172 |
extern BoolT cstring_contains
|
|
|
173 |
PROTO_S ((CStringP, char));
|
|
|
174 |
extern CStringP cstring_find
|
|
|
175 |
PROTO_S ((CStringP, char));
|
|
|
176 |
extern CStringP cstring_find_reverse
|
|
|
177 |
PROTO_S ((CStringP, char));
|
|
|
178 |
extern CStringP cstring_find_basename
|
|
|
179 |
PROTO_S ((CStringP));
|
|
|
180 |
|
|
|
181 |
/*--------------------------------------------------------------------------*/
|
|
|
182 |
|
|
|
183 |
#ifdef FS_FAST
|
|
|
184 |
#define cstring_length(s) ((unsigned) strlen (s))
|
|
|
185 |
#define cstring_equal(s1, s2) (strcmp ((s1), (s2)) == 0)
|
|
|
186 |
#define cstring_contains(s, c) (strchr ((s), (c)) != NIL (CStringP))
|
|
|
187 |
#define cstring_find(s, c) (strchr ((s), (c)))
|
|
|
188 |
#define cstring_find_reverse(s, c) (strrchr ((s), (c)))
|
|
|
189 |
#endif /* defined (FS_FAST) */
|
|
|
190 |
|
|
|
191 |
#endif /* !defined (H_CSTRING) */
|