X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fq2c.c;h=27ff530d318eb9c364ba7db5d59fb8e99c13cc4a;hb=bd0fbcb4295cf0fbcfa5c2a8fc607842c958ad65;hp=f53ccfc33c181ad48cba48705f35e23d5cb2d552;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index f53ccfc33c..27ff530d31 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -585,11 +585,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. */ - int translatable; /* Error message is translatable */ + char *pv_options; /* PV_* options for SBC_VARLIST. */ }; /* Name of the command; i.e., DESCRIPTIVES. */ @@ -811,7 +807,6 @@ parse_subcommand (subcommand *sbc) sbc->narray = 0; sbc->type = SBC_PLAIN; sbc->spec = NULL; - sbc->translatable = 0; if (match_token ('[')) { @@ -848,39 +843,18 @@ parse_subcommand (subcommand *sbc) if (match_token ('(')) { force_string (); - sbc->message = xstrdup (tokstr); + sbc->pv_options = xstrdup (tokstr); lex_get(); skip_token (')'); } - else sbc->message = NULL; + else + sbc->pv_options = NULL; sbc->type = SBC_VARLIST; } else if (match_id ("INTEGER")) - { sbc->type = match_id ("LIST") ? SBC_INT_LIST : SBC_INT; - if ( token == T_STRING) - { - sbc->restriction = xstrdup (tokstr); - lex_get (); - if ( match_id("N_") ) - { - skip_token('('); - force_string (); - lex_get(); - skip_token(')'); - sbc->translatable = 1; - } - else { - force_string (); - lex_get (); - } - sbc->message = xstrdup (tokstr); - } - else - sbc->restriction = NULL; - } else if (match_id ("PINT")) sbc->type = SBC_PINT; else if (match_id ("DOUBLE")) @@ -891,19 +865,7 @@ parse_subcommand (subcommand *sbc) sbc->type = SBC_DBL; } else if (match_id ("STRING")) - { - sbc->type = SBC_STRING; - if (token == T_STRING) - { - sbc->restriction = xstrdup (tokstr); - lex_get (); - force_string (); - sbc->message = xstrdup (tokstr); - lex_get (); - } - else - sbc->restriction = NULL; - } + sbc->type = SBC_STRING; else if (match_id ("CUSTOM")) sbc->type = SBC_CUSTOM; else @@ -1500,10 +1462,9 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) { dump (1, "if (!lex_match (lexer, T_LPAREN))"); dump (1, "{"); - dump (0, "msg (SE, _(\"`(' expected after %s " - "specifier of %s subcommand.\"));", - s->specname, sbc->name); - dump (0, "goto lossage;"); + dump (0, "lex_error_expecting (lexer, \"`('\", " + "NULL_SENTINEL);"); + dump (0, "goto lossage;"); dump (-1, "}"); outdent (); } @@ -1511,38 +1472,22 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) if (s->value == VAL_INT) { - dump (1, "if (!lex_is_integer (lexer))"); - dump (1, "{"); - dump (0, "msg (SE, _(\"%s specifier of %s subcommand " - "requires an integer argument.\"));", - s->specname, sbc->name); + dump (1, "if (!lex_force_int (lexer))"); dump (0, "goto lossage;"); - dump (-1, "}"); dump (-1, "p->%s%s = lex_integer (lexer);", sbc->prefix, st_lower (s->valname)); } else if (s->value == VAL_DBL) { - dump (1, "if (!lex_is_number (lexer))"); - dump (1, "{"); - dump (0, "msg (SE, _(\"Number expected after %s " - "specifier of %s subcommand.\"));", - s->specname, sbc->name); + dump (1, "if (!lex_force_num (lexer))"); dump (0, "goto lossage;"); - dump (-1, "}"); 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_is_string (lexer))"); - dump (1, "{"); - dump (0, "msg (SE, _(\"%s specifier of %s subcommand " - "requires a string argument.\"));", - s->specname, sbc->name); + dump (1, "if (!lex_force_string_or_id (lexer))"); dump (0, "goto lossage;"); - dump (-1, "}"); dump (-1, "free (p->%s%s);", sbc->prefix, st_lower (s->valname)); dump (0, "p->%s%s = ss_xstrdup (ss_tokss (lexer));", sbc->prefix, st_lower (s->valname)); @@ -1565,9 +1510,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) } dump (1, "{"); - dump (0, "msg (SE, _(\"Bad argument for %s " - "specifier of %s subcommand.\"));", - s->specname, sbc->name); + dump (0, "lex_error (lexer, NULL);"); dump (0, "goto lossage;"); dump (-1, "}"); outdent (); @@ -1577,13 +1520,8 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc) if (s->valtype == VT_PAREN) { - dump (1, "if (!lex_match (lexer, T_RPAREN))"); - dump (1, "{"); - dump (0, "msg (SE, _(\"`)' expected after argument for " - "%s specifier of %s.\"));", - s->specname, sbc->name); + dump (1, "if (!lex_force_match (lexer, T_RPAREN))"); dump (0, "goto lossage;"); - dump (-1, "}"); outdent (); if (s->optvalue) { @@ -1681,8 +1619,8 @@ dump_subcommand (const subcommand *sbc) "PV_APPEND%s%s))", st_lower (sbc->prefix), st_lower (sbc->name), st_lower (sbc->prefix), st_lower (sbc->name), - sbc->message ? " |" : "", - sbc->message ? sbc->message : ""); + sbc->pv_options ? " |" : "", + sbc->pv_options ? sbc->pv_options : ""); dump (0, "goto lossage;"); outdent (); } @@ -1697,31 +1635,13 @@ dump_subcommand (const subcommand *sbc) } else if (sbc->type == SBC_STRING) { - if (sbc->restriction) - { - dump (1, "{"); - dump (0, "int x;"); - } dump (1, "if (!lex_force_string (lexer))"); dump (0, "return false;"); outdent (); - if (sbc->restriction) - { - dump (0, "x = ss_length (lex_tokss (lexer));"); - dump (1, "if (!(%s))", sbc->restriction); - dump (1, "{"); - dump (0, "msg (SE, _(\"String for %s must be %s.\"));", - sbc->name, sbc->message); - dump (0, "goto lossage;"); - dump (-1, "}"); - outdent (); - } dump (0, "free(p->s_%s);", st_lower(sbc->name) ); dump (0, "p->s_%s = ss_xstrdup (lex_tokss (lexer));", st_lower (sbc->name)); dump (0, "lex_get (lexer);"); - if (sbc->restriction) - dump (-1, "}"); } else if (sbc->type == SBC_DBL) { @@ -1739,19 +1659,6 @@ dump_subcommand (const subcommand *sbc) dump (0, "goto lossage;"); dump (-1, "x = lex_integer (lexer);"); dump (0, "lex_get(lexer);"); - if (sbc->restriction) - { - char buf[1024]; - dump (1, "if (!(%s))", sbc->restriction); - dump (1, "{"); - sprintf(buf,sbc->message,sbc->name); - if ( sbc->translatable ) - dump (0, "msg (SE, gettext(\"%s\"));",buf); - else - dump (0, "msg (SE, \"%s\");",buf); - dump (0, "goto lossage;"); - dump (-1, "}"); - } dump (0, "p->n_%s[p->sbc_%s - 1] = x;", st_lower (sbc->name), st_lower(sbc->name) ); dump (-1,"}"); } @@ -1767,7 +1674,8 @@ dump_subcommand (const subcommand *sbc) { dump (0, "if ( p->sbc_%s > MAXLISTS)",st_lower(sbc->name)); dump (1, "{"); - dump (0, "msg (SE, \"No more than %%d %s subcommands allowed\",MAXLISTS);",st_lower(sbc->name)); + dump (0, "subc_list_error (lexer, \"%s\", MAXLISTS);", + st_lower(sbc->name)); dump (0, "goto lossage;"); dump (-1,"}"); @@ -1821,7 +1729,7 @@ dump_parser (int persistent) dump (0, "static int"); dump (0, "parse_%s (struct lexer *lexer, struct dataset *ds%s, struct cmd_%s *p, void *aux UNUSED)", make_identifier (cmdname), - (def && ( def->type == SBC_VARLIST && def->type == SBC_CUSTOM))?"":" UNUSED", + (def && ( def->type == SBC_VARLIST || def->type == SBC_CUSTOM))?"":" UNUSED", make_identifier (cmdname)); dump (1, "{"); @@ -1891,8 +1799,7 @@ dump_parser (int persistent) { dump (1, "if (p->sbc_%s > 1)", st_lower (sbc->name)); dump (1, "{"); - dump (0, "msg (SE, _(\"%s subcommand may be given only once.\"));", - sbc->name); + dump (0, "lex_sbc_only_once (\"%s\");", sbc->name); dump (0, "goto lossage;"); dump (-1, "}"); outdent (); @@ -1946,8 +1853,7 @@ dump_parser (int persistent) { dump (0, "if ( 0 == p->sbc_%s)", st_lower (sbc->name)); dump (1, "{"); - dump (0, "msg (SE, _(\"%s subcommand must be given.\"));", - sbc->name); + dump (0, "lex_sbc_missing (\"%s\");", sbc->name); dump (0, "goto lossage;"); dump (-1, "}"); dump_blank_line (0); @@ -2136,16 +2042,13 @@ main (int argc, char *argv[]) dump (0, "#include \"language/lexer/subcommand-list.h\""); dump (0, "#include \"language/lexer/variable-parser.h\""); dump (0, "#include \"libpspp/assertion.h\""); + dump (0, "#include \"libpspp/cast.h\""); dump (0, "#include \"libpspp/message.h\""); dump (0, "#include \"libpspp/str.h\""); dump_blank_line (0); dump (0, "#include \"gl/xalloc.h\""); dump_blank_line (0); - - dump (0, "#include \"gettext.h\""); - dump (0, "#define _(msgid) gettext (msgid)"); - dump_blank_line (0); } else if (!strcmp (directive, "declarations")) dump_declarations ();