xref: /openbsd-src/gnu/usr.bin/binutils-2.17/include/dyn-string.h (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* An abstract string datatype.
2*3d8817e4Smiod    Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
3*3d8817e4Smiod    Contributed by Mark Mitchell (mark@markmitchell.com).
4*3d8817e4Smiod 
5*3d8817e4Smiod This file is part of GCC.
6*3d8817e4Smiod 
7*3d8817e4Smiod GCC is free software; you can redistribute it and/or modify
8*3d8817e4Smiod it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option)
10*3d8817e4Smiod any later version.
11*3d8817e4Smiod 
12*3d8817e4Smiod GCC is distributed in the hope that it will be useful,
13*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*3d8817e4Smiod GNU General Public License for more details.
16*3d8817e4Smiod 
17*3d8817e4Smiod You should have received a copy of the GNU General Public License
18*3d8817e4Smiod along with GCC; see the file COPYING.  If not, write to
19*3d8817e4Smiod the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20*3d8817e4Smiod Boston, MA 02110-1301, USA.  */
21*3d8817e4Smiod 
22*3d8817e4Smiod 
23*3d8817e4Smiod typedef struct dyn_string
24*3d8817e4Smiod {
25*3d8817e4Smiod   int allocated;	/* The amount of space allocated for the string.  */
26*3d8817e4Smiod   int length;		/* The actual length of the string.  */
27*3d8817e4Smiod   char *s;		/* The string itself, NUL-terminated.  */
28*3d8817e4Smiod }* dyn_string_t;
29*3d8817e4Smiod 
30*3d8817e4Smiod /* The length STR, in bytes, not including the terminating NUL.  */
31*3d8817e4Smiod #define dyn_string_length(STR)                                          \
32*3d8817e4Smiod   ((STR)->length)
33*3d8817e4Smiod 
34*3d8817e4Smiod /* The NTBS in which the contents of STR are stored.  */
35*3d8817e4Smiod #define dyn_string_buf(STR)                                             \
36*3d8817e4Smiod   ((STR)->s)
37*3d8817e4Smiod 
38*3d8817e4Smiod /* Compare DS1 to DS2 with strcmp.  */
39*3d8817e4Smiod #define dyn_string_compare(DS1, DS2)                                    \
40*3d8817e4Smiod   (strcmp ((DS1)->s, (DS2)->s))
41*3d8817e4Smiod 
42*3d8817e4Smiod 
43*3d8817e4Smiod extern int dyn_string_init (struct dyn_string *, int);
44*3d8817e4Smiod extern dyn_string_t dyn_string_new (int);
45*3d8817e4Smiod extern void dyn_string_delete (dyn_string_t);
46*3d8817e4Smiod extern char *dyn_string_release (dyn_string_t);
47*3d8817e4Smiod extern dyn_string_t dyn_string_resize (dyn_string_t, int);
48*3d8817e4Smiod extern void dyn_string_clear (dyn_string_t);
49*3d8817e4Smiod extern int dyn_string_copy (dyn_string_t, dyn_string_t);
50*3d8817e4Smiod extern int dyn_string_copy_cstr (dyn_string_t, const char *);
51*3d8817e4Smiod extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
52*3d8817e4Smiod extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
53*3d8817e4Smiod extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
54*3d8817e4Smiod extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
55*3d8817e4Smiod extern int dyn_string_insert_char (dyn_string_t, int, int);
56*3d8817e4Smiod extern int dyn_string_append (dyn_string_t, dyn_string_t);
57*3d8817e4Smiod extern int dyn_string_append_cstr (dyn_string_t, const char *);
58*3d8817e4Smiod extern int dyn_string_append_char (dyn_string_t, int);
59*3d8817e4Smiod extern int dyn_string_substring (dyn_string_t,  dyn_string_t, int, int);
60*3d8817e4Smiod extern int dyn_string_eq (dyn_string_t, dyn_string_t);
61