sb.h revision 130561
160484Sobrien/* sb.h - header file for string buffer manipulation routines
278828Sobrien   Copyright 1994, 1995, 2000 Free Software Foundation, Inc.
378828Sobrien
460484Sobrien   Written by Steve and Judy Chamberlain of Cygnus Support,
560484Sobrien      sac@cygnus.com
660484Sobrien
760484Sobrien   This file is part of GAS, the GNU Assembler.
860484Sobrien
960484Sobrien   GAS is free software; you can redistribute it and/or modify
1060484Sobrien   it under the terms of the GNU General Public License as published by
1160484Sobrien   the Free Software Foundation; either version 2, or (at your option)
1260484Sobrien   any later version.
1360484Sobrien
1460484Sobrien   GAS is distributed in the hope that it will be useful,
1560484Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1660484Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1760484Sobrien   GNU General Public License for more details.
1860484Sobrien
1960484Sobrien   You should have received a copy of the GNU General Public License
2060484Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
2160484Sobrien   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2260484Sobrien   02111-1307, USA.  */
2360484Sobrien
2460484Sobrien#ifndef SB_H
2577298Sobrien
2660484Sobrien#define SB_H
2760484Sobrien
2860484Sobrien#include <stdio.h>
2960484Sobrien#include "ansidecl.h"
3060484Sobrien
3160484Sobrien/* string blocks
3260484Sobrien
3360484Sobrien   I had a couple of choices when deciding upon this data structure.
3460484Sobrien   gas uses null terminated strings for all its internal work.  This
3560484Sobrien   often means that parts of the program that want to examine
36   substrings have to manipulate the data in the string to do the
37   right thing (a common operation is to single out a bit of text by
38   saving away the character after it, nulling it out, operating on
39   the substring and then replacing the character which was under the
40   null).  This is a pain and I remember a load of problems that I had with
41   code in gas which almost got this right.  Also, it's harder to grow and
42   allocate null terminated strings efficiently.
43
44   Obstacks provide all the functionality needed, but are too
45   complicated, hence the sb.
46
47   An sb is allocated by the caller, and is initialized to point to an
48   sb_element.  sb_elements are kept on a free lists, and used when
49   needed, replaced onto the free list when unused.
50 */
51
52#define sb_max_power_two    30	/* don't allow strings more than
53			           2^sb_max_power_two long */
54/* structure of an sb */
55typedef struct sb
56  {
57    char *ptr;			/* points to the current block.  */
58    int len;			/* how much is used.  */
59    int pot;			/* the maximum length is 1<<pot */
60    struct le *item;
61  }
62sb;
63
64/* Structure of the free list object of an sb */
65typedef struct le
66  {
67    struct le *next;
68    int size;
69    char data[1];
70  }
71sb_element;
72
73/* The free list */
74typedef struct
75  {
76    sb_element *size[sb_max_power_two];
77  } sb_list_vector;
78
79extern int string_count[sb_max_power_two];
80
81extern void sb_build (sb *, int);
82extern void sb_new (sb *);
83extern void sb_kill (sb *);
84extern void sb_add_sb (sb *, sb *);
85extern void sb_reset (sb *);
86extern void sb_add_char (sb *, int);
87extern void sb_add_string (sb *, const char *);
88extern void sb_add_buffer (sb *, const char *, int);
89extern void sb_print (FILE *, sb *);
90extern void sb_print_at (FILE *, int, sb *);
91extern char *sb_name (sb *);
92extern char *sb_terminate (sb *);
93extern int sb_skip_white (int, sb *);
94extern int sb_skip_comma (int, sb *);
95
96/* Actually in input-scrub.c.  */
97extern void input_scrub_include_sb (sb *, char *, int);
98
99#endif /* SB_H */
100