8sa1-gcc/gcc/dyn-string.c
Kaveh R. Ghazi 87e11268b6 cpplib.c (special_symbol): Qualify a char* with the `const' keyword.
* cpplib.c (special_symbol): Qualify a char* with the `const' keyword.
        Instead of writing to const char *buf directly, use a non-const
        variable `wbuf' to allocate and write a string, then set buf = wbuf.
        * cppulp.c (user_label_prefix): Qualify a char* with the `const'
        keyword.
        * dyn-string.c (dyn_string_append): Likewise.
        * dyn-string.h (dyn_string_append): Likewise.
        * final.c (end_final, output_operand_lossage, asm_fprintf): Likewise.
        * output.h (end_final, output_operand_lossage, asm_fprintf,
        named_section, decode_reg_name, make_decl_rtl, user_label_prefix):
        Likewise.
        * profile.c (init_branch_prob): Likewise.
        * toplev.c (set_target_switch, vmessage,
        v_message_with_file_and_line, v_message_with_decl,
        v_error_with_file_and_line, v_error_with_decl, v_error_for_asm,
        verror, vfatal, v_warning_with_file_and_line, v_warning_with_decl,
        v_warning_for_asm, vwarning, vpedwarn, v_pedwarn_with_decl,
        v_pedwarn_with_file_and_line, vsorry, v_really_sorry,
        open_dump_file, dump_rtl, clean_dump_file,
        print_version, print_single_switch, print_switch_values,
        dump_base_name, debug_args, lang_independent_options,
        user_label_prefix, documented_lang_options, target_switches,
        target_options, print_time, pfatal_with_name, fatal_io_error,
        fatal_insn, default_print_error_function, print_error_function,
        report_error_function, error_with_file_and_line, error_with_decl,
        error_for_asm, error, fatal, warning_with_file_and_line,
        warning_with_decl, warning_for_asm, warning, pedwarn,
        pedwarn_with_decl, pedwarn_with_file_and_line, sorry,
        really_sorry, botch, output_quoted_string, output_file_directive,
        open_dump_file, rest_of_decl_compilation, display_help, main):
        Likewise.
        * toplev.h (print_time, fatal, fatal_io_error, pfatal_with_name,
        fatal_insn, warning, error, pedwarn, pedwarn_with_file_and_line,
        warning_with_file_and_line, error_with_file_and_line, sorry,
        really_sorry, default_print_error_function, report_error_function,
        rest_of_decl_compilation, pedwarn_with_decl, warning_with_decl,
        error_with_decl, error_for_asm, warning_for_asm, output_quoted_string,
        output_file_directive, botch): Likewise.
        * tree.h (make_decl_rtl): Likewise.
        * varasm.c (strip_reg_name, named_section, decode_reg_name,
        make_decl_rtl): Likewise.

From-SVN: r24743
1999-01-18 08:53:41 +00:00

98 lines
2.4 KiB
C

/* An abstract string datatype.
Copyright (C) 1998, 1999 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, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "dyn-string.h"
/* 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;
const 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;
}