1 |
6 |
jlechner |
/* sb.h - header file for string buffer manipulation routines
|
2 |
|
|
Copyright 1994, 1995, 2000, 2003, 2006, 2007 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
Written by Steve and Judy Chamberlain of Cygnus Support,
|
5 |
|
|
sac@cygnus.com
|
6 |
|
|
|
7 |
|
|
This file is part of GAS, the GNU Assembler.
|
8 |
|
|
|
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 3, or (at your option)
|
12 |
|
|
any later version.
|
13 |
|
|
|
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.
|
18 |
|
|
|
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, 51 Franklin Street - Fifth Floor, Boston, MA
|
22 |
|
|
02110-1301, USA. */
|
23 |
|
|
|
24 |
|
|
#ifndef SB_H
|
25 |
|
|
|
26 |
|
|
#define SB_H
|
27 |
|
|
|
28 |
|
|
/* String blocks
|
29 |
|
|
|
30 |
|
|
I had a couple of choices when deciding upon this data structure.
|
31 |
|
|
gas uses null terminated strings for all its internal work. This
|
32 |
|
|
often means that parts of the program that want to examine
|
33 |
|
|
substrings have to manipulate the data in the string to do the
|
34 |
|
|
right thing (a common operation is to single out a bit of text by
|
35 |
|
|
saving away the character after it, nulling it out, operating on
|
36 |
|
|
the substring and then replacing the character which was under the
|
37 |
|
|
null). This is a pain and I remember a load of problems that I had with
|
38 |
|
|
code in gas which almost got this right. Also, it's harder to grow and
|
39 |
|
|
allocate null terminated strings efficiently.
|
40 |
|
|
|
41 |
|
|
Obstacks provide all the functionality needed, but are too
|
42 |
|
|
complicated, hence the sb.
|
43 |
|
|
|
44 |
|
|
An sb is allocated by the caller, and is initialized to point to an
|
45 |
|
|
sb_element. sb_elements are kept on a free lists, and used when
|
46 |
|
|
needed, replaced onto the free list when unused. */
|
47 |
|
|
|
48 |
|
|
#define sb_max_power_two 30 /* Don't allow strings more than
|
49 |
|
|
2^sb_max_power_two long. */
|
50 |
|
|
|
51 |
|
|
typedef struct sb
|
52 |
|
|
{
|
53 |
|
|
char *ptr; /* Points to the current block. */
|
54 |
|
|
int len; /* How much is used. */
|
55 |
|
|
int pot; /* The maximum length is 1<<pot. */
|
56 |
|
|
struct le *item;
|
57 |
|
|
}
|
58 |
|
|
sb;
|
59 |
|
|
|
60 |
|
|
/* Structure of the free list object of a string block. */
|
61 |
|
|
|
62 |
|
|
typedef struct le
|
63 |
|
|
{
|
64 |
|
|
struct le *next;
|
65 |
|
|
int size;
|
66 |
|
|
char data[1];
|
67 |
|
|
}
|
68 |
|
|
sb_element;
|
69 |
|
|
|
70 |
|
|
extern void sb_new (sb *);
|
71 |
|
|
extern void sb_kill (sb *);
|
72 |
|
|
extern void sb_add_sb (sb *, sb *);
|
73 |
|
|
extern void sb_scrub_and_add_sb (sb *, sb *);
|
74 |
|
|
extern void sb_reset (sb *);
|
75 |
|
|
extern void sb_add_char (sb *, int);
|
76 |
|
|
extern void sb_add_string (sb *, const char *);
|
77 |
|
|
extern void sb_add_buffer (sb *, const char *, int);
|
78 |
|
|
extern char *sb_terminate (sb *);
|
79 |
|
|
extern int sb_skip_white (int, sb *);
|
80 |
|
|
extern int sb_skip_comma (int, sb *);
|
81 |
|
|
|
82 |
|
|
/* Actually in input-scrub.c. */
|
83 |
|
|
extern void input_scrub_include_sb (sb *, char *, int);
|
84 |
|
|
|
85 |
|
|
#endif /* SB_H */
|