-/* 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.
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* 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;
/* 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;
+
+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) + 1);
+ char *d = dest;
+
+ while (*s)
+ {
+ if (*s == hyphen_proxy)
+ *d = '-';
+ else
+ *d = *s;
+ s++;
+ d++;
+ }
+ *d = '\0';
+
+ return dest;
+}
+
setting *def; /* Default setting. */
setting *omit_kw; /* Setting for which the keyword can be omitted. */
setting *def; /* Default setting. */
setting *omit_kw; /* Setting for which the keyword can be omitted. */
int narray; /* Index of next array element. */
const char *prefix; /* Prefix for variable and constant names. */
specifier *spec; /* Array of specifiers. */
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. */
/* SBC_STRING and SBC_INT only. */
char *restriction; /* Expression restricting string length. */
char *message; /* Error message. */
force_id ();
s->specname = xstrdup (tokstr);
s->con = add_symbol (s->specname, 0, 0);
force_id ();
s->specname = xstrdup (tokstr);
s->con = add_symbol (s->specname, 0, 0);
{
if (spec->varname)
dump (0, "long %s%s;", sbc->prefix, spec->varname);
{
if (spec->varname)
dump (0, "long %s%s;", sbc->prefix, spec->varname);
if (k)
sprintf (buf, "%s%s,", st_upper (prefix), sym->name);
else
if (k)
sprintf (buf, "%s%s,", st_upper (prefix), sym->name);
else
if (sbc->type == SBC_ARRAY && sbc->narray)
{
dump (0, "/* Array indices for %s subcommand. */", sbc->name);
if (sbc->type == SBC_ARRAY && sbc->narray)
{
dump (0, "/* Array indices for %s subcommand. */", sbc->name);
dump (0, "/* %s subcommand. */", sbc->name);
dump (0, "int sbc_%s;", st_lower (sbc->name));
dump (0, "/* %s subcommand. */", sbc->name);
dump (0, "int sbc_%s;", st_lower (sbc->name));
strcpy (s, "-1");
dump (0, "p->%s%s = %s;", sbc->prefix, spec->varname, s);
}
strcpy (s, "-1");
dump (0, "p->%s%s = %s;", sbc->prefix, spec->varname, s);
}
dump (0, "p->%sv_%s = NULL;",
st_lower (sbc->prefix), st_lower (sbc->name));
break;
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));
case SBC_VAR:
dump (0, "p->%sv_%s = NULL;",
st_lower (sbc->prefix), st_lower (sbc->name));
if (is_keyword (t))
sprintf (s, "lex_match (lexer, T_%s)", t);
else if (!strcmp (t, "ON") || !strcmp (t, "YES"))
if (is_keyword (t))
sprintf (s, "lex_match (lexer, T_%s)", t);
else if (!strcmp (t, "ON") || !strcmp (t, "YES"))
else if (isdigit ((unsigned char) t[0]))
sprintf (s, "lex_match_int (lexer, %s)", t);
else
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);
+ }
+
if (spec->omit_kw && spec->omit_kw->parent->next)
error ("Default specifier is not in last specifier in `%s' "
"subcommand.", sbc->name);
if (spec->omit_kw && spec->omit_kw->parent->next)
error ("Default specifier is not in last specifier in `%s' "
"subcommand.", sbc->name);
if (spec->varname)
{
dump (0, "p->%s%s = %s%s;", sbc->prefix, spec->varname,
st_upper (prefix), find_symbol (s->con)->name);
if (spec->varname)
{
dump (0, "p->%s%s = %s%s;", sbc->prefix, spec->varname,
st_upper (prefix), find_symbol (s->con)->name);
dump (0, "p->a_%s[%s%s%s] = 1;",
st_lower (sbc->name),
st_upper (prefix), st_upper (sbc->prefix),
dump (0, "p->a_%s[%s%s%s] = 1;",
st_lower (sbc->name),
st_upper (prefix), st_upper (sbc->prefix),
dump (-1, "p->%s%s = lex_tokval (lexer);", sbc->prefix,
st_lower (s->valname));
}
dump (-1, "p->%s%s = lex_tokval (lexer);", sbc->prefix,
st_lower (s->valname));
}
{
dump (1, "if (lex_token (lexer) != T_ID "
"&& lex_token (lexer) != T_STRING)");
{
dump (1, "if (lex_token (lexer) != T_ID "
"&& lex_token (lexer) != T_STRING)");
dump (1, "{");
dump (0, "msg (SE, _(\"Bad argument for %s "
"specifier of %s subcommand.\"));",
dump (1, "{");
dump (0, "msg (SE, _(\"Bad argument for %s "
"specifier of %s subcommand.\"));",
if (s->valtype == VT_PAREN)
{
dump (1, "if (!lex_match (lexer, ')'))");
if (s->valtype == VT_PAREN)
{
dump (1, "if (!lex_match (lexer, ')'))");
{
dump (1, "if (!lex_force_num (lexer))");
dump (0, "goto lossage;");
{
dump (1, "if (!lex_force_num (lexer))");
dump (0, "goto lossage;");
st_lower (sbc->name), st_lower (sbc->name) );
dump (0, "lex_get(lexer);");
}
st_lower (sbc->name), st_lower (sbc->name) );
dump (0, "lex_get(lexer);");
}
dump (0, "msg (SE, gettext(\"%s\"));",buf);
else
dump (0, "msg (SE, \"%s\");",buf);
dump (0, "msg (SE, gettext(\"%s\"));",buf);
else
dump (0, "msg (SE, \"%s\");",buf);
dump(1,"{");
dump (0, "lex_match (lexer, '=');");
dump(1,"if (lex_match_id(lexer, \"COMPATIBLE\"))");
dump(1,"{");
dump (0, "lex_match (lexer, '=');");
dump(1,"if (lex_match_id(lexer, \"COMPATIBLE\"))");
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));
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));
dump (0, "#line %d \"%s\"", oln + 1, ofn);
if (!strcmp (directive, "specification"))
{
dump (0, "#line %d \"%s\"", oln + 1, ofn);
if (!strcmp (directive, "specification"))
{
dump (0, "#include <libpspp/assertion.h>");
dump (0, "#include <libpspp/message.h>");
dump (0, "#include <language/lexer/lexer.h>");
dump (0, "#include <language/lexer/variable-parser.h>");
dump (0, "#include <data/settings.h>");
dump (0, "#include <libpspp/assertion.h>");
dump (0, "#include <libpspp/message.h>");
dump (0, "#include <language/lexer/lexer.h>");
dump (0, "#include <language/lexer/variable-parser.h>");
dump (0, "#include <data/settings.h>");
dump (0, "#include <libpspp/str.h>");
dump (0, "#include <language/lexer/subcommand-list.h>");
dump (0, "#include <data/variable.h>");
dump (0, nullstr);
dump (0, "#include <libpspp/str.h>");
dump (0, "#include <language/lexer/subcommand-list.h>");
dump (0, "#include <data/variable.h>");
dump (0, nullstr);
dump (0, "#include \"gettext.h\"");
dump (0, "#define _(msgid) gettext (msgid)");
dump (0, nullstr);
dump (0, "#include \"gettext.h\"");
dump (0, "#define _(msgid) gettext (msgid)");
dump (0, nullstr);