b48b07616ea97c0c4535a50b37cd8d91b1962415
1 /* sb.c - string buffer manipulation routines
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 Written by Steve and Judy Chamberlain of Cygnus Support,
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 /* These routines are about manipulating strings.
30 They are managed in things called `sb's which is an abbreviation
31 for string buffers. An sb has to be created, things can be glued
32 on to it, and at the end of it's life it should be freed. The
33 contents should never be pointed at whilst it is still growing,
34 since it could be moved at any time
38 sb_grow... (&foo,...);
46 static void sb_check
PARAMS ((sb
*, int));
48 /* Statistics of sb structures. */
50 int string_count
[sb_max_power_two
];
52 /* Free list of sb structures. */
54 static sb_list_vector free_list
;
56 /* initializes an sb. */
63 /* see if we can find one to allocate */
66 if (size
> sb_max_power_two
)
69 e
= free_list
.size
[size
];
72 /* nothing there, allocate one and stick into the free list */
73 e
= (sb_element
*) xmalloc (sizeof (sb_element
) + (1 << size
));
74 e
->next
= free_list
.size
[size
];
76 free_list
.size
[size
] = e
;
80 /* remove from free list */
82 free_list
.size
[size
] = e
->next
;
84 /* copy into callers world */
96 sb_build (ptr
, dsize
);
99 /* deallocate the sb at ptr */
105 /* return item to free list */
106 ptr
->item
->next
= free_list
.size
[ptr
->pot
];
107 free_list
.size
[ptr
->pot
] = ptr
->item
;
110 /* add the sb at s to the end of the sb at ptr */
117 sb_check (ptr
, s
->len
);
118 memcpy (ptr
->ptr
+ ptr
->len
, s
->ptr
, s
->len
);
122 /* make sure that the sb at ptr has room for another len characters,
123 and grow it if it doesn't. */
130 if (ptr
->len
+ len
>= 1 << ptr
->pot
)
134 while (ptr
->len
+ len
>= 1 << pot
)
136 sb_build (&tmp
, pot
);
137 sb_add_sb (&tmp
, ptr
);
143 /* make the sb at ptr point back to the beginning. */
152 /* add character c to the end of the sb at ptr. */
160 ptr
->ptr
[ptr
->len
++] = c
;
163 /* add null terminated string s to the end of sb at ptr. */
166 sb_add_string (ptr
, s
)
170 int len
= strlen (s
);
172 memcpy (ptr
->ptr
+ ptr
->len
, s
, len
);
176 /* add string at s of length len to sb at ptr */
179 sb_add_buffer (ptr
, s
, len
)
185 memcpy (ptr
->ptr
+ ptr
->len
, s
, len
);
189 /* print the sb at ptr to the output file */
192 sb_print (outfile
, ptr
)
199 for (i
= 0; i
< ptr
->len
; i
++)
203 fprintf (outfile
, ",");
205 fprintf (outfile
, "%d", ptr
->ptr
[i
]);
211 sb_print_at (outfile
, idx
, ptr
)
217 for (i
= idx
; i
< ptr
->len
; i
++)
218 putc (ptr
->ptr
[i
], outfile
);
221 /* put a null at the end of the sb at in and return the start of the
222 string, so that it can be used as an arg to printf %s. */
228 /* stick a null on the end of the string */
233 /* like sb_name, but don't include the null byte in the string. */
244 /* start at the index idx into the string in sb at ptr and skip
245 whitespace. return the index of the first non whitespace character */
248 sb_skip_white (idx
, ptr
)
252 while (idx
< ptr
->len
253 && (ptr
->ptr
[idx
] == ' '
254 || ptr
->ptr
[idx
] == '\t'))
259 /* start at the index idx into the sb at ptr. skips whitespace,
260 a comma and any following whitespace. returnes the index of the
264 sb_skip_comma (idx
, ptr
)
268 while (idx
< ptr
->len
269 && (ptr
->ptr
[idx
] == ' '
270 || ptr
->ptr
[idx
] == '\t'))
274 && ptr
->ptr
[idx
] == ',')
277 while (idx
< ptr
->len
278 && (ptr
->ptr
[idx
] == ' '
279 || ptr
->ptr
[idx
] == '\t'))
This page took 0.033938 seconds and 3 git commands to generate.