]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* sb.h - header file for string buffer manipulation routines |
aa820537 AM |
2 | Copyright 1994, 1995, 2000, 2003, 2005, 2006, 2007 |
3 | Free Software Foundation, Inc. | |
252b5132 RH |
4 | |
5 | Written by Steve and Judy Chamberlain of Cygnus Support, | |
6 | [email protected] | |
7 | ||
8 | This file is part of GAS, the GNU Assembler. | |
9 | ||
10 | GAS is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 12 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
13 | any later version. |
14 | ||
15 | GAS is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
22 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
23 | 02110-1301, USA. */ | |
252b5132 RH |
24 | |
25 | #ifndef SB_H | |
26 | ||
27 | #define SB_H | |
28 | ||
93a9f991 | 29 | /* String blocks |
252b5132 RH |
30 | |
31 | I had a couple of choices when deciding upon this data structure. | |
32 | gas uses null terminated strings for all its internal work. This | |
33 | often means that parts of the program that want to examine | |
34 | substrings have to manipulate the data in the string to do the | |
35 | right thing (a common operation is to single out a bit of text by | |
36 | saving away the character after it, nulling it out, operating on | |
37 | the substring and then replacing the character which was under the | |
38 | null). This is a pain and I remember a load of problems that I had with | |
39 | code in gas which almost got this right. Also, it's harder to grow and | |
40 | allocate null terminated strings efficiently. | |
41 | ||
42 | Obstacks provide all the functionality needed, but are too | |
43 | complicated, hence the sb. | |
44 | ||
47eebc20 | 45 | An sb is allocated by the caller, and is initialized to point to an |
252b5132 | 46 | sb_element. sb_elements are kept on a free lists, and used when |
93a9f991 NC |
47 | needed, replaced onto the free list when unused. */ |
48 | ||
49 | #define sb_max_power_two 30 /* Don't allow strings more than | |
50 | 2^sb_max_power_two long. */ | |
252b5132 | 51 | |
252b5132 | 52 | typedef struct sb |
93a9f991 NC |
53 | { |
54 | char *ptr; /* Points to the current block. */ | |
55 | int len; /* How much is used. */ | |
56 | int pot; /* The maximum length is 1<<pot. */ | |
57 | struct le *item; | |
58 | } | |
252b5132 RH |
59 | sb; |
60 | ||
93a9f991 NC |
61 | /* Structure of the free list object of a string block. */ |
62 | ||
252b5132 | 63 | typedef struct le |
93a9f991 NC |
64 | { |
65 | struct le *next; | |
66 | int size; | |
67 | char data[1]; | |
68 | } | |
252b5132 RH |
69 | sb_element; |
70 | ||
24361518 KH |
71 | extern void sb_new (sb *); |
72 | extern void sb_kill (sb *); | |
73 | extern void sb_add_sb (sb *, sb *); | |
c19d1205 | 74 | extern void sb_scrub_and_add_sb (sb *, sb *); |
24361518 KH |
75 | extern void sb_reset (sb *); |
76 | extern void sb_add_char (sb *, int); | |
77 | extern void sb_add_string (sb *, const char *); | |
3c9aabc7 | 78 | extern void sb_add_buffer (sb *, const char *, int); |
24361518 KH |
79 | extern char *sb_terminate (sb *); |
80 | extern int sb_skip_white (int, sb *); | |
81 | extern int sb_skip_comma (int, sb *); | |
252b5132 RH |
82 | |
83 | /* Actually in input-scrub.c. */ | |
24361518 | 84 | extern void input_scrub_include_sb (sb *, char *, int); |
252b5132 RH |
85 | |
86 | #endif /* SB_H */ |