Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
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 62... Line 92...
62
 
92
 
63
/*** Functions for manipulating nstrings.
93
/*** Functions for manipulating nstrings.
64
**/
94
**/
65
 
95
 
66
void
96
void
67
nstring_init PROTO_N ((nstring))
97
nstring_init(NStringP nstring)
68
	     PROTO_T (NStringP nstring)
-
 
69
{
98
{
70
    nstring->length   = 0;
99
    nstring->length   = 0;
71
    nstring->contents = NIL (CStringP);
100
    nstring->contents = NIL(CStringP);
72
}
101
}
73
 
102
 
74
void
103
void
75
nstring_init_length PROTO_N ((nstring, length))
104
nstring_init_length(NStringP nstring, unsigned length)
76
		    PROTO_T (NStringP nstring X
-
 
77
			     unsigned length)
-
 
78
{
105
{
79
    nstring->length   = length;
106
    nstring->length   = length;
80
    nstring->contents = ALLOCATE_VECTOR (char, length);
107
    nstring->contents = ALLOCATE_VECTOR(char, length);
81
}
108
}
82
 
109
 
83
void
110
void
84
nstring_assign PROTO_N ((to, from))
111
nstring_assign(NStringP to, NStringP from)
85
	       PROTO_T (NStringP to X
-
 
86
			NStringP from)
-
 
87
{
112
{
88
    to->length     = nstring_length (from);
113
    to->length     = nstring_length(from);
89
    to->contents   = (from->contents);
114
    to->contents   = (from->contents);
90
}
115
}
91
 
116
 
92
void
117
void
93
nstring_copy_cstring PROTO_N ((nstring, cstring))
118
nstring_copy_cstring(NStringP nstring, CStringP cstring)
94
		     PROTO_T (NStringP nstring X
-
 
95
			      CStringP cstring)
-
 
96
{
119
{
97
    unsigned length = cstring_length (cstring);
120
    unsigned length = cstring_length(cstring);
98
 
121
 
99
    if (length > 0) {
122
    if (length > 0) {
100
	nstring->length   = length;
123
	nstring->length   = length;
101
	nstring->contents = ALLOCATE_VECTOR (char, length);
124
	nstring->contents = ALLOCATE_VECTOR(char, length);
102
	(void) memcpy ((GenericP) (nstring->contents), (GenericP) cstring,
125
	(void)memcpy((GenericP)(nstring->contents), (GenericP)cstring,
103
		       (SizeT) length);
126
		     (SizeT)length);
104
    } else {
127
    } else {
105
	nstring->length   = 0;
128
	nstring->length   = 0;
106
	nstring->contents = NIL (CStringP);
129
	nstring->contents = NIL(CStringP);
107
    }
130
    }
108
}
131
}
109
 
132
 
110
void
133
void
111
nstring_insert_cstring PROTO_N ((nstring, cstring))
134
nstring_insert_cstring(NStringP nstring, CStringP cstring)
112
		       PROTO_T (NStringP nstring X
-
 
113
				CStringP cstring)
-
 
114
{
135
{
115
    unsigned length = nstring_length (nstring);
136
    unsigned length = nstring_length(nstring);
116
 
137
 
117
    if (length > 0) {
138
    if (length > 0) {
118
	(void) memcpy ((GenericP) (nstring->contents), (GenericP) cstring,
139
	(void)memcpy((GenericP)(nstring->contents), (GenericP)cstring,
119
		       (SizeT) length);
140
		     (SizeT)length);
120
    }
141
    }
121
}
142
}
122
 
143
 
123
void
144
void
124
nstring_copy PROTO_N ((to, from))
145
nstring_copy(NStringP to, NStringP from)
125
	     PROTO_T (NStringP to X
-
 
126
		      NStringP from)
-
 
127
{
146
{
128
    unsigned length = nstring_length (from);
147
    unsigned length = nstring_length(from);
129
 
148
 
130
    if (length > 0) {
149
    if (length > 0) {
131
	to->length   = length;
150
	to->length   = length;
132
	to->contents = ALLOCATE_VECTOR (char, length);
151
	to->contents = ALLOCATE_VECTOR(char, length);
133
	(void) memcpy ((GenericP) (to->contents),
152
	(void)memcpy((GenericP)(to->contents),
134
		       (GenericP) (from->contents), (SizeT) length);
153
		     (GenericP)(from->contents), (SizeT)length);
135
    } else {
154
    } else {
136
	to->length   = 0;
155
	to->length   = 0;
137
	to->contents = NIL (CStringP);
156
	to->contents = NIL(CStringP);
138
    }
157
    }
139
}
158
}
140
 
159
 
141
CStringP
160
CStringP
142
nstring_to_cstring PROTO_N ((nstring))
161
nstring_to_cstring(NStringP nstring)
143
		   PROTO_T (NStringP nstring)
-
 
144
{
162
{
145
    unsigned length = nstring_length (nstring);
163
    unsigned length = nstring_length(nstring);
146
    CStringP tmp    = ALLOCATE_VECTOR (char, length + 1);
164
    CStringP tmp    = ALLOCATE_VECTOR(char, length + 1);
147
 
165
 
148
    if (length > 0) {
166
    if (length > 0) {
149
	(void) memcpy ((GenericP) tmp, (GenericP) (nstring->contents),
167
	(void)memcpy((GenericP)tmp, (GenericP)(nstring->contents),
150
		       (SizeT) length);
168
		     (SizeT)length);
151
    }
169
    }
152
    tmp [length] = '\0';
170
    tmp[length] = '\0';
153
    return (tmp);
171
    return(tmp);
154
}
172
}
155
 
173
 
156
unsigned
174
unsigned
157
nstring_hash_value PROTO_N ((nstring))
175
nstring_hash_value(NStringP nstring)
158
		   PROTO_T (NStringP nstring)
-
 
159
{
176
{
160
    unsigned value        = 0;
177
    unsigned value        = 0;
161
    CStringP tmp_contents = (nstring->contents);
178
    CStringP tmp_contents = (nstring->contents);
162
    unsigned tmp_length   = nstring_length (nstring);
179
    unsigned tmp_length   = nstring_length(nstring);
163
 
180
 
164
    while (tmp_length --) {
181
    while (tmp_length--) {
165
	value += ((unsigned) (*tmp_contents ++));
182
	value += ((unsigned)(*tmp_contents++));
166
    }
183
    }
167
    return (value);
184
    return(value);
168
}
185
}
169
 
186
 
170
#ifdef FS_FAST
187
#ifdef FS_FAST
171
#undef nstring_length
188
#undef nstring_length
172
#endif /* defined (FS_FAST) */
189
#endif /* defined (FS_FAST) */
173
unsigned
190
unsigned
174
nstring_length PROTO_N ((nstring))
191
nstring_length(NStringP nstring)
175
	       PROTO_T (NStringP nstring)
-
 
176
{
192
{
177
    return (nstring->length);
193
    return(nstring->length);
178
}
194
}
179
#ifdef FS_FAST
195
#ifdef FS_FAST
180
#define nstring_length(s) ((s)->length)
196
#define nstring_length(s)	((s)->length)
181
#endif /* defined (FS_FAST) */
197
#endif /* defined (FS_FAST) */
182
 
198
 
183
#ifdef FS_FAST
199
#ifdef FS_FAST
184
#undef nstring_contents
200
#undef nstring_contents
185
#endif /* defined (FS_FAST) */
201
#endif /* defined (FS_FAST) */
186
CStringP
202
CStringP
187
nstring_contents PROTO_N ((nstring))
203
nstring_contents(NStringP nstring)
188
		 PROTO_T (NStringP nstring)
-
 
189
{
204
{
190
    return (nstring->contents);
205
    return(nstring->contents);
191
}
206
}
192
#ifdef FS_FAST
207
#ifdef FS_FAST
193
#define nstring_contents(s) ((s)->contents)
208
#define nstring_contents(s)	((s)->contents)
194
#endif /* defined (FS_FAST) */
209
#endif /* defined (FS_FAST) */
195
 
210
 
196
CmpT
211
CmpT
197
nstring_compare PROTO_N ((nstring1, nstring2))
212
nstring_compare(NStringP nstring1, NStringP nstring2)
198
		PROTO_T (NStringP nstring1 X
-
 
199
			 NStringP nstring2)
-
 
200
{
213
{
201
    unsigned length = nstring_length (nstring1);
214
    unsigned length = nstring_length(nstring1);
202
    int      status;
215
    int      status;
203
 
216
 
204
    if (length > nstring_length (nstring2)) {
217
    if (length > nstring_length(nstring2)) {
205
	length = nstring_length (nstring2);
218
	length = nstring_length(nstring2);
206
    }
219
    }
207
    status = memcmp ((GenericP) (nstring1->contents),
220
    status = memcmp((GenericP)(nstring1->contents),
208
		     (GenericP) (nstring2->contents), (SizeT) length);
221
		    (GenericP)(nstring2->contents), (SizeT)length);
209
    if (status < 0) {
222
    if (status < 0) {
210
	return (CMP_LT);
223
	return(CMP_LT);
211
    } else if (status > 0) {
224
    } else if (status > 0) {
212
	return (CMP_GT);
225
	return(CMP_GT);
213
    } else if (nstring_length (nstring1) < nstring_length (nstring2)) {
226
    } else if (nstring_length(nstring1) < nstring_length(nstring2)) {
214
	return (CMP_LT);
227
	return(CMP_LT);
215
    } else if (nstring_length (nstring1) > nstring_length (nstring2)) {
228
    } else if (nstring_length(nstring1) > nstring_length(nstring2)) {
216
	return (CMP_GT);
229
	return(CMP_GT);
217
    } else {
230
    } else {
218
	return (CMP_EQ);
231
	return(CMP_EQ);
219
    }
232
    }
220
}
233
}
221
 
234
 
222
BoolT
235
BoolT
223
nstring_equal PROTO_N ((nstring1, nstring2))
236
nstring_equal(NStringP nstring1, NStringP nstring2)
224
	      PROTO_T (NStringP nstring1 X
-
 
225
		       NStringP nstring2)
-
 
226
{
237
{
227
    unsigned length = nstring_length (nstring1);
238
    unsigned length = nstring_length(nstring1);
228
 
239
 
229
    return ((length == nstring_length (nstring2)) &&
240
    return((length == nstring_length(nstring2)) &&
230
	    (memcmp ((GenericP) (nstring1->contents),
241
	   (memcmp((GenericP)(nstring1->contents),
231
		     (GenericP) (nstring2->contents), (SizeT) length) == 0));
242
		   (GenericP)(nstring2->contents), (SizeT)length) == 0));
232
}
243
}
233
 
244
 
234
BoolT
245
BoolT
235
nstring_ci_equal PROTO_N ((nstring1, nstring2))
246
nstring_ci_equal(NStringP nstring1, NStringP nstring2)
236
		 PROTO_T (NStringP nstring1 X
-
 
237
			  NStringP nstring2)
-
 
238
{
247
{
239
    unsigned length = nstring_length (nstring1);
248
    unsigned length = nstring_length(nstring1);
240
 
249
 
241
    if (length == nstring_length (nstring2)) {
250
    if (length == nstring_length(nstring2)) {
242
	CStringP tmp1 = (nstring1->contents);
251
	CStringP tmp1 = (nstring1->contents);
243
	CStringP tmp2 = (nstring2->contents);
252
	CStringP tmp2 = (nstring2->contents);
244
	char c1;
253
	char c1;
245
	char c2;
254
	char c2;
246
 
255
 
247
	do {
256
	do {
248
	    c1 = syntax_upcase (*tmp1 ++);
257
	    c1 = syntax_upcase(*tmp1++);
249
	    c2 = syntax_upcase (*tmp2 ++);
258
	    c2 = syntax_upcase(*tmp2++);
250
	    if (length -- == 0) {
259
	    if (length-- == 0) {
251
		return (TRUE);
260
		return(TRUE);
252
	    }
261
	    }
253
	} while (c1 == c2);
262
	} while (c1 == c2);
254
    }
263
    }
255
    return (FALSE);
264
    return(FALSE);
256
}
265
}
257
 
266
 
258
BoolT
267
BoolT
259
nstring_contains PROTO_N ((nstring, c))
268
nstring_contains(NStringP nstring, char c)
260
		 PROTO_T (NStringP nstring X
-
 
261
			  char     c)
-
 
262
{
269
{
263
    CStringP contents = nstring_contents (nstring);
270
    CStringP contents = nstring_contents(nstring);
264
    unsigned length   = nstring_length (nstring);
271
    unsigned length   = nstring_length(nstring);
265
 
272
 
266
    return (memchr ((GenericP) contents, c, (SizeT) length) != NIL (GenericP));
273
    return(memchr((GenericP)contents, c, (SizeT)length) != NIL(GenericP));
267
}
274
}
268
 
275
 
269
BoolT
276
BoolT
270
nstring_is_prefix PROTO_N ((nstring1, nstring2))
277
nstring_is_prefix(NStringP nstring1,			   NStringP nstring2)
271
		  PROTO_T (NStringP nstring1 X
-
 
272
			   NStringP nstring2)
-
 
273
{
278
{
274
    CStringP contents1 = nstring_contents (nstring1);
279
    CStringP contents1 = nstring_contents(nstring1);
275
    CStringP contents2 = nstring_contents (nstring2);
280
    CStringP contents2 = nstring_contents(nstring2);
276
    unsigned length    = nstring_length (nstring2);
281
    unsigned length    = nstring_length(nstring2);
277
 
282
 
278
    return ((length < nstring_length (nstring1)) &&
283
    return((length < nstring_length(nstring1)) &&
279
	    (memcmp ((GenericP) contents1, (GenericP) contents2,
284
	   (memcmp((GenericP)contents1, (GenericP)contents2,
280
		     (SizeT) length) == 0));
285
		   (SizeT)length) == 0));
281
}
286
}
282
 
287
 
283
void
288
void
284
nstring_destroy PROTO_N ((nstring))
289
nstring_destroy(NStringP nstring)
285
		PROTO_T (NStringP nstring)
-
 
286
{
290
{
287
    DEALLOCATE (nstring->contents);
291
    DEALLOCATE(nstring->contents);
288
}
292
}
289
 
293
 
290
void
294
void
291
write_nstring PROTO_N ((ostream, nstring))
295
write_nstring(OStreamP ostream, NStringP nstring)
292
	      PROTO_T (OStreamP ostream X
-
 
293
		       NStringP nstring)
-
 
294
{
296
{
295
    unsigned length = nstring_length (nstring);
297
    unsigned length = nstring_length(nstring);
296
 
298
 
297
    if (length > 0) {
299
    if (length > 0) {
298
	write_chars (ostream, nstring->contents, length);
300
	write_chars(ostream, nstring->contents, length);
299
    }
301
    }
300
}
302
}
301
 
303
 
302
/*** Functions for manipulating dstrings.
304
/*** Functions for manipulating dstrings.
303
**/
305
**/
304
 
306
 
305
void
307
void
306
dstring_init PROTO_N ((dstring))
308
dstring_init(DStringP dstring)
307
	     PROTO_T (DStringP dstring)
-
 
308
{
309
{
309
    dstring->length     = 0;
310
    dstring->length     = 0;
310
    dstring->max_length = DSTRING_CHUNK_SIZE;
311
    dstring->max_length = DSTRING_CHUNK_SIZE;
311
    dstring->contents   = ALLOCATE_VECTOR (char, dstring->max_length);
312
    dstring->contents   = ALLOCATE_VECTOR(char, dstring->max_length);
312
}
313
}
313
 
314
 
314
#ifdef FS_FAST
315
#ifdef FS_FAST
315
#undef dstring_length
316
#undef dstring_length
316
#endif /* defined (FS_FAST) */
317
#endif /* defined (FS_FAST) */
317
unsigned
318
unsigned
318
dstring_length PROTO_N ((dstring))
319
dstring_length(DStringP dstring)
319
	       PROTO_T (DStringP dstring)
-
 
320
{
320
{
321
    return (dstring->length);
321
    return(dstring->length);
322
}
322
}
323
#ifdef FS_FAST
323
#ifdef FS_FAST
324
#define dstring_length(s) ((s)->length)
324
#define dstring_length(s)	((s)->length)
325
#endif /* defined (FS_FAST) */
325
#endif /* defined (FS_FAST) */
326
 
326
 
327
void
327
void
328
dstring_append_char PROTO_N ((dstring, c))
328
dstring_append_char(DStringP dstring, char c)
329
		    PROTO_T (DStringP dstring X
-
 
330
			     char     c)
-
 
331
{
329
{
332
    if ((dstring->length) >= (dstring->max_length)) {
330
    if ((dstring->length) >= (dstring->max_length)) {
333
	CStringP tmp;
331
	CStringP tmp;
334
 
332
 
335
	dstring->max_length += DSTRING_CHUNK_SIZE;
333
	dstring->max_length += DSTRING_CHUNK_SIZE;
336
	tmp                  = ALLOCATE_VECTOR (char, dstring->max_length);
334
	tmp                  = ALLOCATE_VECTOR(char, dstring->max_length);
337
	(void) memcpy ((GenericP) tmp, (GenericP) (dstring->contents),
335
	(void)memcpy((GenericP)tmp, (GenericP)(dstring->contents),
338
		       (SizeT) (dstring->length));
336
		     (SizeT)(dstring->length));
339
	DEALLOCATE (dstring->contents);
337
	DEALLOCATE(dstring->contents);
340
	dstring->contents = tmp;
338
	dstring->contents = tmp;
341
    }
339
    }
342
    dstring->contents [dstring->length ++] = c;
340
    dstring->contents[dstring->length++] = c;
343
}
341
}
344
 
342
 
345
void
343
void
346
dstring_append_cstring PROTO_N ((dstring, cstring))
344
dstring_append_cstring(DStringP dstring, CStringP cstring)
347
		       PROTO_T (DStringP dstring X
-
 
348
				CStringP cstring)
-
 
349
{
345
{
350
    unsigned clength = cstring_length (cstring);
346
    unsigned clength = cstring_length(cstring);
351
    unsigned length  = (clength + (dstring->length));
347
    unsigned length  = (clength + (dstring->length));
352
 
348
 
353
    if (length > (dstring->max_length)) {
349
    if (length > (dstring->max_length)) {
354
	CStringP tmp;
350
	CStringP tmp;
355
 
351
 
356
	while ((dstring->max_length) < length) {
352
	while ((dstring->max_length) < length) {
357
	    dstring->max_length += DSTRING_CHUNK_SIZE;
353
	    dstring->max_length += DSTRING_CHUNK_SIZE;
358
	}
354
	}
359
	tmp = ALLOCATE_VECTOR (char, dstring->max_length);
355
	tmp = ALLOCATE_VECTOR(char, dstring->max_length);
360
	(void) memcpy ((GenericP) tmp, (GenericP) (dstring->contents),
356
	(void)memcpy((GenericP)tmp, (GenericP)(dstring->contents),
361
		       (SizeT) (dstring->length));
357
		     (SizeT)(dstring->length));
362
	DEALLOCATE (dstring->contents);
358
	DEALLOCATE(dstring->contents);
363
	dstring->contents = tmp;
359
	dstring->contents = tmp;
364
    }
360
    }
365
    (void) memcpy ((GenericP) &(dstring->contents [dstring->length]),
361
  (void)memcpy((GenericP) & (dstring->contents[dstring->length]),
366
		   (GenericP) cstring, (SizeT) clength);
362
	       (GenericP)cstring, (SizeT)clength);
367
    dstring->length = length;
363
    dstring->length = length;
368
}
364
}
369
 
365
 
370
void
366
void
371
dstring_append_nstring PROTO_N ((dstring, nstring))
367
dstring_append_nstring(DStringP dstring, NStringP nstring)
372
		       PROTO_T (DStringP dstring X
-
 
373
				NStringP nstring)
-
 
374
{
368
{
375
    unsigned nlength = nstring_length (nstring);
369
    unsigned nlength = nstring_length(nstring);
376
    unsigned length  = (nlength + (dstring->length));
370
    unsigned length  = (nlength + (dstring->length));
377
 
371
 
378
    if (length > (dstring->max_length)) {
372
    if (length > (dstring->max_length)) {
379
	CStringP tmp;
373
	CStringP tmp;
380
 
374
 
381
	while ((dstring->max_length) < length) {
375
	while ((dstring->max_length) < length) {
382
	    dstring->max_length += DSTRING_CHUNK_SIZE;
376
	    dstring->max_length += DSTRING_CHUNK_SIZE;
383
	}
377
	}
384
	tmp = ALLOCATE_VECTOR (char, dstring->max_length);
378
	tmp = ALLOCATE_VECTOR(char, dstring->max_length);
385
	(void) memcpy ((GenericP) tmp, (GenericP) (dstring->contents),
379
	(void)memcpy((GenericP)tmp, (GenericP)(dstring->contents),
386
		       (SizeT) (dstring->length));
380
		     (SizeT)(dstring->length));
387
	DEALLOCATE (dstring->contents);
381
	DEALLOCATE(dstring->contents);
388
	dstring->contents = tmp;
382
	dstring->contents = tmp;
389
    }
383
    }
390
    (void) memcpy ((GenericP) &(dstring->contents [dstring->length]),
384
  (void)memcpy((GenericP) & (dstring->contents[dstring->length]),
391
		   (GenericP) nstring_contents (nstring), (SizeT) nlength);
385
	       (GenericP)nstring_contents(nstring), (SizeT)nlength);
392
    dstring->length = length;
386
    dstring->length = length;
393
}
387
}
394
 
388
 
395
BoolT
389
BoolT
396
dstring_last_char_equal PROTO_N ((dstring, c))
390
dstring_last_char_equal(DStringP dstring, char c)
397
			PROTO_T (DStringP dstring X
-
 
398
				 char     c)
-
 
399
{
391
{
400
    return ((dstring->length) &&
392
    return((dstring->length) &&
401
	    ((dstring->contents [dstring->length - 1]) == c));
393
	   ((dstring->contents[dstring->length - 1]) == c));
402
}
394
}
403
 
395
 
404
void
396
void
405
dstring_to_nstring PROTO_N ((dstring, nstring))
397
dstring_to_nstring(DStringP dstring, NStringP nstring)
406
		   PROTO_T (DStringP dstring X
-
 
407
			    NStringP nstring)
-
 
408
{
398
{
409
    if (dstring->length > 0) {
399
    if (dstring->length > 0) {
410
	nstring->length   = (dstring->length);
400
	nstring->length   = (dstring->length);
411
	nstring->contents = ALLOCATE_VECTOR (char, dstring->length);
401
	nstring->contents = ALLOCATE_VECTOR(char, dstring->length);
412
	(void) memcpy ((GenericP) (nstring->contents),
402
	(void)memcpy((GenericP)(nstring->contents),
413
		       (GenericP) (dstring->contents),
403
		     (GenericP)(dstring->contents),
414
		       (SizeT) (dstring->length));
404
		     (SizeT)(dstring->length));
415
    } else {
405
    } else {
416
	nstring->length   = 0;
406
	nstring->length   = 0;
417
	nstring->contents = NIL (CStringP);
407
	nstring->contents = NIL(CStringP);
418
    }
408
    }
419
}
409
}
420
 
410
 
421
CStringP
411
CStringP
422
dstring_to_cstring PROTO_N ((dstring))
412
dstring_to_cstring(DStringP dstring)
423
		   PROTO_T (DStringP dstring)
-
 
424
{
413
{
425
    CStringP tmp = ALLOCATE_VECTOR (char, dstring->length + 1);
414
    CStringP tmp = ALLOCATE_VECTOR(char, dstring->length + 1);
426
 
415
 
427
    if (dstring->length > 0) {
416
    if (dstring->length > 0) {
428
	(void) memcpy ((GenericP) tmp, (GenericP) (dstring->contents),
417
	(void)memcpy((GenericP)tmp, (GenericP)(dstring->contents),
429
		       (SizeT) (dstring->length));
418
		     (SizeT)(dstring->length));
430
    }
419
    }
431
    tmp [dstring->length] = '\0';
420
    tmp[dstring->length] = '\0';
432
    return (tmp);
421
    return(tmp);
433
}
422
}
434
 
423
 
435
CStringP
424
CStringP
436
dstring_destroy_to_cstring PROTO_N ((dstring))
425
dstring_destroy_to_cstring(DStringP dstring)
437
			   PROTO_T (DStringP dstring)
-
 
438
{
426
{
439
    CStringP tmp;
427
    CStringP tmp;
440
 
428
 
441
    if ((dstring->length) >= (dstring->max_length)) {
429
    if ((dstring->length) >= (dstring->max_length)) {
442
	tmp = ALLOCATE_VECTOR (char, (dstring->length) + 1);
430
	tmp = ALLOCATE_VECTOR(char, (dstring->length) + 1);
443
	(void) memcpy ((GenericP) tmp, (GenericP) (dstring->contents),
431
	(void)memcpy((GenericP)tmp, (GenericP)(dstring->contents),
444
		       (SizeT) (dstring->length));
432
		     (SizeT)(dstring->length));
445
	DEALLOCATE (dstring->contents);
433
	DEALLOCATE(dstring->contents);
446
    } else {
434
    } else {
447
	tmp = (dstring->contents);
435
	tmp = (dstring->contents);
448
    }
436
    }
449
    tmp [dstring->length] = '\0';
437
    tmp[dstring->length] = '\0';
450
    dstring->length       = 0;
438
    dstring->length       = 0;
451
    dstring->max_length   = 0;
439
    dstring->max_length   = 0;
452
    dstring->contents     = NIL (CStringP);
440
    dstring->contents     = NIL(CStringP);
453
    return (tmp);
441
    return(tmp);
454
}
442
}
455
 
443
 
456
void
444
void
457
dstring_destroy PROTO_N ((dstring))
445
dstring_destroy(DStringP dstring)
458
		PROTO_T (DStringP dstring)
-
 
459
{
446
{
460
    DEALLOCATE (dstring->contents);
447
    DEALLOCATE(dstring->contents);
461
}
448
}
462

449

463
/*
450
/*
464
 * Local variables(smf):
451
 * Local variables(smf):
465
 * eval: (include::add-path-entry "../os-interface" "../generated")
452
 * eval: (include::add-path-entry "../os-interface" "../generated")