From: Ben Pfaff Date: Mon, 15 May 2006 03:53:33 +0000 (+0000) Subject: Get rid of capacity argument to ds_init() and update all callers. X-Git-Tag: v0.6.0~849 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a2039fb1ebfd48013ab259b28091e74e7f50588;p=pspp-builds.git Get rid of capacity argument to ds_init() and update all callers. --- diff --git a/src/data/data-in.c b/src/data/data-in.c index b4658582..4e2e8fcb 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -54,7 +54,7 @@ vdls_error (const struct data_in *i, const char *format, va_list args) if (i->flags & DI_IGNORE_ERROR) return; - ds_init (&text, 64); + ds_init (&text); if (i->f1 == i->f2) ds_printf (&text, _("(column %d"), i->f1); else diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index a4e3b0cb..377241ef 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -89,7 +89,7 @@ error (struct pfm_reader *r, const char *msg, ...) struct string text; va_list args; - ds_init (&text, 64); + ds_init (&text); ds_printf (&text, _("portable file %s corrupt at offset %ld: "), fh_get_file_name (r->fh), ftell (r->file)); va_start (args, msg); diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index b4d4ff29..dda351b9 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -686,7 +686,7 @@ write_vls_length_table (struct sfm_writer *w, struct string vls_length_map; - ds_init (&vls_length_map, 12 * dict_get_var_cnt (dict)); + ds_init (&vls_length_map); vls_hdr.rec_type = 7; vls_hdr.subtype = 14; @@ -732,7 +732,7 @@ write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) struct string long_name_map; size_t i; - ds_init (&long_name_map, 10 * dict_get_var_cnt (dict)); + ds_init (&long_name_map); for (i = 0; i < dict_get_var_cnt (dict); i++) { struct variable *v = dict_get_var (dict, i); diff --git a/src/language/command.c b/src/language/command.c index 1e040d6c..7b903ab1 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -430,7 +430,7 @@ unknown_command_error (char *const words[], size_t word_cnt) struct string s; size_t i; - ds_init (&s, 0); + ds_init (&s); for (i = 0; i < word_cnt; i++) { if (i != 0) diff --git a/src/language/control/repeat.c b/src/language/control/repeat.c index b6897361..b5efdc99 100644 --- a/src/language/control/repeat.c +++ b/src/language/control/repeat.c @@ -469,7 +469,7 @@ do_repeat_filter (struct string *line, void *block_) struct string output; bool dot; - ds_init (&output, ds_capacity (line)); + ds_init (&output); /* Strip trailing whitespace, check for & remove terminal dot. */ while (isspace (ds_last (line))) diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index a8b484d4..e26941b0 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -120,8 +120,8 @@ dfm_open_reader (struct file_handle *fh) r = xmalloc (sizeof *r); r->fh = fh; - ds_init (&r->line, 64); - ds_init (&r->scratch, 0); + ds_init (&r->line); + ds_init (&r->scratch); r->flags = DFM_ADVANCE; r->eof_cnt = 0; if (fh != fh_inline_file ()) diff --git a/src/language/data-io/list.q b/src/language/data-io/list.q index b1bb9aad..84b1ac81 100644 --- a/src/language/data-io/list.q +++ b/src/language/data-io/list.q @@ -604,7 +604,7 @@ determine_layout (void) d->cp_y += d->font_height; } - ds_init(&line_buffer, largest_page_width + 2); + ds_init (&line_buffer); } /* Writes case C to output. */ diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index 71543008..81ed4da8 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -1112,7 +1112,7 @@ no_match (const char *func_name, struct string s; const struct operation *f; - ds_init (&s, 128); + ds_init (&s); if (last - first == 1) { diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index 4cb3f593..750f3053 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -104,8 +104,8 @@ static void dump_token (void); void lex_init (void) { - ds_init (&tokstr, 64); - ds_init (&put_tokstr, 64); + ds_init (&tokstr); + ds_init (&put_tokstr); if (!lex_get_line ()) eof = true; } diff --git a/src/language/line-buffer.c b/src/language/line-buffer.c index e4515320..709bc2f0 100644 --- a/src/language/line-buffer.c +++ b/src/language/line-buffer.c @@ -111,7 +111,7 @@ getl_initialize (void) { ds_create (&getl_include_path, fn_getenv_default ("STAT_INCLUDE_PATH", include_path)); - ds_init (&getl_buf, 256); + ds_init (&getl_buf); init_prompts (); } diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 6e029143..30556119 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,8 @@ +Sun May 14 20:52:20 2006 Ben Pfaff + + * str.c (ds_init): Remove `capacity' argument and just initialize + the string to a capacity of zero. Updated all callers. + Tue May 9 09:56:57 2006 Ben Pfaff * va_copy.h: Removed. Now use va_copy() provided by gnulib diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 70edaeed..ef2be7d0 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -247,13 +247,13 @@ ds_create (struct string *st, const char *s) strcpy (st->string, s); } -/* Initializes ST, making room for at least CAPACITY characters. */ +/* Initializes ST as an empty string. */ void -ds_init (struct string *st, size_t capacity) +ds_init (struct string *st) { st->length = 0; - st->capacity = MAX (8, capacity); - st->string = xmalloc (st->capacity + 1); + st->capacity = 0; + st->string = NULL; } /* Frees ST. */ @@ -285,7 +285,7 @@ ds_init_substring (struct string *dst, const struct string *src, size_t idx, size_t cnt) { assert (dst != src); - ds_init (dst, cnt); + ds_init (dst); ds_assign_substring (dst, src, idx, cnt); } diff --git a/src/libpspp/str.h b/src/libpspp/str.h index aa93fb2b..379762fc 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -117,7 +117,7 @@ struct string #define DS_INITIALIZER {NULL, 0, 0} /* Constructors, destructors. */ -void ds_init (struct string *, size_t); +void ds_init (struct string *); void ds_init_substring (struct string *, const struct string *src, size_t start, size_t cnt); void ds_create (struct string *, const char *); diff --git a/src/output/afm.c b/src/output/afm.c index 8e6d6916..643ce870 100644 --- a/src/output/afm.c +++ b/src/output/afm.c @@ -720,7 +720,7 @@ get_word (struct parser *p, char **word) struct string s; int c; - ds_init (&s, 0); + ds_init (&s); while (!isspace (c = getc (p->file)) && c != EOF) ds_putc (&s, c); ungetc (c, p->file); @@ -756,9 +756,8 @@ force_get_word (struct parser *p) static bool get_string (struct parser *p, char **string) { - struct string s; + struct string s = DS_INITIALIZER; - ds_init (&s, 0); skip_spaces (p); for (;;) { diff --git a/src/output/ascii.c b/src/output/ascii.c index 53610bde..8f960fe3 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -672,7 +672,7 @@ ascii_close_page (struct outp_driver *this) struct string out; int line_num; - ds_init (&out, 128); + ds_init (&out); ds_putc_multiple (&out, '\n', x->top_margin); if (x->headers) diff --git a/src/output/output.c b/src/output/output.c index ffaa7eb8..19761e75 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -286,7 +286,7 @@ outp_read_devices (void) config_path), NULL); - ds_init (&line, 128); + ds_init (&line); if (init_fn == NULL) { @@ -767,7 +767,7 @@ configure_driver_line (struct string *line) for (i = 0; i < 4; i++) { struct string *token = &tokens[i]; - ds_init (token, 0); + ds_init (token); ds_separate (line, token, i < 3 ? ":" : "", &save_idx); ds_trim_spaces (token); } @@ -1032,7 +1032,7 @@ outp_get_paper_size (char *size, int *h, int *v) config_path), NULL); - ds_init (&line, 128); + ds_init (&line); if (pprsz_fn == NULL) { diff --git a/src/output/postscript.c b/src/output/postscript.c index f212bb20..919d1bb7 100644 --- a/src/output/postscript.c +++ b/src/output/postscript.c @@ -874,7 +874,7 @@ write_text (struct outp_driver *this, fprintf (ext->file, "F%d setfont\n", font); } - ds_init (&out, 0); + ds_init (&out); for (i = 0; i < char_cnt; i = j) { for (j = i + 1; j < char_cnt; j++) @@ -1382,7 +1382,7 @@ reencode_font (struct outp_driver *this, struct font *font) line_number = 0; - ds_init (&line, 0); + ds_init (&line); while (ds_get_config_line (file, &line, &line_number)) { char *pschar, *code;