xref: /netbsd-src/external/gpl3/binutils.old/dist/include/dyn-string.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* An abstract string datatype.
2*e992f068Schristos    Copyright (C) 1998-2022 Free Software Foundation, Inc.
375fd0b74Schristos    Contributed by Mark Mitchell (mark@markmitchell.com).
475fd0b74Schristos 
575fd0b74Schristos This file is part of GCC.
675fd0b74Schristos 
775fd0b74Schristos GCC is free software; you can redistribute it and/or modify
875fd0b74Schristos it under the terms of the GNU General Public License as published by
975fd0b74Schristos the Free Software Foundation; either version 2, or (at your option)
1075fd0b74Schristos any later version.
1175fd0b74Schristos 
1275fd0b74Schristos GCC is distributed in the hope that it will be useful,
1375fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1475fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1575fd0b74Schristos GNU General Public License for more details.
1675fd0b74Schristos 
1775fd0b74Schristos You should have received a copy of the GNU General Public License
1875fd0b74Schristos along with GCC; see the file COPYING.  If not, write to
1975fd0b74Schristos the Free Software Foundation, 51 Franklin Street - Fifth Floor,
2075fd0b74Schristos Boston, MA 02110-1301, USA.  */
2175fd0b74Schristos 
2275fd0b74Schristos #ifndef DYN_STRING_H
2375fd0b74Schristos #define DYN_STRING_H
2475fd0b74Schristos 
2575fd0b74Schristos #ifdef __cplusplus
2675fd0b74Schristos extern "C" {
2775fd0b74Schristos #endif
2875fd0b74Schristos 
2975fd0b74Schristos typedef struct dyn_string
3075fd0b74Schristos {
3175fd0b74Schristos   int allocated;	/* The amount of space allocated for the string.  */
3275fd0b74Schristos   int length;		/* The actual length of the string.  */
3375fd0b74Schristos   char *s;		/* The string itself, NUL-terminated.  */
3475fd0b74Schristos }* dyn_string_t;
3575fd0b74Schristos 
3675fd0b74Schristos /* The length STR, in bytes, not including the terminating NUL.  */
3775fd0b74Schristos #define dyn_string_length(STR)                                          \
3875fd0b74Schristos   ((STR)->length)
3975fd0b74Schristos 
4075fd0b74Schristos /* The NTBS in which the contents of STR are stored.  */
4175fd0b74Schristos #define dyn_string_buf(STR)                                             \
4275fd0b74Schristos   ((STR)->s)
4375fd0b74Schristos 
4475fd0b74Schristos /* Compare DS1 to DS2 with strcmp.  */
4575fd0b74Schristos #define dyn_string_compare(DS1, DS2)                                    \
4675fd0b74Schristos   (strcmp ((DS1)->s, (DS2)->s))
4775fd0b74Schristos 
4875fd0b74Schristos 
4975fd0b74Schristos extern int dyn_string_init (struct dyn_string *, int);
5075fd0b74Schristos extern dyn_string_t dyn_string_new (int);
5175fd0b74Schristos extern void dyn_string_delete (dyn_string_t);
5275fd0b74Schristos extern char *dyn_string_release (dyn_string_t);
5375fd0b74Schristos extern dyn_string_t dyn_string_resize (dyn_string_t, int);
5475fd0b74Schristos extern void dyn_string_clear (dyn_string_t);
5575fd0b74Schristos extern int dyn_string_copy (dyn_string_t, dyn_string_t);
5675fd0b74Schristos extern int dyn_string_copy_cstr (dyn_string_t, const char *);
5775fd0b74Schristos extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
5875fd0b74Schristos extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
5975fd0b74Schristos extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
6075fd0b74Schristos extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
6175fd0b74Schristos extern int dyn_string_insert_char (dyn_string_t, int, int);
6275fd0b74Schristos extern int dyn_string_append (dyn_string_t, dyn_string_t);
6375fd0b74Schristos extern int dyn_string_append_cstr (dyn_string_t, const char *);
6475fd0b74Schristos extern int dyn_string_append_char (dyn_string_t, int);
6575fd0b74Schristos extern int dyn_string_substring (dyn_string_t,  dyn_string_t, int, int);
6675fd0b74Schristos extern int dyn_string_eq (dyn_string_t, dyn_string_t);
6775fd0b74Schristos 
6875fd0b74Schristos #ifdef __cplusplus
6975fd0b74Schristos }
7075fd0b74Schristos #endif
7175fd0b74Schristos 
7275fd0b74Schristos #endif /* !defined (DYN_STRING_H) */
73