133965Sjdp/* sb.h - header file for string buffer manipulation routines 2218822Sdim Copyright 1994, 1995, 2000, 2003, 2006 Free Software Foundation, Inc. 333965Sjdp 433965Sjdp Written by Steve and Judy Chamberlain of Cygnus Support, 533965Sjdp sac@cygnus.com 633965Sjdp 733965Sjdp This file is part of GAS, the GNU Assembler. 833965Sjdp 933965Sjdp GAS is free software; you can redistribute it and/or modify 1033965Sjdp it under the terms of the GNU General Public License as published by 1133965Sjdp the Free Software Foundation; either version 2, or (at your option) 1233965Sjdp any later version. 1333965Sjdp 1433965Sjdp GAS is distributed in the hope that it will be useful, 1533965Sjdp but WITHOUT ANY WARRANTY; without even the implied warranty of 1633965Sjdp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1733965Sjdp GNU General Public License for more details. 1833965Sjdp 1933965Sjdp You should have received a copy of the GNU General Public License 2033965Sjdp along with GAS; see the file COPYING. If not, write to the Free 21218822Sdim Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 22218822Sdim 02110-1301, USA. */ 2333965Sjdp 2433965Sjdp#ifndef SB_H 2533965Sjdp 2633965Sjdp#define SB_H 2733965Sjdp 28218822Sdim/* String blocks 2933965Sjdp 3033965Sjdp I had a couple of choices when deciding upon this data structure. 3133965Sjdp gas uses null terminated strings for all its internal work. This 3233965Sjdp often means that parts of the program that want to examine 3333965Sjdp substrings have to manipulate the data in the string to do the 3433965Sjdp right thing (a common operation is to single out a bit of text by 3533965Sjdp saving away the character after it, nulling it out, operating on 3633965Sjdp the substring and then replacing the character which was under the 3733965Sjdp null). This is a pain and I remember a load of problems that I had with 3833965Sjdp code in gas which almost got this right. Also, it's harder to grow and 3933965Sjdp allocate null terminated strings efficiently. 4033965Sjdp 4133965Sjdp Obstacks provide all the functionality needed, but are too 4233965Sjdp complicated, hence the sb. 4333965Sjdp 44130561Sobrien An sb is allocated by the caller, and is initialized to point to an 4533965Sjdp sb_element. sb_elements are kept on a free lists, and used when 46218822Sdim needed, replaced onto the free list when unused. */ 4733965Sjdp 48218822Sdim#define sb_max_power_two 30 /* Don't allow strings more than 49218822Sdim 2^sb_max_power_two long. */ 50218822Sdim 5133965Sjdptypedef struct sb 52218822Sdim{ 53218822Sdim char *ptr; /* Points to the current block. */ 54218822Sdim int len; /* How much is used. */ 55218822Sdim int pot; /* The maximum length is 1<<pot. */ 56218822Sdim struct le *item; 57218822Sdim} 5833965Sjdpsb; 5933965Sjdp 60218822Sdim/* Structure of the free list object of a string block. */ 61218822Sdim 6233965Sjdptypedef struct le 63218822Sdim{ 64218822Sdim struct le *next; 65218822Sdim int size; 66218822Sdim char data[1]; 67218822Sdim} 6833965Sjdpsb_element; 6933965Sjdp 70130561Sobrienextern void sb_new (sb *); 71130561Sobrienextern void sb_kill (sb *); 72130561Sobrienextern void sb_add_sb (sb *, sb *); 73218822Sdimextern void sb_scrub_and_add_sb (sb *, sb *); 74130561Sobrienextern void sb_reset (sb *); 75130561Sobrienextern void sb_add_char (sb *, int); 76130561Sobrienextern void sb_add_string (sb *, const char *); 77130561Sobrienextern void sb_add_buffer (sb *, const char *, int); 78130561Sobrienextern char *sb_terminate (sb *); 79130561Sobrienextern int sb_skip_white (int, sb *); 80130561Sobrienextern int sb_skip_comma (int, sb *); 8133965Sjdp 8233965Sjdp/* Actually in input-scrub.c. */ 83130561Sobrienextern void input_scrub_include_sb (sb *, char *, int); 8433965Sjdp 8533965Sjdp#endif /* SB_H */ 86