merge from gcc
[binutils.git] / gas / sb.h
blobdd01e0ddb75ffc3d0fe31da23103c279f3a6368a
1 /* sb.h - header file for string buffer manipulation routines
2 Copyright 1994, 1995, 2000 Free Software Foundation, Inc.
4 Written by Steve and Judy Chamberlain of Cygnus Support,
5 sac@cygnus.com
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)
12 any later version.
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
22 02111-1307, USA. */
24 #ifndef SB_H
26 #define SB_H
28 #include <stdio.h>
29 #include "ansidecl.h"
31 /* string blocks
33 I had a couple of choices when deciding upon this data structure.
34 gas uses null terminated strings for all its internal work. This
35 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.
44 Obstacks provide all the functionality needed, but are too
45 complicated, hence the sb.
47 An sb is allocated by the caller, and is initialzed 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.
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 */
55 typedef struct sb
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;
62 sb;
64 /* Structure of the free list object of an sb */
65 typedef struct le
67 struct le *next;
68 int size;
69 char data[1];
71 sb_element;
73 /* The free list */
74 typedef struct
76 sb_element *size[sb_max_power_two];
77 } sb_list_vector;
79 extern int string_count[sb_max_power_two];
81 extern void sb_build PARAMS ((sb *, int));
82 extern void sb_new PARAMS ((sb *));
83 extern void sb_kill PARAMS ((sb *));
84 extern void sb_add_sb PARAMS ((sb *, sb *));
85 extern void sb_reset PARAMS ((sb *));
86 extern void sb_add_char PARAMS ((sb *, int));
87 extern void sb_add_string PARAMS ((sb *, const char *));
88 extern void sb_add_buffer PARAMS ((sb *, const char *, int));
89 extern void sb_print PARAMS ((FILE *, sb *));
90 extern void sb_print_at PARAMS ((FILE *, int, sb *));
91 extern char *sb_name PARAMS ((sb *));
92 extern char *sb_terminate PARAMS ((sb *));
93 extern int sb_skip_white PARAMS ((int, sb *));
94 extern int sb_skip_comma PARAMS ((int, sb *));
96 /* Actually in input-scrub.c. */
97 extern void input_scrub_include_sb PARAMS ((sb *, char *, int));
99 #endif /* SB_H */