Back to index

cell-binutils  2.17cvs20070401
dyn-string.h
Go to the documentation of this file.
00001 /* An abstract string datatype.
00002    Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
00003    Contributed by Mark Mitchell (mark@markmitchell.com).
00004 
00005 This file is part of GCC.
00006    
00007 GCC is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2, or (at your option)
00010 any later version.
00011 
00012 GCC is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GCC; see the file COPYING.  If not, write to
00019 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
00020 Boston, MA 02110-1301, USA.  */
00021 
00022 
00023 typedef struct dyn_string
00024 {
00025   int allocated;     /* The amount of space allocated for the string.  */
00026   int length;        /* The actual length of the string.  */
00027   char *s;           /* The string itself, NUL-terminated.  */
00028 }* dyn_string_t;
00029 
00030 /* The length STR, in bytes, not including the terminating NUL.  */
00031 #define dyn_string_length(STR)                                          \
00032   ((STR)->length)
00033 
00034 /* The NTBS in which the contents of STR are stored.  */
00035 #define dyn_string_buf(STR)                                             \
00036   ((STR)->s)
00037 
00038 /* Compare DS1 to DS2 with strcmp.  */
00039 #define dyn_string_compare(DS1, DS2)                                    \
00040   (strcmp ((DS1)->s, (DS2)->s))
00041 
00042 
00043 extern int dyn_string_init (struct dyn_string *, int);
00044 extern dyn_string_t dyn_string_new (int);
00045 extern void dyn_string_delete (dyn_string_t);
00046 extern char *dyn_string_release (dyn_string_t);
00047 extern dyn_string_t dyn_string_resize (dyn_string_t, int);
00048 extern void dyn_string_clear (dyn_string_t);
00049 extern int dyn_string_copy (dyn_string_t, dyn_string_t);
00050 extern int dyn_string_copy_cstr (dyn_string_t, const char *);
00051 extern int dyn_string_prepend (dyn_string_t, dyn_string_t);
00052 extern int dyn_string_prepend_cstr (dyn_string_t, const char *);
00053 extern int dyn_string_insert (dyn_string_t, int, dyn_string_t);
00054 extern int dyn_string_insert_cstr (dyn_string_t, int, const char *);
00055 extern int dyn_string_insert_char (dyn_string_t, int, int);
00056 extern int dyn_string_append (dyn_string_t, dyn_string_t);
00057 extern int dyn_string_append_cstr (dyn_string_t, const char *);
00058 extern int dyn_string_append_char (dyn_string_t, int);
00059 extern int dyn_string_substring (dyn_string_t,  dyn_string_t, int, int);
00060 extern int dyn_string_eq (dyn_string_t, dyn_string_t);