xref: /openbsd-src/gnu/usr.bin/binutils/include/dyn-string.h (revision d2201f2f89f0be1a0be6f7568000ed297414a06d)
135bd5cb4Sespie /* An abstract string datatype.
2*d2201f2fSdrahn    Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
335bd5cb4Sespie    Contributed by Mark Mitchell (mark@markmitchell.com).
435bd5cb4Sespie 
5*d2201f2fSdrahn This file is part of GCC.
635bd5cb4Sespie 
7*d2201f2fSdrahn GCC is free software; you can redistribute it and/or modify
835bd5cb4Sespie it under the terms of the GNU General Public License as published by
935bd5cb4Sespie the Free Software Foundation; either version 2, or (at your option)
1035bd5cb4Sespie any later version.
1135bd5cb4Sespie 
12*d2201f2fSdrahn GCC is distributed in the hope that it will be useful,
1335bd5cb4Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
1435bd5cb4Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1535bd5cb4Sespie GNU General Public License for more details.
1635bd5cb4Sespie 
1735bd5cb4Sespie You should have received a copy of the GNU General Public License
18*d2201f2fSdrahn along with GCC; see the file COPYING.  If not, write to
1935bd5cb4Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
2035bd5cb4Sespie Boston, MA 02111-1307, USA.  */
2135bd5cb4Sespie 
2235bd5cb4Sespie 
2335bd5cb4Sespie typedef struct dyn_string
2435bd5cb4Sespie {
2535bd5cb4Sespie   int allocated;	/* The amount of space allocated for the string.  */
2635bd5cb4Sespie   int length;		/* The actual length of the string.  */
2735bd5cb4Sespie   char *s;		/* The string itself, NUL-terminated.  */
2835bd5cb4Sespie }* dyn_string_t;
2935bd5cb4Sespie 
3035bd5cb4Sespie /* The length STR, in bytes, not including the terminating NUL.  */
3135bd5cb4Sespie #define dyn_string_length(STR)                                          \
3235bd5cb4Sespie   ((STR)->length)
3335bd5cb4Sespie 
3435bd5cb4Sespie /* The NTBS in which the contents of STR are stored.  */
3535bd5cb4Sespie #define dyn_string_buf(STR)                                             \
3635bd5cb4Sespie   ((STR)->s)
3735bd5cb4Sespie 
3835bd5cb4Sespie /* Compare DS1 to DS2 with strcmp.  */
3935bd5cb4Sespie #define dyn_string_compare(DS1, DS2)                                    \
4035bd5cb4Sespie   (strcmp ((DS1)->s, (DS2)->s))
4135bd5cb4Sespie 
4235bd5cb4Sespie 
4335bd5cb4Sespie /* dyn_string functions are used in the demangling implementation
4435bd5cb4Sespie    included in the G++ runtime library.  To prevent collisions with
4535bd5cb4Sespie    names in user programs, the functions that are used in the
4635bd5cb4Sespie    demangler are given implementation-reserved names.  */
4735bd5cb4Sespie 
48*d2201f2fSdrahn #if defined(IN_LIBGCC2) || defined(IN_GLIBCPP_V3)
4935bd5cb4Sespie 
5035bd5cb4Sespie #define dyn_string_init                 __cxa_dyn_string_init
5135bd5cb4Sespie #define dyn_string_new                  __cxa_dyn_string_new
5235bd5cb4Sespie #define dyn_string_delete               __cxa_dyn_string_delete
5335bd5cb4Sespie #define dyn_string_release              __cxa_dyn_string_release
5435bd5cb4Sespie #define dyn_string_resize               __cxa_dyn_string_resize
5535bd5cb4Sespie #define dyn_string_clear                __cxa_dyn_string_clear
5635bd5cb4Sespie #define dyn_string_copy                 __cxa_dyn_string_copy
5735bd5cb4Sespie #define dyn_string_copy_cstr            __cxa_dyn_string_copy_cstr
5835bd5cb4Sespie #define dyn_string_prepend              __cxa_dyn_string_prepend
5935bd5cb4Sespie #define dyn_string_prepend_cstr         __cxa_dyn_string_prepend_cstr
6035bd5cb4Sespie #define dyn_string_insert               __cxa_dyn_string_insert
6135bd5cb4Sespie #define dyn_string_insert_cstr          __cxa_dyn_string_insert_cstr
6235bd5cb4Sespie #define dyn_string_insert_char          __cxa_dyn_string_insert_char
6335bd5cb4Sespie #define dyn_string_append               __cxa_dyn_string_append
6435bd5cb4Sespie #define dyn_string_append_cstr          __cxa_dyn_string_append_cstr
6535bd5cb4Sespie #define dyn_string_append_char          __cxa_dyn_string_append_char
6635bd5cb4Sespie #define dyn_string_substring            __cxa_dyn_string_substring
6735bd5cb4Sespie #define dyn_string_eq                   __cxa_dyn_string_eq
6835bd5cb4Sespie 
69*d2201f2fSdrahn #endif /* IN_LIBGCC2 || IN_GLIBCPP_V3 */
7035bd5cb4Sespie 
7135bd5cb4Sespie 
7235bd5cb4Sespie extern int dyn_string_init              PARAMS ((struct dyn_string *, int));
7335bd5cb4Sespie extern dyn_string_t dyn_string_new      PARAMS ((int));
7435bd5cb4Sespie extern void dyn_string_delete           PARAMS ((dyn_string_t));
7535bd5cb4Sespie extern char *dyn_string_release         PARAMS ((dyn_string_t));
7635bd5cb4Sespie extern dyn_string_t dyn_string_resize   PARAMS ((dyn_string_t, int));
7735bd5cb4Sespie extern void dyn_string_clear            PARAMS ((dyn_string_t));
7835bd5cb4Sespie extern int dyn_string_copy              PARAMS ((dyn_string_t, dyn_string_t));
7935bd5cb4Sespie extern int dyn_string_copy_cstr         PARAMS ((dyn_string_t, const char *));
8035bd5cb4Sespie extern int dyn_string_prepend           PARAMS ((dyn_string_t, dyn_string_t));
8135bd5cb4Sespie extern int dyn_string_prepend_cstr      PARAMS ((dyn_string_t, const char *));
8235bd5cb4Sespie extern int dyn_string_insert            PARAMS ((dyn_string_t, int,
8335bd5cb4Sespie 						 dyn_string_t));
8435bd5cb4Sespie extern int dyn_string_insert_cstr       PARAMS ((dyn_string_t, int,
8535bd5cb4Sespie 						 const char *));
8635bd5cb4Sespie extern int dyn_string_insert_char       PARAMS ((dyn_string_t, int, int));
8735bd5cb4Sespie extern int dyn_string_append            PARAMS ((dyn_string_t, dyn_string_t));
8835bd5cb4Sespie extern int dyn_string_append_cstr       PARAMS ((dyn_string_t, const char *));
8935bd5cb4Sespie extern int dyn_string_append_char       PARAMS ((dyn_string_t, int));
9035bd5cb4Sespie extern int dyn_string_substring         PARAMS ((dyn_string_t,
9135bd5cb4Sespie 						 dyn_string_t, int, int));
9235bd5cb4Sespie extern int dyn_string_eq                PARAMS ((dyn_string_t, dyn_string_t));
93