Back to index

cell-binutils  2.17cvs20070401
sb.h
Go to the documentation of this file.
00001 /* sb.h - header file for string buffer manipulation routines
00002    Copyright 1994, 1995, 2000, 2003, 2006 Free Software Foundation, Inc.
00003 
00004    Written by Steve and Judy Chamberlain of Cygnus Support,
00005       sac@cygnus.com
00006 
00007    This file is part of GAS, the GNU Assembler.
00008 
00009    GAS is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2, or (at your option)
00012    any later version.
00013 
00014    GAS is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with GAS; see the file COPYING.  If not, write to the Free
00021    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00022    02110-1301, USA.  */
00023 
00024 #ifndef SB_H
00025 
00026 #define SB_H
00027 
00028 /* String blocks
00029 
00030    I had a couple of choices when deciding upon this data structure.
00031    gas uses null terminated strings for all its internal work.  This
00032    often means that parts of the program that want to examine
00033    substrings have to manipulate the data in the string to do the
00034    right thing (a common operation is to single out a bit of text by
00035    saving away the character after it, nulling it out, operating on
00036    the substring and then replacing the character which was under the
00037    null).  This is a pain and I remember a load of problems that I had with
00038    code in gas which almost got this right.  Also, it's harder to grow and
00039    allocate null terminated strings efficiently.
00040 
00041    Obstacks provide all the functionality needed, but are too
00042    complicated, hence the sb.
00043 
00044    An sb is allocated by the caller, and is initialized to point to an
00045    sb_element.  sb_elements are kept on a free lists, and used when
00046    needed, replaced onto the free list when unused.  */
00047 
00048 #define sb_max_power_two    30     /* Don't allow strings more than
00049                                 2^sb_max_power_two long.  */
00050 
00051 typedef struct sb
00052 {
00053   char *ptr;                /* Points to the current block.  */
00054   int len;                  /* How much is used.  */
00055   int pot;                  /* The maximum length is 1<<pot.  */
00056   struct le *item;
00057 }
00058 sb;
00059 
00060 /* Structure of the free list object of a string block.  */
00061 
00062 typedef struct le
00063 {
00064   struct le *next;
00065   int size;
00066   char data[1];
00067 }
00068 sb_element;
00069 
00070 extern void sb_new (sb *);
00071 extern void sb_kill (sb *);
00072 extern void sb_add_sb (sb *, sb *);
00073 extern void sb_scrub_and_add_sb (sb *, sb *);
00074 extern void sb_reset (sb *);
00075 extern void sb_add_char (sb *, int);
00076 extern void sb_add_string (sb *, const char *);
00077 extern void sb_add_buffer (sb *, const char *, int);
00078 extern char *sb_terminate (sb *);
00079 extern int sb_skip_white (int, sb *);
00080 extern int sb_skip_comma (int, sb *);
00081 
00082 /* Actually in input-scrub.c.  */
00083 extern void input_scrub_include_sb (sb *, char *, int);
00084 
00085 #endif /* SB_H */