Add aux data parameter to q2c parse_<command>() and custom parser
[pspp-builds.git] / src / language / lexer / q2c.c
index 72ce7addc9f6ebcdf9d2a047e66c9c0c22347cb0..a62cf9171b30442fdc5adb4ebe2d075a76425b24 100644 (file)
 #include <unistd.h>
 #include <libpspp/compiler.h>
 #include <libpspp/str.h>
-
-
-/* Brokenness. */
-#ifndef EXIT_SUCCESS
-#define EXIT_SUCCESS 0
-#endif
-
-#ifndef EXIT_FAILURE
-#define EXIT_FAILURE 1
-#endif
+#include "exit.h"
 
      
-#include <libpspp/debug-print.h>
-
 /* Max length of an input line. */
 #define MAX_LINE_LEN 1024
 
@@ -1188,7 +1177,7 @@ dump_declarations (void)
              dump (0, "/* Prototype for custom subcommands of %s. */",
                    cmdname);
            }
-         dump (0, "static int %scustom_%s (struct cmd_%s *);",
+         dump (0, "static int %scustom_%s (struct cmd_%s *, void *);",
                st_lower (prefix), st_lower (sbc->name),
                make_identifier (cmdname));
        }
@@ -1200,7 +1189,7 @@ dump_declarations (void)
   /* Prototypes for parsing and freeing functions. */
   {
     dump (0, "/* Command parsing functions. */");
-    dump (0, "static int parse_%s (struct cmd_%s *);",
+    dump (0, "static int parse_%s (struct cmd_%s *, void *);",
          make_identifier (cmdname), make_identifier (cmdname));
     dump (0, "static void free_%s (struct cmd_%s *);",
          make_identifier (cmdname), make_identifier (cmdname));
@@ -1635,7 +1624,7 @@ dump_subcommand (const subcommand *sbc)
          outdent ();
        }
       dump (0, "free(p->s_%s);", st_lower(sbc->name) );
-      dump (0, "p->s_%s = xstrdup (ds_c_str (&tokstr));",
+      dump (0, "p->s_%s = ds_xstrdup (&tokstr);",
            st_lower (sbc->name));
       dump (0, "lex_get ();");
       if (sbc->restriction)
@@ -1707,7 +1696,7 @@ dump_subcommand (const subcommand *sbc)
     }
   else if (sbc->type == SBC_CUSTOM)
     {
-      dump (1, "switch (%scustom_%s (p))",
+      dump (1, "switch (%scustom_%s (p, aux))",
            st_lower (prefix), st_lower (sbc->name));
       dump (0, "{");
       dump (1, "case 0:");
@@ -1736,7 +1725,8 @@ dump_parser (int persistent)
   indent = 0;
 
   dump (0, "static int");
-  dump (0, "parse_%s (struct cmd_%s *p)", make_identifier (cmdname),
+  dump (0, "parse_%s (struct cmd_%s *p, void *aux UNUSED)",
+        make_identifier (cmdname),
        make_identifier (cmdname));
   dump (1, "{");
 
@@ -1772,7 +1762,7 @@ dump_parser (int persistent)
     }
   else if (def && def->type == SBC_CUSTOM)
     {
-      dump (1, "switch (%scustom_%s (p))",
+      dump (1, "switch (%scustom_%s (p, aux))",
            st_lower (prefix), st_lower (def->name));
       dump (0, "{");
       dump (1, "case 0:");
@@ -1942,9 +1932,11 @@ dump_free (int persistent)
              dump (0, "free (p->s_%s);", st_lower (sbc->name));
              break;
            case SBC_DBL_LIST:
-             dump (0, "int i;");
-             dump (1, "for(i = 0; i < MAXLISTS ; ++i)");
-             dump (0, "subc_list_double_destroy(&p->dl_%s[i]);", st_lower (sbc->name));
+              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 (0, "}");
              outdent();
              break;
            default:
@@ -2041,6 +2033,7 @@ main (int argc, char *argv[])
          dump (0, "#include <libpspp/alloc.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>");