X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fq2c.c;h=ea4e348148b29febf66718075ca8aabfef77eb29;hb=c3ac5a8af9c449072c7e872ca70a78c1755ae309;hp=0b21afbaeed2f208668d4fe345150635c06e2390;hpb=480a0746507ce73d26f528b56dc3ed80195096e0;p=pspp-builds.git diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index 0b21afba..ea4e3481 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -1,37 +1,49 @@ -/* q2c - parser generator for PSPP procedures. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2008 Free Software Foundation, Inc. - This program 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 of the - License, or (at your option) any later version. + This program 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 3 of the License, or + (at your option) any later version. - This program 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. + This program 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 this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -#include + along with this program. If not, see . */ #include #include #include #include #include -#include +#include +#include #include #include -#include -#include -#include -#include "exit.h" - +/* GNU C allows the programmer to declare that certain functions take + printf-like arguments, never return, etc. Conditionalize these + declarations on whether gcc is in use. */ +#if __GNUC__ > 1 +#define ATTRIBUTE(X) __attribute__ (X) +#else +#define ATTRIBUTE(X) +#endif + +/* Marks a function argument as possibly not used. */ +#define UNUSED ATTRIBUTE ((unused)) + +/* Marks a function that will never return. */ +#define NO_RETURN ATTRIBUTE ((noreturn)) + +/* Mark a function as taking a printf- or scanf-like format + string as its FMT'th argument and that the FIRST'th argument + is the first one to be checked against the format string. */ +#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (__printf__, FMT, FIRST))) + /* Max length of an input line. */ #define MAX_LINE_LEN 1024 @@ -138,14 +150,14 @@ static void * xmalloc (size_t size) { void *vp; - + if (size == 0) return NULL; - + vp = malloc (size); if (!vp) fail ("xmalloc(%lu): %s", (unsigned long) size, VME); - + return vp; } @@ -159,11 +171,11 @@ xstrdup (const char *s) assert (s != NULL); size = strlen (s) + 1; - + t = malloc (size); if (!t) fail ("xstrdup(%lu): %s", (unsigned long) strlen (s), VME); - + memcpy (t, s, size); return t; } @@ -178,22 +190,22 @@ get_buffer (void) if (++cb >= 8) cb = 0; - + return b[cb]; } - + /* Copies a string to a static buffer, converting it to lowercase in the process, and returns a pointer to the static buffer. */ static char * st_lower (const char *s) { char *p, *cp; - + p = cp = get_buffer (); while (*s) *cp++ = tolower ((unsigned char) (*s++)); *cp++ = '\0'; - + return p; } @@ -208,7 +220,7 @@ st_upper (const char *s) while (*s) *cp++ = toupper ((unsigned char) (*s++)); *cp++ = '\0'; - + return p; } @@ -325,7 +337,7 @@ find_symbol (int x) return iter; } -#if DUMP_TOKENS +#if DUMP_TOKENS /* Writes a printable representation of the current token to stdout. */ static void @@ -345,6 +357,44 @@ dump_token (void) } #endif /* DUMP_TOKENS */ + +const char hyphen_proxy = '_'; + +static void +id_cpy (char **cp) +{ + char *dest = tokstr; + char *src = *cp; + + while (*src == '_' || *src == '-' || isalnum ((unsigned char) *src)) + { + *dest++ = *src == '-' ? hyphen_proxy :toupper ((unsigned char) (*src)); + src++; + } + + *cp = src; + *dest++ = '\0'; +} + +static char * +unmunge (const char *s) +{ + char *dest = xmalloc (strlen (s)); + char *d = dest; + + while (*s) + { + if (*s == hyphen_proxy) + *d = '-'; + else + *d = *s; + s++; + d++; + } + + return dest; +} + /* Reads a token from the input file. */ static int lex_get (void) @@ -355,11 +405,11 @@ lex_get (void) cp = skip_ws (cp); if (*cp != '\0') break; - + if (!get_line ()) fail ("%s: Unexpected end of file.", ifn); } - + if (*cp == '"') { char *dest = tokstr; @@ -386,17 +436,16 @@ lex_get (void) { char *dest = tokstr; token = T_ID; - while (*cp == '_' || isalnum ((unsigned char) *cp)) - *dest++ = toupper ((unsigned char) (*cp++)); - *dest++ = '\0'; + + id_cpy (&cp); } else token = *cp++; - + #if DUMP_TOKENS dump_token (); #endif - + return token; } @@ -458,7 +507,8 @@ enum { VAL_NONE, /* No value. */ VAL_INT, /* Integer value. */ - VAL_DBL /* Floating point value. */ + VAL_DBL, /* Floating point value. */ + VAL_STRING /* String value. */ }; /* For those specifiers with values, the syntax of those values. */ @@ -497,7 +547,7 @@ struct specifier setting *def; /* Default setting. */ setting *omit_kw; /* Setting for which the keyword can be omitted. */ - + int index; /* Next array index. */ }; @@ -536,7 +586,7 @@ struct subcommand int narray; /* Index of next array element. */ const char *prefix; /* Prefix for variable and constant names. */ specifier *spec; /* Array of specifiers. */ - + /* SBC_STRING and SBC_INT only. */ char *restriction; /* Expression restricting string length. */ char *message; /* Error message. */ @@ -587,7 +637,7 @@ static void parse_setting (setting *s, specifier *spec) { s->parent = spec; - + if (match_token ('*')) { if (spec->omit_kw) @@ -595,7 +645,7 @@ parse_setting (setting *s, specifier *spec) else spec->omit_kw = s; } - + if (match_token ('!')) { if (spec->def) @@ -603,7 +653,7 @@ parse_setting (setting *s, specifier *spec) else spec->def = s; } - + force_id (); s->specname = xstrdup (tokstr); s->con = add_symbol (s->specname, 0, 0); @@ -623,20 +673,22 @@ parse_setting (setting *s, specifier *spec) s->valtype = VT_PLAIN; s->optvalue = match_token ('*'); - + if (match_id ("N")) s->value = VAL_INT; else if (match_id ("D")) s->value = VAL_DBL; + else if (match_id ("S")) + s->value = VAL_STRING; else - error ("`n' or `d' expected."); - + error ("`n', `d', or `s' expected."); + skip_token (':'); - + force_id (); s->valname = xstrdup (tokstr); lex_get (); - + if (token == ',') { lex_get (); @@ -646,7 +698,7 @@ parse_setting (setting *s, specifier *spec) } else s->restriction = NULL; - + if (s->valtype == VT_PAREN) skip_token (')'); } @@ -668,7 +720,7 @@ parse_specifier (specifier *spec, subcommand *sbc) spec->varname = xstrdup (st_lower (tokstr)); lex_get (); } - + /* Handle array elements. */ if (token != ':') { @@ -684,20 +736,20 @@ parse_specifier (specifier *spec, subcommand *sbc) return; } skip_token (':'); - - if ( sbc->type == SBC_ARRAY && token == T_ID ) + + if ( sbc->type == SBC_ARRAY && token == T_ID ) { spec->varname = xstrdup (st_lower (tokstr)); spec->index = sbc->narray; sbc->narray++; } - - - + + + /* Parse all the settings. */ { setting **s = &spec->s; - + for (;;) { *s = xmalloc (sizeof **s); @@ -722,7 +774,7 @@ parse_specifiers (subcommand *sbc) *spec = NULL; return; } - + for (;;) { *spec = xmalloc (sizeof **spec); @@ -756,7 +808,7 @@ parse_subcommand (subcommand *sbc) force_id (); sbc->name = xstrdup (tokstr); lex_get (); - + sbc->narray = 0; sbc->type = SBC_PLAIN; sbc->spec = NULL; @@ -767,10 +819,10 @@ parse_subcommand (subcommand *sbc) force_id (); sbc->prefix = xstrdup (st_lower (tokstr)); lex_get (); - + skip_token (']'); skip_token ('='); - + sbc->type = SBC_ARRAY; parse_specifiers (sbc); @@ -782,12 +834,12 @@ parse_subcommand (subcommand *sbc) force_id (); sbc->prefix = xstrdup (st_lower (tokstr)); lex_get (); - + skip_token (')'); } else sbc->prefix = ""; - + skip_token ('='); if (match_id ("VAR")) @@ -799,7 +851,7 @@ parse_subcommand (subcommand *sbc) force_string (); sbc->message = xstrdup (tokstr); lex_get(); - + skip_token (')'); } else sbc->message = NULL; @@ -809,7 +861,7 @@ parse_subcommand (subcommand *sbc) else if (match_id ("INTEGER")) { sbc->type = match_id ("LIST") ? SBC_INT_LIST : SBC_INT; - if ( token == T_STRING) + if ( token == T_STRING) { sbc->restriction = xstrdup (tokstr); lex_get (); @@ -865,7 +917,7 @@ void parse_subcommands (void) { subcommand **sbc = &subcommands; - + for (;;) { *sbc = xmalloc (sizeof **sbc); @@ -908,7 +960,7 @@ dump (int indention, const char *format, ...) if (indention < 0) indent += BASE_INDENT * indention; - + oln++; va_start (args, format); for (i = 0; i < indent; i++) @@ -928,7 +980,7 @@ dump_specifier_vars (const specifier *spec, const subcommand *sbc) { if (spec->varname) dump (0, "long %s%s;", sbc->prefix, spec->varname); - + { setting *s; @@ -938,8 +990,11 @@ dump_specifier_vars (const specifier *spec, const subcommand *sbc) { const char *typename; - assert (s->value == VAL_INT || s->value == VAL_DBL); - typename = s->value == VAL_INT ? "long" : "double"; + assert (s->value == VAL_INT || s->value == VAL_DBL + || s->value == VAL_STRING); + typename = (s->value == VAL_INT ? "long" + : s->value == VAL_DBL ? "double" + : "char *"); dump (0, "%s %s%s;", typename, sbc->prefix, st_lower (s->valname)); } @@ -979,7 +1034,7 @@ make_identifier (const char *name) else *cp++ = '_'; *cp = '\0'; - + return p; } @@ -989,6 +1044,8 @@ dump_declarations (void) { indent = 0; + dump (0, "struct dataset;"); + /* Write out enums for all the identifiers in the symbol table. */ { int f, k; @@ -1012,7 +1069,7 @@ dump_declarations (void) buf = xmalloc (1024); else dump (0, buf); - + if (k) sprintf (buf, "%s%s,", st_upper (prefix), sym->name); else @@ -1049,7 +1106,7 @@ dump_declarations (void) if (sbc->type == SBC_ARRAY && sbc->narray) { dump (0, "/* Array indices for %s subcommand. */", sbc->name); - + dump (1, "enum"); dump (1, "{"); @@ -1082,7 +1139,7 @@ dump_declarations (void) if (sbc != subcommands) dump (0, nullstr); - + dump (0, "/* %s subcommand. */", sbc->name); dump (0, "int sbc_%s;", st_lower (sbc->name)); @@ -1092,7 +1149,7 @@ dump_declarations (void) case SBC_PLAIN: { specifier *spec; - + for (spec = sbc->spec; spec; spec = spec->next) { if (spec->s == 0) @@ -1102,8 +1159,8 @@ dump_declarations (void) spec->varname); else if (f == 0) { - dump (0, "int a_%s[%s%scount];", - st_lower (sbc->name), + dump (0, "int a_%s[%s%scount];", + st_lower (sbc->name), st_upper (prefix), st_upper (sbc->prefix) ); @@ -1120,12 +1177,12 @@ dump_declarations (void) case SBC_VARLIST: dump (0, "size_t %sn_%s;", st_lower (sbc->prefix), st_lower (sbc->name)); - dump (0, "struct variable **%sv_%s;", st_lower (sbc->prefix), + dump (0, "const struct variable **%sv_%s;", st_lower (sbc->prefix), st_lower (sbc->name)); break; case SBC_VAR: - dump (0, "struct variable *%sv_%s;", st_lower (sbc->prefix), + dump (0, "const struct variable *%sv_%s;", st_lower (sbc->prefix), st_lower (sbc->name)); break; @@ -1212,7 +1269,7 @@ dump_specifier_init (const specifier *spec, const subcommand *sbc) strcpy (s, "-1"); dump (0, "p->%s%s = %s;", sbc->prefix, spec->varname, s); } - + { setting *s; @@ -1222,8 +1279,11 @@ dump_specifier_init (const specifier *spec, const subcommand *sbc) { const char *init; - assert (s->value == VAL_INT || s->value == VAL_DBL); - init = s->value == VAL_INT ? "NOT_LONG" : "SYSMIS"; + assert (s->value == VAL_INT || s->value == VAL_DBL + || s->value == VAL_STRING); + init = (s->value == VAL_INT ? "LONG_MIN" + : s->value == VAL_DBL ? "SYSMIS" + : "NULL"); dump (0, "p->%s%s = %s;", sbc->prefix, st_lower (s->valname), init); } @@ -1238,24 +1298,24 @@ dump_vars_init (int persistent) /* Loop through all the subcommands. */ { subcommand *sbc; - + for (sbc = subcommands; sbc; sbc = sbc->next) { int f = 0; - + dump (0, "p->sbc_%s = 0;", st_lower (sbc->name)); - if ( ! persistent ) + if ( ! persistent ) { switch (sbc->type) { case SBC_INT_LIST: - break; - case SBC_DBL_LIST: dump (1, "{"); dump (0, "int i;"); dump (1, "for (i = 0; i < MAXLISTS; ++i)"); - dump (0, "subc_list_double_create(&p->dl_%s[i]) ;", + dump (0, "subc_list_%s_create(&p->%cl_%s[i]) ;", + sbc->type == SBC_INT_LIST ? "int" : "double", + sbc->type == SBC_INT_LIST ? 'i' : 'd', st_lower (sbc->name) ); dump (-2, "}"); @@ -1272,12 +1332,12 @@ dump_vars_init (int persistent) case SBC_CUSTOM: /* nothing */ break; - + case SBC_PLAIN: case SBC_ARRAY: { specifier *spec; - + for (spec = sbc->spec; spec; spec = spec->next) if (spec->s == NULL) { @@ -1301,7 +1361,7 @@ dump_vars_init (int persistent) dump (0, "p->%sv_%s = NULL;", st_lower (sbc->prefix), st_lower (sbc->name)); break; - + case SBC_VAR: dump (0, "p->%sv_%s = NULL;", st_lower (sbc->prefix), st_lower (sbc->name)); @@ -1316,12 +1376,12 @@ dump_vars_init (int persistent) dump (1, "{"); dump (0, "int i;"); dump (1, "for (i = 0; i < MAXLISTS; ++i)"); - dump (0, "p->n_%s[i] = NOT_LONG;", st_lower (sbc->name)); + dump (0, "p->n_%s[i] = LONG_MIN;", st_lower (sbc->name)); dump (-2, "}"); break; default: - NOT_REACHED (); + abort (); } } } @@ -1339,7 +1399,7 @@ make_match (const char *t) while (*t == '_') t++; - + if (is_keyword (t)) sprintf (s, "lex_match (lexer, T_%s)", t); else if (!strcmp (t, "ON") || !strcmp (t, "YES")) @@ -1351,8 +1411,12 @@ make_match (const char *t) else if (isdigit ((unsigned char) t[0])) sprintf (s, "lex_match_int (lexer, %s)", t); else - sprintf (s, "lex_match_id (lexer, \"%s\")", t); - + { + char *c = unmunge (t); + sprintf (s, "lex_match_hyphenated_word (lexer, \"%s\")", c); + free (c); + } + return s; } @@ -1369,7 +1433,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) if (spec->omit_kw && spec->omit_kw->parent->next) error ("Default specifier is not in last specifier in `%s' " "subcommand.", sbc->name); - + for (s = spec->s; s; s = s->next) { int first = spec == sbc->spec && s == spec->s; @@ -1397,13 +1461,13 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) { if (spec->omit_kw != s) dump (1, "{"); - + if (spec->varname) { dump (0, "p->%s%s = %s%s;", sbc->prefix, spec->varname, st_upper (prefix), find_symbol (s->con)->name); - if ( sbc->type == SBC_ARRAY ) + if ( sbc->type == SBC_ARRAY ) dump (0, "p->a_%s[%s%s%s] = 1;", st_lower (sbc->name), st_upper (prefix), st_upper (sbc->prefix), @@ -1443,7 +1507,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) dump (-1, "p->%s%s = lex_integer (lexer);", sbc->prefix, st_lower (s->valname)); } - else + else if (s->value == VAL_DBL) { dump (1, "if (!lex_is_number (lexer))"); dump (1, "{"); @@ -1455,7 +1519,23 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) dump (-1, "p->%s%s = lex_tokval (lexer);", sbc->prefix, st_lower (s->valname)); } - + else if (s->value == VAL_STRING) + { + dump (1, "if (lex_token (lexer) != T_ID " + "&& lex_token (lexer) != T_STRING)"); + dump (1, "{"); + dump (0, "msg (SE, _(\"%s specifier of %s subcommand " + "requires a string argument.\"));", + s->specname, sbc->name); + dump (0, "goto lossage;"); + dump (-1, "}"); + dump (-1, "free (p->%s%s);", sbc->prefix, st_lower (s->valname)); + dump (0, "p->%s%s = xstrdup (ds_cstr (lex_tokstr (lexer)));", + sbc->prefix, st_lower (s->valname)); + } + else + abort (); + if (s->restriction) { { @@ -1469,7 +1549,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) free (str); free (str2); } - + dump (1, "{"); dump (0, "msg (SE, _(\"Bad argument for %s " "specifier of %s subcommand.\"));", @@ -1478,9 +1558,9 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) dump (-1, "}"); outdent (); } - + dump (0, "lex_get (lexer);"); - + if (s->valtype == VT_PAREN) { dump (1, "if (!lex_match (lexer, ')'))"); @@ -1497,11 +1577,11 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) outdent (); } } - + if (s != spec->omit_kw) dump (-1, "}"); } - + if (s == spec->omit_kw) { dump (-1, "}"); @@ -1521,7 +1601,7 @@ dump_subcommand (const subcommand *sbc) dump (1, "while (lex_token (lexer) != '/' && lex_token (lexer) != '.')"); dump (1, "{"); - + { specifier *spec; @@ -1546,7 +1626,7 @@ dump_subcommand (const subcommand *sbc) } } } - + { specifier *spec; setting *s; @@ -1583,7 +1663,7 @@ dump_subcommand (const subcommand *sbc) } else if (sbc->type == SBC_VARLIST) { - dump (1, "if (!parse_variables (lexer, dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, " + dump (1, "if (!parse_variables_const (lexer, dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, " "PV_APPEND%s%s))", st_lower (sbc->prefix), st_lower (sbc->name), st_lower (sbc->prefix), st_lower (sbc->name), @@ -1633,7 +1713,7 @@ dump_subcommand (const subcommand *sbc) { dump (1, "if (!lex_force_num (lexer))"); dump (0, "goto lossage;"); - dump (-1, "p->n_%s[p->sbc_%s - 1] = lex_number (lexer);", + dump (-1, "p->n_%s[p->sbc_%s - 1] = lex_number (lexer);", st_lower (sbc->name), st_lower (sbc->name) ); dump (0, "lex_get(lexer);"); } @@ -1649,9 +1729,9 @@ dump_subcommand (const subcommand *sbc) { char buf[1024]; dump (1, "if (!(%s))", sbc->restriction); - dump (1, "{"); + dump (1, "{"); sprintf(buf,sbc->message,sbc->name); - if ( sbc->translatable ) + if ( sbc->translatable ) dump (0, "msg (SE, gettext(\"%s\"));",buf); else dump (0, "msg (SE, \"%s\");",buf); @@ -1669,7 +1749,7 @@ dump_subcommand (const subcommand *sbc) dump (-1, "p->n_%s = lex_integer (lexer);", st_lower (sbc->name)); dump (0, "lex_match (lexer, ')');"); } - else if (sbc->type == SBC_DBL_LIST) + else if (sbc->type == SBC_DBL_LIST || sbc->type == SBC_INT_LIST) { dump (0, "if ( p->sbc_%s > MAXLISTS)",st_lower(sbc->name)); dump (1, "{"); @@ -1685,9 +1765,10 @@ dump_subcommand (const subcommand *sbc) dump (0, "goto lossage;"); dump (-1,"}"); - dump (0, "subc_list_double_push (&p->dl_%s[p->sbc_%s-1], lex_number (lexer));", - st_lower (sbc->name), st_lower (sbc->name) - ); + dump (0, "subc_list_%s_push (&p->%cl_%s[p->sbc_%s-1], lex_number (lexer));", + sbc->type == SBC_INT_LIST ? "int" : "double", + sbc->type == SBC_INT_LIST ? 'i' : 'd', + st_lower (sbc->name), st_lower (sbc->name)); dump (0, "lex_get (lexer);"); dump (-1,"}"); @@ -1751,7 +1832,7 @@ dump_parser (int persistent) } dump (1, "{"); dump (0, "p->sbc_%s++;", st_lower (def->name)); - dump (1, "if (!parse_variables (lexer, dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, " + dump (1, "if (!parse_variables_const (lexer, dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, " "PV_APPEND))", st_lower (def->prefix), st_lower (def->name), st_lower (def->prefix), st_lower (def->name)); @@ -1780,7 +1861,7 @@ dump_parser (int persistent) dump (-1, "}"); outdent (); } - + { subcommand *sbc; @@ -1810,22 +1891,22 @@ dump_parser (int persistent) /* Now deal with the /ALGORITHM subcommand implicit to all commands */ - dump(1,"else if ( get_syntax() != COMPATIBLE && lex_match_id(lexer, \"ALGORITHM\"))"); + dump(1,"else if ( settings_get_syntax () != COMPATIBLE && lex_match_id(lexer, \"ALGORITHM\"))"); dump(1,"{"); dump (0, "lex_match (lexer, '=');"); dump(1,"if (lex_match_id(lexer, \"COMPATIBLE\"))"); - dump(0,"set_cmd_algorithm(COMPATIBLE);"); + dump(0,"settings_set_cmd_algorithm (COMPATIBLE);"); outdent(); dump(1,"else if (lex_match_id(lexer, \"ENHANCED\"))"); - dump(0,"set_cmd_algorithm(ENHANCED);"); + dump(0,"settings_set_cmd_algorithm (ENHANCED);"); dump (-1, "}"); outdent (); - + dump (1, "if (!lex_match (lexer, '/'))"); dump (0, "break;"); dump (-2, "}"); @@ -1847,7 +1928,7 @@ dump_parser (int persistent) for (sbc = subcommands; sbc; sbc = sbc->next) { - if ( sbc->arity == ARITY_ONCE_EXACTLY ) + if ( sbc->arity == ARITY_ONCE_EXACTLY ) { dump (0, "if ( 0 == p->sbc_%s)", st_lower (sbc->name)); dump (1, "{"); @@ -1875,18 +1956,10 @@ dump_parser (int persistent) static void dump_header (void) { - time_t curtime; - struct tm *loctime; - char *timep; - indent = 0; - curtime = time (NULL); - loctime = localtime (&curtime); - timep = asctime (loctime); - timep[strlen (timep) - 1] = 0; dump (0, "/* %s\t\t-*- mode: c; buffer-read-only: t -*-", ofn); dump (0, nullstr); - dump (0, " Generated by q2c from %s on %s.", ifn, timep); + dump (0, " Generated by q2c from %s.", ifn); dump (0, " Do not modify!"); dump (0, " */"); } @@ -1901,16 +1974,12 @@ dump_free (int persistent) indent = 0; used = 0; - if ( ! persistent ) + if ( ! persistent ) { for (sbc = subcommands; sbc; sbc = sbc->next) - { - if (sbc->type == SBC_STRING) - used = 1; - if (sbc->type == SBC_DBL_LIST) - used = 1; - } - + used = (sbc->type == SBC_STRING + || sbc->type == SBC_DBL_LIST + || sbc->type == SBC_INT_LIST); } dump (0, "static void"); @@ -1918,12 +1987,12 @@ dump_free (int persistent) make_identifier (cmdname), used ? "" : " UNUSED"); dump (1, "{"); - if ( ! persistent ) + if ( ! persistent ) { for (sbc = subcommands; sbc; sbc = sbc->next) { - switch (sbc->type) + switch (sbc->type) { case SBC_VARLIST: dump (0, "free (p->v_%s);", st_lower (sbc->name)); @@ -1932,13 +2001,28 @@ dump_free (int persistent) dump (0, "free (p->s_%s);", st_lower (sbc->name)); break; case SBC_DBL_LIST: + case SBC_INT_LIST: dump (0, "{"); dump (1, "int i;"); dump (2, "for(i = 0; i < MAXLISTS ; ++i)"); - dump (1, "subc_list_double_destroy(&p->dl_%s[i]);", st_lower (sbc->name)); + dump (1, "subc_list_%s_destroy(&p->%cl_%s[i]);", + sbc->type == SBC_INT_LIST ? "int" : "double", + sbc->type == SBC_INT_LIST ? 'i' : 'd', + st_lower (sbc->name)); dump (0, "}"); outdent(); break; + case SBC_PLAIN: + { + specifier *spec; + setting *s; + + for (spec = sbc->spec; spec; spec = spec->next) + for (s = spec->s; s; s = s->next) + if (s->value == VAL_STRING) + dump (0, "free (p->%s%s);", + sbc->prefix, st_lower (s->valname)); + } default: break; } @@ -1958,7 +2042,7 @@ recognize_directive (void) { static char directive[16]; char *sp, *ep; - + sp = skip_ws (buf); if (strncmp (sp, "/*", 2)) return NULL; @@ -1977,7 +2061,7 @@ recognize_directive (void) directive[ep - sp] = '\0'; return directive; } - + int main (int argc, char *argv[]) { @@ -2012,7 +2096,7 @@ main (int argc, char *argv[]) dump (0, "%s", buf); continue; } - + dump (0, "#line %d \"%s\"", oln + 1, ofn); if (!strcmp (directive, "specification")) { @@ -2030,7 +2114,6 @@ main (int argc, char *argv[]) indent = 0; dump (0, "#include "); - dump (0, "#include "); dump (0, "#include "); dump (0, "#include "); dump (0, "#include "); @@ -2041,6 +2124,9 @@ main (int argc, char *argv[]) dump (0, "#include "); dump (0, nullstr); + dump (0, "#include \"xalloc.h\""); + dump (0, nullstr); + dump (0, "#include \"gettext.h\""); dump (0, "#define _(msgid) gettext (msgid)"); dump (0, nullstr); @@ -2050,12 +2136,12 @@ main (int argc, char *argv[]) else if (!strcmp (directive, "functions")) { dump_parser (0); - dump_free (0); + dump_free (0); } else if (!strcmp (directive, "_functions")) { dump_parser (1); - dump_free (1); + dump_free (1); } else error ("unknown directive `%s'", directive);