Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
/**** dstring.h --- String manipulation.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 **** Commentary:
36
 *
37
 ***=== INTRODUCTION =========================================================
38
 *
39
 * This file specifies the interface to a string manipulation facility.  There
40
 * are two types of strings supported: nstrings (strings are stored as a
41
 * length, and a vector of characters), and dstrings which are only of use
42
 * when it is necessary to append characters to a string one at a time with
43
 * reasonable efficiency.
44
 *
45
 * Null pointers are not valid as nstrings or dstrings. Passing a null pointer
46
 * as the argument to a function will have an undefined effect (on many
47
 * machines the program will abort, but this is not guaranteed).
48
 *
49
 ***=== TYPES ================================================================
50
 *
51
 ** Type:	NStringT
52
 ** Type:	NStringP
53
 ** Repr:	<private>
54
 *
55
 * This is the nstring type.  These strings may contain null characters.
56
 *
57
 ** Type:	DStringT
58
 ** Type:	DStringP
59
 ** Repr:	<private>
60
 *
61
 * This is the dstring type.  It is only for appending characters and C
62
 * strings to.  Once it has been completely initialised, it should be
63
 * converted to one of the other string types.
64
 *
65
 ***=== FUNCTIONS ============================================================
66
 *
67
 ** Function:	void			nstring_init
68
 *			PROTO_S ((NStringP nstring))
69
 ** Exceptions:
70
 *
71
 * This function initialises the specified nstring to be an empty nstring.
72
 *
73
 ** Function:	void			nstring_init_length
74
 *			PROTO_S ((NStringP nstring, unsigned length))
75
 ** Exceptions:	XX_dalloc_no_memory
76
 *
77
 * This function initialises the specified nstring to be an nstring of the
78
 * specified length.  The initial contents are unspecified.
79
 *
80
 ** Function:	void			nstring_assign
81
 *			PROTO_S ((NStringP to, NStringP from))
82
 ** Exceptions:
83
 *
84
 * This function assigns the from nstring to the to nstring.  The from nstring
85
 * should not be used afterwards, without reinitialising it.
86
 *
87
 ** Function:	void			nstring_copy_cstring
88
 *			PROTO_S ((NStringP nstring, CStringP cstring))
89
 ** Exceptions:	XX_dalloc_no_memory
90
 *
91
 * This function initialises the specified nstring from the content of the
92
 * specified cstring.
93
 *
94
 ** Function:	void			nstring_insert_cstring
95
 *			PROTO_S ((NStringP nstring, CStringP cstring))
96
 ** Exceptions:
97
 *
98
 * This function inserts the specified cstring into the specified nstring.
99
 * Sufficient characters are copied to fill up the nstring.
100
 *
101
 ** Function:	void			nstring_copy
102
 *			PROTO_S ((NStringP to, NStringP from))
103
 ** Exceptions:	XX_dalloc_no_memory
104
 *
105
 * This function copies the specified from nstring into the specified to
106
 * nstring.
107
 *
108
 ** Function:	CStringP		nstring_to_cstring
109
 *			PROTO_S ((NStringP nstring))
110
 ** Exceptions:	XX_dalloc_no_memory
111
 *
112
 * This function returns a dynamically allocated cstring copy of the specified
113
 * nstring.  If the nstring contains null characters, then the characters
114
 * after the first null will be ignored in the cstring (although they will
115
 * still be part of it).
116
 *
117
 ** Function:	unsigned		nstring_hash_value
118
 *			PROTO_S ((NStringP nstring))
119
 ** Exceptions:
120
 *
121
 * This function returns the hash value associated with the specified nstring.
122
 * This value is guaranteed to be identical for all nstrings with the same
123
 * content.
124
 *
125
 ** Function:	unsigned		nstring_length
126
 *			PROTO_S ((NStringP nstring))
127
 ** Exceptions:
128
 *
129
 * This function returns the length of the specified nstring.
130
 *
131
 ** Function:	CStringP		nstring_contents
132
 *			PROTO_S ((NStringP nstring))
133
 ** Exceptions:
134
 *
135
 * This function returns the contents of the specified nstring.
136
 *
137
 ** Function:	CmpT			nstring_compare
138
 *			PROTO_S ((NStringP nstring1, NStringP nstring2))
139
 ** Exceptions:
140
 *
141
 * This function returns ``CMP_LT'', ``CMP_EQ'', or ``CMP_GT'', depending on
142
 * whether the content of nstring1 is lexicographically less than, equal to,
143
 * or greater than the content of nstring2.
144
 *
145
 ** Function:	BoolT			nstring_equal
146
 *			PROTO_S ((NStringP nstring1, NStringP nstring2))
147
 ** Exceptions:
148
 *
149
 * This function returns true if the specified nstrings have the same content,
150
 * and false otherwise.
151
 *
152
 ** Function:	BoolT			nstring_ci_equal
153
 *			PROTO_S ((NStringP nstring1, NStringP nstring2))
154
 ** Exceptions:
155
 *
156
 * This function returns true if the specified nstrings have the same content
157
 * (ignoring differences in case), and false otherwise.
158
 *
159
 ** Function:	BoolT			nstring_contains
160
 *			PROTO_S ((NStringP nstring, char c))
161
 ** Exceptions:
162
 *
163
 * This function returns true if the specified nstring contains the specified
164
 * character, and false otherwise.
165
 *
166
 ** Function:	BoolT			nstring_is_prefix
167
 *			PROTO_S ((NStringP nstring1, NStringP nstring2))
168
 ** Exceptions:
169
 *
170
 * This function returns true if the second nstring is a prefix of the first
171
 * nstring, and false otherwise.
172
 *
173
 ** Function:	void			nstring_destroy
174
 *			PROTO_S ((NStringP nstring))
175
 ** Exceptions:
176
 *
177
 * This function deallocates the contents of the specified nstring.
178
 *
179
 ** Function:	void			write_nstring
180
 *			PROTO_S ((OStreamP stream, NStringP nstring))
181
 ** Exceptions:	XX_dalloc_no_memory, XX_ostream_write_error
182
 *
183
 * This function writes the content of the specified nstring to the specified
184
 * ostream.
185
 *
186
 ** Function:	void			dstring_init
187
 *			PROTO_S ((DStringP dstring))
188
 ** Exceptions:	XX_dalloc_no_memory
189
 *
190
 * This function initialises the specified dstring to be an empty dstring.
191
 *
192
 ** Function:	unsigned		dstring_length
193
 *			PROTO_S ((DStringP dstring))
194
 ** Exceptions:
195
 *
196
 * This function returns the length of the specified dstring.
197
 *
198
 ** Function:	void			dstring_append_char
199
 *			PROTO_S ((DStringP dstring, char c))
200
 ** Exceptions:	XX_dalloc_no_memory
201
 *
202
 * This function appends the specified character to the specified dstring.
203
 *
204
 ** Function:	void			dstring_append_cstring
205
 *			PROTO_S ((DStringP dstring, CStringP cstring)
206
 ** Exceptions:	XX_dalloc_no_memory
207
 *
208
 * This function appends the content of the specified cstring to the specified
209
 * dstring.
210
 *
211
 ** Function:	void			dstring_append_nstring
212
 *			PROTO_S ((DStringP dstring, NStringP nstring)
213
 ** Exceptions:	XX_dalloc_no_memory
214
 *
215
 * This function appends the content of the specified nstring to the specified
216
 * dstring.
217
 *
218
 ** Function:	BoolT			dstring_last_char_equal
219
 *			PROTO_S ((DStringP dstring, char c))
220
 ** Exceptions:
221
 *
222
 * This function returns true if the last character of the specified dstring
223
 * is the same as the specified character, and false otherwise.  If the
224
 * dstring is empty, then false is always returned.
225
 *
226
 ** Function:	void			dstring_to_nstring
227
 *			PROTO_S ((DStringP dstring, NStringP nstring_ref))
228
 ** Exceptions:	XX_dalloc_no_memory
229
 *
230
 * This function copies the content of the specified dstring into the
231
 * specified nstring.
232
 *
233
 ** Functions:	CStringP		dstring_to_cstring
234
 *			PROTO_S ((DStringP dstring))
235
 ** Exceptions:	XX_dalloc_no_memory
236
 *
237
 * This function copies the content of the specified dstring into a
238
 * dynamically allocated cstring, and returns it.
239
 *
240
 ** Function:	CStringP		dstring_destroy_to_cstring
241
 *			PROTO_S ((DStringP dstring))
242
 ** Exceptions:	XX_dalloc_no_memory
243
 *
244
 * This function does the equivalent of a call to ``dstring_to_cstring''
245
 * followed by a call to ``dstring_destroy''.  It returns a cstring that is
246
 * normally the internal cstring of the dstring (if there isn't enough room
247
 * for a null character at the end, then the cstring will need to be
248
 * reallocated).
249
 *
250
 ** Function:	void			dstring_destroy
251
 *			PROTO_S ((DStringP dstring))
252
 ** Exceptions:
253
 *
254
 * This function deallocates the contents of the specified dstring.
255
 *
256
 **** Change log:
257
 * $Log: dstring.h,v $
258
 * Revision 1.1.1.1  1998/01/17  15:57:17  release
259
 * First version to be checked into rolling release.
260
 *
261
 * Revision 1.2  1994/12/12  11:44:35  smf
262
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
263
 * OSSG C Coding Standards.
264
 *
265
 * Revision 1.1.1.1  1994/07/25  16:05:49  smf
266
 * Initial import of library shared files.
267
 *
268
**/
269
 
270
/****************************************************************************/
271
 
272
#ifndef H_DSTRING
273
#define H_DSTRING
274
 
275
#include "os-interface.h"
276
#include "cstring.h"
277
#include "dalloc.h"
278
#include "ostream.h"
279
 
280
/*--------------------------------------------------------------------------*/
281
 
282
typedef struct NStringT {
283
    unsigned			length;
284
    CStringP			contents;
285
} NStringT, *NStringP;
286
 
287
typedef struct DStringT {
288
    unsigned			length;
289
    unsigned			max_length;
290
    CStringP			contents;
291
} DStringT, *DStringP;
292
 
293
/*--------------------------------------------------------------------------*/
294
 
295
extern void			nstring_init
296
	PROTO_S ((NStringP));
297
extern void			nstring_init_length
298
	PROTO_S ((NStringP, unsigned));
299
extern void			nstring_assign
300
	PROTO_S ((NStringP, NStringP));
301
extern void			nstring_copy_cstring
302
	PROTO_S ((NStringP, CStringP));
303
extern void			nstring_insert_cstring
304
	PROTO_S ((NStringP, CStringP));
305
extern void			nstring_copy
306
	PROTO_S ((NStringP, NStringP));
307
extern CStringP			nstring_to_cstring
308
	PROTO_S ((NStringP));
309
extern unsigned			nstring_hash_value
310
	PROTO_S ((NStringP));
311
extern unsigned			nstring_length
312
	PROTO_S ((NStringP));
313
extern CStringP			nstring_contents
314
	PROTO_S ((NStringP));
315
extern CmpT			nstring_compare
316
	PROTO_S ((NStringP, NStringP));
317
extern BoolT			nstring_equal
318
	PROTO_S ((NStringP, NStringP));
319
extern BoolT			nstring_ci_equal
320
	PROTO_S ((NStringP, NStringP));
321
extern BoolT			nstring_contains
322
	PROTO_S ((NStringP, char));
323
extern BoolT			nstring_is_prefix
324
	PROTO_S ((NStringP, NStringP));
325
extern void			nstring_destroy
326
	PROTO_S ((NStringP));
327
 
328
extern void			write_nstring
329
	PROTO_S ((OStreamP, NStringP));
330
 
331
extern void			dstring_init
332
	PROTO_S ((DStringP));
333
extern unsigned			dstring_length
334
	PROTO_S ((DStringP));
335
extern void			dstring_append_char
336
	PROTO_S ((DStringP, char));
337
extern void			dstring_append_cstring
338
	PROTO_S ((DStringP, CStringP));
339
extern void			dstring_append_nstring
340
	PROTO_S ((DStringP, NStringP));
341
extern BoolT			dstring_last_char_equal
342
	PROTO_S ((DStringP, char));
343
extern void			dstring_to_nstring
344
	PROTO_S ((DStringP, NStringP));
345
extern CStringP			dstring_to_cstring
346
	PROTO_S ((DStringP));
347
extern CStringP			dstring_destroy_to_cstring
348
	PROTO_S ((DStringP));
349
extern void			dstring_destroy
350
	PROTO_S ((DStringP));
351
 
352
/*--------------------------------------------------------------------------*/
353
 
354
#ifdef FS_FAST
355
#define nstring_length(s) ((s)->length)
356
#define nstring_contents(s) ((s)->contents)
357
#define dstring_length(s) ((s)->length)
358
#endif /* defined (FS_FAST) */
359
 
360
#endif /* !defined (H_DSTRING) */
361
 
362
/*
363
 * Local variables(smf):
364
 * eval: (include::add-path-entry "../os-interface" "../generated")
365
 * end:
366
**/