0056a9b5cf
* configure.in (host_xm_file, build_xm_file, xm_file, tm_file): Arrange to include gansidecl.h in {ht}config.h & tm.h just before the config/ directory headers. (tm_file_list, host_xm_file_list, build_xm_file_list): Handle gansidecl.h in the list of dependencies. * Makefile.in (RTL_BASE_H): Don't depend on gansidecl.h. (TREE_H, DEMANGLE_H, RECOG_H, REGS_H, libgcc2.a, stmp-multilib, mbchar.o, collect2.o, pexecute.o, vfprintf.o, splay-tree.o, gcc.o, gencheck.o, choose-temp.o, mkstemp.o, mkstemp.o, prefix.o, dyn-string.o, cexp.o, cccp.o, cppmain.o, cpplib.o, cpperror.o, cppexp.o, cppfiles.o, cpphash.o, cppalloc.o, scan-decls.o): Likewise. * cccp.c: Don't include gansidecl.h. * cexp.y: Likewise. * collect2.c: Likewise. * config/c4x/c4x.c: Likewise. * config/v850/v850.h: Likewise. * cppalloc.c: Likewise. * cpperror.c: Likewise. * cppexp.c: Likewise. * cppfiles.c: Likewise. * cpphash.c: Likewise. * cpplib.c: Likewise. * cppmain.c: Likewise. * cppulp.c: Likewise. * demangle.h: Likewise. * doprint.c: Likewise. * dyn-string.c: Likewise. * eh-common.h: Likewise. * fix-header.c: Likewise. * frame.c: Likewise. * gcc.c: Likewise. * gcov.c: Likewise. * gen-protos.c: Likewise. * gencheck.c: Likewise. * halfpic.h: Likewise. * hash.c: Likewise. * machmode.h: Likewise. * mbchar.c: Likewise. * prefix.c: Likewise. * protoize.c: Likewise. * recog.h: Likewise. * rtl.h: Likewise. * scan-decls.c: Likewise. * tree.h: Likewise. * varray.h: Likewise. From-SVN: r23558
100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
/* An abstract string datatype.
|
|
Copyright (C) 1998 Free Software Foundation, Inc.
|
|
Contributed by Mark Mitchell (mark@markmitchell.com).
|
|
|
|
This file is part of GNU CC.
|
|
|
|
GNU CC is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GNU CC is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GNU CC; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "dyn-string.h"
|
|
|
|
extern char *xmalloc ();
|
|
extern char *xrealloc ();
|
|
|
|
/* Create a new dynamic string capable of holding at least SPACE
|
|
characters, including the terminating NUL. If SPACE is 0, it
|
|
will be silently increased to 1. */
|
|
|
|
dyn_string_t
|
|
dyn_string_new (space)
|
|
int space;
|
|
{
|
|
dyn_string_t result = (dyn_string_t) xmalloc (sizeof (struct dyn_string));
|
|
|
|
if (space == 0)
|
|
/* We need at least one byte in which to store the terminating
|
|
NUL. */
|
|
space = 1;
|
|
|
|
result->allocated = space;
|
|
result->s = (char*) xmalloc (space);
|
|
result->length = 0;
|
|
result->s[0] = '\0';
|
|
|
|
return result;
|
|
}
|
|
|
|
/* Free the memory used by DS. */
|
|
|
|
void
|
|
dyn_string_delete (ds)
|
|
dyn_string_t ds;
|
|
{
|
|
free (ds->s);
|
|
free (ds);
|
|
}
|
|
|
|
/* Append the NUL-terminated string S to DS, resizing DS if
|
|
necessary. */
|
|
|
|
dyn_string_t
|
|
dyn_string_append (ds, s)
|
|
dyn_string_t ds;
|
|
char *s;
|
|
{
|
|
int len = strlen (s);
|
|
dyn_string_resize (ds, ds->length + len + 1 /* '\0' */);
|
|
strcpy (ds->s + ds->length, s);
|
|
ds->length += len;
|
|
|
|
return ds;
|
|
}
|
|
|
|
/* Increase the capacity of DS so that it can hold at least SPACE
|
|
characters, including the terminating NUL. This function will not
|
|
(at present) reduce the capacity of DS. */
|
|
|
|
dyn_string_t
|
|
dyn_string_resize (ds, space)
|
|
dyn_string_t ds;
|
|
int space;
|
|
{
|
|
int new_allocated = ds->allocated;
|
|
|
|
while (space > new_allocated)
|
|
new_allocated *= 2;
|
|
|
|
if (new_allocated != ds->allocated)
|
|
{
|
|
/* We actually need more space. */
|
|
ds->allocated = new_allocated;
|
|
ds->s = (char*) xrealloc (ds->s, ds->allocated);
|
|
}
|
|
|
|
return ds;
|
|
}
|