Merge commit 'origin/stable'
[pspp-builds.git] / src / language / lexer / q2c.c
index a0a3c67d2d61c36d390323b040bf8a3e211f0330..be0f29c5216ac392209e3e075a6df469208b54b2 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   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
@@ -357,6 +357,45 @@ 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) + 1);
+  char *d = dest;
+
+  while (*s)
+    {
+      if (*s == hyphen_proxy)
+       *d = '-';
+      else
+       *d = *s;
+      s++;
+      d++;
+    }
+  *d = '\0';
+
+  return dest;
+}
+
 /* Reads a token from the input file. */
 static int
 lex_get (void)
@@ -398,9 +437,8 @@ 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++;
@@ -1244,7 +1282,7 @@ dump_specifier_init (const specifier *spec, const subcommand *sbc)
 
            assert (s->value == VAL_INT || s->value == VAL_DBL
                     || s->value == VAL_STRING);
-           init = (s->value == VAL_INT ? "NOT_LONG"
+           init = (s->value == VAL_INT ? "LONG_MIN"
                     : s->value == VAL_DBL ? "SYSMIS"
                     : "NULL");
 
@@ -1339,7 +1377,7 @@ 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;
 
@@ -1374,7 +1412,11 @@ 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;
 }
@@ -1850,16 +1892,16 @@ 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 ();
@@ -2073,18 +2115,19 @@ main (int argc, char *argv[])
          indent = 0;
 
          dump (0, "#include <stdlib.h>");
-         dump (0, "#include <libpspp/alloc.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/magic.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 \"xalloc.h\"");
+         dump (0, nullstr);
+
           dump (0, "#include \"gettext.h\"");
           dump (0, "#define _(msgid) gettext (msgid)");
          dump (0, nullstr);