Apply patch #5225, assertions.
[pspp-builds.git] / src / language / lexer / q2c.c
index ec369dbcb5b3b0d04bc40d428c1ddb6f2bbcf259..a6de4ac62bbf95bf00bf69bc8316216eda1aed5b 100644 (file)
 #include <time.h>
 #include <errno.h>
 #include <unistd.h>
+#include <libpspp/assertion.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"
 
      
 /* Max length of an input line. */
@@ -748,8 +740,6 @@ parse_specifiers (subcommand *sbc)
 static void
 parse_subcommand (subcommand *sbc)
 {
-  sbc->arity = ARITY_MANY;
-
   if (match_token ('*'))
     {
       if (def)
@@ -757,8 +747,9 @@ parse_subcommand (subcommand *sbc)
       def = sbc;
     }
 
+  sbc->arity = ARITY_ONCE_ONLY;
   if ( match_token('+'))
-    sbc->arity = ARITY_ONCE_ONLY ;
+    sbc->arity = ARITY_MANY;
   else if (match_token('^'))
     sbc->arity = ARITY_ONCE_EXACTLY ;
 
@@ -1186,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));
        }
@@ -1198,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));
@@ -1331,7 +1322,7 @@ dump_vars_init (int persistent)
                break;
 
              default:
-               assert (0);
+               NOT_REACHED ();
              }
          }
       }
@@ -1633,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)
@@ -1705,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:");
@@ -1719,7 +1710,7 @@ dump_subcommand (const subcommand *sbc)
       dump (0, "goto lossage;");
       dump (-1, "default:");
       indent ();
-      dump (0, "assert (0);");
+      dump (0, "NOT_REACHED ();");
       dump (-1, "}");
       outdent ();
     }
@@ -1734,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, "{");
 
@@ -1770,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:");
@@ -1784,7 +1776,7 @@ dump_parser (int persistent)
       dump (0, "break;");
       dump (-1, "default:");
       indent ();
-      dump (0, "assert (0);");
+      dump (0, "NOT_REACHED ();");
       dump (-1, "}");
       outdent ();
     }
@@ -1940,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:
@@ -2037,8 +2031,10 @@ main (int argc, char *argv[])
 
          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/str.h>");
           dump (0, "#include <language/lexer/subcommand-list.h>");