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