xref: /dflybsd-src/contrib/binutils-2.27/gas/sb.h (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj /* sb.h - header file for string buffer manipulation routines
2*a9fa9459Szrj    Copyright (C) 1994-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj 
4*a9fa9459Szrj    Written by Steve and Judy Chamberlain of Cygnus Support,
5*a9fa9459Szrj       sac@cygnus.com
6*a9fa9459Szrj 
7*a9fa9459Szrj    This file is part of GAS, the GNU Assembler.
8*a9fa9459Szrj 
9*a9fa9459Szrj    GAS is free software; you can redistribute it and/or modify
10*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
11*a9fa9459Szrj    the Free Software Foundation; either version 3, or (at your option)
12*a9fa9459Szrj    any later version.
13*a9fa9459Szrj 
14*a9fa9459Szrj    GAS is distributed in the hope that it will be useful,
15*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*a9fa9459Szrj    GNU General Public License for more details.
18*a9fa9459Szrj 
19*a9fa9459Szrj    You should have received a copy of the GNU General Public License
20*a9fa9459Szrj    along with GAS; see the file COPYING.  If not, write to the Free
21*a9fa9459Szrj    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22*a9fa9459Szrj    02110-1301, USA.  */
23*a9fa9459Szrj 
24*a9fa9459Szrj #ifndef SB_H
25*a9fa9459Szrj 
26*a9fa9459Szrj #define SB_H
27*a9fa9459Szrj 
28*a9fa9459Szrj /* String blocks
29*a9fa9459Szrj 
30*a9fa9459Szrj    I had a couple of choices when deciding upon this data structure.
31*a9fa9459Szrj    gas uses null terminated strings for all its internal work.  This
32*a9fa9459Szrj    often means that parts of the program that want to examine
33*a9fa9459Szrj    substrings have to manipulate the data in the string to do the
34*a9fa9459Szrj    right thing (a common operation is to single out a bit of text by
35*a9fa9459Szrj    saving away the character after it, nulling it out, operating on
36*a9fa9459Szrj    the substring and then replacing the character which was under the
37*a9fa9459Szrj    null).  This is a pain and I remember a load of problems that I had with
38*a9fa9459Szrj    code in gas which almost got this right.  Also, it's harder to grow and
39*a9fa9459Szrj    allocate null terminated strings efficiently.
40*a9fa9459Szrj 
41*a9fa9459Szrj    Obstacks provide all the functionality needed, but are too
42*a9fa9459Szrj    complicated, hence the sb.
43*a9fa9459Szrj 
44*a9fa9459Szrj    An sb is allocated by the caller.  */
45*a9fa9459Szrj 
46*a9fa9459Szrj typedef struct sb
47*a9fa9459Szrj {
48*a9fa9459Szrj   char *ptr;			/* Points to the current block.  */
49*a9fa9459Szrj   size_t len;			/* How much is used.  */
50*a9fa9459Szrj   size_t max;			/* The maximum length.  */
51*a9fa9459Szrj }
52*a9fa9459Szrj sb;
53*a9fa9459Szrj 
54*a9fa9459Szrj extern void sb_new (sb *);
55*a9fa9459Szrj extern void sb_build (sb *, size_t);
56*a9fa9459Szrj extern void sb_kill (sb *);
57*a9fa9459Szrj extern void sb_add_sb (sb *, sb *);
58*a9fa9459Szrj extern void sb_scrub_and_add_sb (sb *, sb *);
59*a9fa9459Szrj extern void sb_reset (sb *);
60*a9fa9459Szrj extern void sb_add_char (sb *, size_t);
61*a9fa9459Szrj extern void sb_add_string (sb *, const char *);
62*a9fa9459Szrj extern void sb_add_buffer (sb *, const char *, size_t);
63*a9fa9459Szrj extern char *sb_terminate (sb *);
64*a9fa9459Szrj extern size_t sb_skip_white (size_t, sb *);
65*a9fa9459Szrj extern size_t sb_skip_comma (size_t, sb *);
66*a9fa9459Szrj 
67*a9fa9459Szrj /* Actually in input-scrub.c.  */
68*a9fa9459Szrj extern void input_scrub_include_sb (sb *, char *, int);
69*a9fa9459Szrj 
70*a9fa9459Szrj #endif /* SB_H */
71