Separate settings and the SET command, for modularity.
[pspp-builds.git] / src / q2c.c
index 20b245986b127b3bc8ddd703048d11def95f7682..f771d466ecc505a30b94fe2c0b2e01cf09f22dba 100644 (file)
--- a/src/q2c.c
+++ b/src/q2c.c
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include <assert.h>
@@ -30,6 +30,7 @@
 #endif
 #include "str.h"
 
+
 /* Brokenness. */
 #ifndef EXIT_SUCCESS
 #define EXIT_SUCCESS 0
@@ -283,7 +284,7 @@ add_symbol (const char *name, int unique, int value)
   symbol *iter, *sym;
   int x;
 
-  sym = xmalloc (sizeof (symbol));
+  sym = xmalloc (sizeof *sym);
   sym->name = xstrdup (name);
   sym->unique = unique;
   sym->value = value;
@@ -338,10 +339,10 @@ find_symbol (int x)
   return iter;
 }
 
-#if DEBUGGING
+#if DEBUGGING 
 /* Writes a printable representation of the current token to
    stdout. */
-void
+static void
 dump_token (void)
 {
   switch (token)
@@ -373,15 +374,7 @@ lex_get (void)
        fail ("%s: Unexpected end of file.", ifn);
     }
   
-  if (*cp == '_' || isalnum ((unsigned char) *cp))
-    {
-      char *dest = tokstr;
-      token = T_ID;
-      while (*cp == '_' || isalnum ((unsigned char) *cp))
-       *dest++ = toupper ((unsigned char) (*cp++));
-      *dest++ = '\0';
-    }
-  else if (*cp == '"')
+  if (*cp == '"')
     {
       char *dest = tokstr;
       token = T_STRING;
@@ -403,6 +396,14 @@ lex_get (void)
        error ("Unterminated string literal.");
       cp++;
     }
+  else if (*cp == '_' || isalnum ((unsigned char) *cp))
+    {
+      char *dest = tokstr;
+      token = T_ID;
+      while (*cp == '_' || isalnum ((unsigned char) *cp))
+       *dest++ = toupper ((unsigned char) (*cp++));
+      *dest++ = '\0';
+    }
   else
     token = *cp++;
   
@@ -531,6 +532,13 @@ typedef enum
   }
 subcommand_type;
 
+typedef enum
+  {
+    ARITY_ONCE_EXACTLY,  /* must occur exactly once */
+    ARITY_ONCE_ONLY,     /* zero or once */
+    ARITY_MANY           /* 0, 1, ... , inf */
+  }subcommand_arity;
+
 /* A single subcommand. */
 typedef struct subcommand subcommand;
 struct subcommand
@@ -538,14 +546,15 @@ struct subcommand
     subcommand *next;          /* Next in the chain. */
     char *name;                        /* Subcommand name. */
     subcommand_type type;      /* One of SBC_*. */
-    int once;                  /* 1=Subcommand may appear only once. */
+    subcommand_arity arity;    /* How many times should the subcommand occur*/
     int narray;                        /* Index of next array element. */
     const char *prefix;                /* Prefix for variable and constant names. */
     specifier *spec;           /* Array of specifiers. */
     
-    /* SBC_STRING only. */
+    /* SBC_STRING and SBC_INT only. */
     char *restriction;         /* Expression restricting string length. */
     char *message;             /* Error message. */
+    int translatable;           /* Error message is translatable */
   };
 
 /* Name of the command; i.e., DESCRIPTIVES. */
@@ -690,13 +699,22 @@ parse_specifier (specifier *spec, subcommand *sbc)
     }
   skip_token (':');
   
+  if ( sbc->type == SBC_ARRAY && token == T_ID ) 
+    {
+       spec->varname = xstrdup (st_lower (tokstr));
+       spec->index = sbc->narray;
+       sbc->narray++;
+    }
+    
+  
+  
   /* Parse all the settings. */
   {
     setting **s = &spec->s;
     
     for (;;)
       {
-       *s = xmalloc (sizeof (setting));
+       *s = xmalloc (sizeof **s);
        parse_setting (*s, spec);
        if (token == ',' || token == ';' || token == '.')
          break;
@@ -721,7 +739,7 @@ parse_specifiers (subcommand *sbc)
   
   for (;;)
     {
-      *spec = xmalloc (sizeof (specifier));
+      *spec = xmalloc (sizeof **spec);
       parse_specifier (*spec, sbc);
       if (token == ';' || token == '.')
        break;
@@ -735,6 +753,8 @@ parse_specifiers (subcommand *sbc)
 static void
 parse_subcommand (subcommand *sbc)
 {
+  sbc->arity = ARITY_MANY;
+
   if (match_token ('*'))
     {
       if (def)
@@ -742,7 +762,11 @@ parse_subcommand (subcommand *sbc)
       def = sbc;
     }
 
-  sbc->once = match_token ('+');
+  if ( match_token('+'))
+    sbc->arity = ARITY_ONCE_ONLY ;
+  else if (match_token('^'))
+    sbc->arity = ARITY_ONCE_EXACTLY ;
+
 
   force_id ();
   sbc->name = xstrdup (tokstr);
@@ -751,6 +775,7 @@ parse_subcommand (subcommand *sbc)
   sbc->narray = 0;
   sbc->type = SBC_PLAIN;
   sbc->spec = NULL;
+  sbc->translatable = 0;
 
   if (match_token ('['))
     {
@@ -763,6 +788,7 @@ parse_subcommand (subcommand *sbc)
       
       sbc->type = SBC_ARRAY;
       parse_specifiers (sbc);
+
     }
   else
     {
@@ -796,11 +822,38 @@ parse_subcommand (subcommand *sbc)
          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"))
-       sbc->type = match_id ("LIST") ? SBC_DBL_LIST : SBC_DBL;
+       {
+         if ( match_id ("LIST") )
+           sbc->type = SBC_DBL_LIST;
+         else
+           sbc->type = SBC_DBL;
+       }
       else if (match_id ("STRING"))
        {
          sbc->type = SBC_STRING;
@@ -830,7 +883,7 @@ parse_subcommands (void)
   
   for (;;)
     {
-      *sbc = xmalloc (sizeof (subcommand));
+      *sbc = xmalloc (sizeof **sbc);
       (*sbc)->next = NULL;
 
       parse_subcommand (*sbc);
@@ -996,6 +1049,12 @@ dump_declarations (void)
       }
   }
 
+  /* Write out some type definitions */
+  {
+    dump (0, "#define MAXLISTS 10");
+  }
+
+
   /* For every array subcommand, write out the associated enumerated
      values. */
   {
@@ -1013,7 +1072,6 @@ dump_declarations (void)
            specifier *spec;
 
            for (spec = sbc->spec; spec; spec = spec->next)
-             if (!spec->s)
                dump (0, "%s%s%s = %d,",
                      st_upper (prefix), st_upper (sbc->prefix),
                      st_upper (spec->varname), spec->index);
@@ -1059,8 +1117,12 @@ dump_declarations (void)
                              spec->varname);
                      else if (f == 0)
                        {
-                         dump (0, "int a_%s[%d];", 
-                               st_lower (sbc->name), sbc->narray);
+                         dump (0, "int a_%s[%s%scount];", 
+                               st_lower (sbc->name), 
+                               st_upper (prefix),
+                               st_upper (sbc->prefix)
+                               );
+
                          f = 1;
                        }
                    }
@@ -1071,7 +1133,7 @@ dump_declarations (void)
            break;
 
          case SBC_VARLIST:
-           dump (0, "int %sn_%s;", st_lower (sbc->prefix),
+           dump (0, "size_t %sn_%s;", st_lower (sbc->prefix),
                  st_lower (sbc->name));
            dump (0, "struct variable **%sv_%s;", st_lower (sbc->prefix),
                  st_lower (sbc->name));
@@ -1088,13 +1150,24 @@ dump_declarations (void)
 
          case SBC_INT:
          case SBC_PINT:
-           dump (0, "long n_%s;", st_lower (sbc->name));
+           dump (0, "long n_%s[MAXLISTS];", st_lower (sbc->name));
            break;
 
          case SBC_DBL:
-           dump (0, "double n_%s;", st_lower (sbc->name));
+           dump (0, "double n_%s[MAXLISTS];", st_lower (sbc->name));
            break;
 
+         case SBC_DBL_LIST:
+           dump (0, "subc_list_double dl_%s[MAXLISTS];",
+                 st_lower(sbc->name));
+           break;
+
+         case SBC_INT_LIST:
+           dump (0, "subc_list_int il_%s[MAXLISTS];",
+                 st_lower(sbc->name));
+           break;
+
+
          default:;
            /* nothing */
          }
@@ -1175,71 +1248,96 @@ dump_specifier_init (const specifier *spec, const subcommand *sbc)
 
 /* Write code to initialize all variables. */
 static void
-dump_vars_init (void)
+dump_vars_init (int persistent)
 {
   /* Loop through all the subcommands. */
   {
     subcommand *sbc;
-
+    
     for (sbc = subcommands; sbc; sbc = sbc->next)
       {
        int f = 0;
        
        dump (0, "p->sbc_%s = 0;", st_lower (sbc->name));
-       switch (sbc->type)
+       if ( ! persistent ) 
          {
-         case SBC_DBL:
-         case SBC_INT_LIST:
-         case SBC_DBL_LIST:
-         case SBC_CUSTOM:
-           /* nothing */
-           break;
+           switch (sbc->type)
+             {
+             case SBC_INT_LIST:
+               break;
+
+             case SBC_DBL_LIST:
+               dump (1, "{");
+               dump (0, "int i;");
+               dump (1, "for (i = 0; i < MAXLISTS; ++i)");
+               dump (0, "subc_list_double_create(&p->dl_%s[i]) ;",
+                     st_lower (sbc->name)
+                     );
+               dump (-2, "}");
+               break;
+
+             case SBC_DBL:
+               dump (1, "{");
+               dump (0, "int i;");
+               dump (1, "for (i = 0; i < MAXLISTS; ++i)");
+               dump (0, "p->n_%s[i] = SYSMIS;", st_lower (sbc->name));
+               dump (-2, "}");
+               break;
+
+             case SBC_CUSTOM:
+               /* nothing */
+               break;
            
-         case SBC_PLAIN:
-         case SBC_ARRAY:
-           {
-             specifier *spec;
+             case SBC_PLAIN:
+             case SBC_ARRAY:
+               {
+                 specifier *spec;
            
-             for (spec = sbc->spec; spec; spec = spec->next)
-               if (spec->s == NULL)
-                 {
-                   if (sbc->type == SBC_PLAIN)
-                     dump (0, "p->%s%s = 0;", sbc->prefix, spec->varname);
-                   else if (f == 0)
+                 for (spec = sbc->spec; spec; spec = spec->next)
+                   if (spec->s == NULL)
                      {
-                       dump (0, "memset (p->a_%s, 0, sizeof p->a_%s);",
-                             st_lower (sbc->name), st_lower (sbc->name));
-                       f = 1;
+                       if (sbc->type == SBC_PLAIN)
+                         dump (0, "p->%s%s = 0;", sbc->prefix, spec->varname);
+                       else if (f == 0)
+                         {
+                           dump (0, "memset (p->a_%s, 0, sizeof p->a_%s);",
+                                 st_lower (sbc->name), st_lower (sbc->name));
+                           f = 1;
+                         }
                      }
-                 }
-               else
-                 dump_specifier_init (spec, sbc);
-           }
-           break;
-
-         case SBC_VARLIST:
-           dump (0, "p->%sn_%s = 0;",
-                 st_lower (sbc->prefix), st_lower (sbc->name));
-           dump (0, "p->%sv_%s = NULL;",
-                 st_lower (sbc->prefix), st_lower (sbc->name));
-           break;
+                   else
+                     dump_specifier_init (spec, sbc);
+               }
+               break;
+
+             case SBC_VARLIST:
+               dump (0, "p->%sn_%s = 0;",
+                     st_lower (sbc->prefix), st_lower (sbc->name));
+               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));
-           break;
-
-         case SBC_STRING:
-           dump (0, "p->s_%s = NULL;", st_lower (sbc->name));
-           break;
-
-         case SBC_INT:
-         case SBC_PINT:
-           dump (0, "p->n_%s = NOT_LONG;", st_lower (sbc->name));
-           break;
-
-         default:
-           assert (0);
+             case SBC_VAR:
+               dump (0, "p->%sv_%s = NULL;",
+                     st_lower (sbc->prefix), st_lower (sbc->name));
+               break;
+
+             case SBC_STRING:
+               dump (0, "p->s_%s = NULL;", st_lower (sbc->name));
+               break;
+
+             case SBC_INT:
+             case SBC_PINT:
+               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 (-2, "}");
+               break;
+
+             default:
+               assert (0);
+             }
          }
       }
   }
@@ -1305,6 +1403,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc)
        dump (1, "%sif (%s)", first ? "" : "else ",
              make_match (s->specname));
 
+
       /* Handle values. */
       if (s->value == VAL_NONE)
        dump (0, "p->%s%s = %s%s;", sbc->prefix, spec->varname,
@@ -1315,9 +1414,18 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc)
            dump (1, "{");
          
          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->%s%s = %s%s;", sbc->prefix, spec->varname,
+                   st_upper (prefix), find_symbol (s->con)->name);
+
+             if ( sbc->type == SBC_ARRAY ) 
+               dump (0, "p->a_%s[%s%s%s] = 1;",
+                     st_lower (sbc->name),
+                     st_upper (prefix), st_upper (sbc->prefix),
+                     st_upper (spec->varname));
+           }
+
+
          if (s->valtype == VT_PAREN)
            {
              if (s->optvalue)
@@ -1340,7 +1448,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc)
 
          if (s->value == VAL_INT)
            {
-             dump (1, "if (!lex_integer_p ())");
+             dump (1, "if (!lex_is_integer ())");
              dump (1, "{");
              dump (0, "msg (SE, _(\"%s specifier of %s subcommand "
                    "requires an integer argument.\"));",
@@ -1352,7 +1460,7 @@ dump_specifier_parse (const specifier *spec, const subcommand *sbc)
            }
          else
            {
-             dump (1, "if (token != T_NUM)");
+             dump (1, "if (!lex_is_number ())");
              dump (1, "{");
              dump (0, "msg (SE, _(\"Number expected after %s "
                    "specifier of %s subcommand.\"));",
@@ -1503,7 +1611,7 @@ dump_subcommand (const subcommand *sbc)
     {
       dump (0, "p->%sv_%s = parse_variable ();",
            st_lower (sbc->prefix), st_lower (sbc->name));
-      dump (1, "if (p->%sv_%s)",
+      dump (1, "if (!p->%sv_%s)",
            st_lower (sbc->prefix), st_lower (sbc->name));
       dump (0, "goto lossage;");
       outdent ();
@@ -1529,7 +1637,8 @@ dump_subcommand (const subcommand *sbc)
          dump (-1, "}");
          outdent ();
        }
-      dump (0, "p->s_%s = xstrdup (ds_value (&tokstr));",
+      dump (0, "free(p->s_%s);", st_lower(sbc->name) );
+      dump (0, "p->s_%s = xstrdup (ds_c_str (&tokstr));",
            st_lower (sbc->name));
       dump (0, "lex_get ();");
       if (sbc->restriction)
@@ -1539,15 +1648,33 @@ dump_subcommand (const subcommand *sbc)
     {
       dump (1, "if (!lex_force_num ())");
       dump (0, "goto lossage;");
-      dump (-1, "p->n_%s = lex_double ();", st_lower (sbc->name));
+      dump (-1, "p->n_%s[p->sbc_%s - 1] = lex_number ();", 
+           st_lower (sbc->name), st_lower (sbc->name) );
       dump (0, "lex_get();");
     }
   else if (sbc->type == SBC_INT)
     {
+      dump(1, "{");
+      dump(0, "int x;");
       dump (1, "if (!lex_force_int ())");
       dump (0, "goto lossage;");
-      dump (-1, "p->n_%s = lex_integer ();", st_lower (sbc->name));
+      dump (-1, "x = lex_integer ();");
       dump (0, "lex_get();");
+      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,"}");
     }
   else if (sbc->type == SBC_PINT)
     {
@@ -1557,6 +1684,30 @@ dump_subcommand (const subcommand *sbc)
       dump (-1, "p->n_%s = lex_integer ();", st_lower (sbc->name));
       dump (0, "lex_match (')');");
     }
+  else if (sbc->type == SBC_DBL_LIST)
+    {
+      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, "goto lossage;");
+      dump (-1,"}");
+
+      dump (1, "while (token != '/' && token != '.')");
+      dump (1, "{");
+      dump (0, "lex_match(',');");
+      dump (0, "if (!lex_force_num ())");
+      dump (1, "{");
+      dump (0, "goto lossage;");
+      dump (-1,"}");
+
+      dump (0, "subc_list_double_push(&p->dl_%s[p->sbc_%s-1],lex_number ());", 
+           st_lower (sbc->name),st_lower (sbc->name)
+           );
+
+      dump (0, "lex_get();");
+      dump (-1,"}");
+
+    }
   else if (sbc->type == SBC_CUSTOM)
     {
       dump (1, "switch (%scustom_%s (p))",
@@ -1581,7 +1732,7 @@ dump_subcommand (const subcommand *sbc)
 
 /* Write out entire parser. */
 static void
-dump_parser (void)
+dump_parser (int persistent)
 {
   int f;
 
@@ -1592,7 +1743,7 @@ dump_parser (void)
        make_identifier (cmdname));
   dump (1, "{");
 
-  dump_vars_init ();
+  dump_vars_init (persistent);
 
   dump (1, "for (;;)");
   dump (1, "{");
@@ -1654,7 +1805,7 @@ dump_parser (void)
 
        dump (0, "lex_match ('=');");
        dump (0, "p->sbc_%s++;", st_lower (sbc->name));
-       if (sbc->once)
+       if (sbc->arity != ARITY_MANY)
          {
            dump (1, "if (p->sbc_%s > 1)", st_lower (sbc->name));
            dump (1, "{");
@@ -1669,6 +1820,24 @@ dump_parser (void)
        outdent ();
       }
   }
+
+
+  /* Now deal with the /ALGORITHM subcommand implicit to all commands */
+  dump(1,"else if ( get_syntax() != COMPATIBLE && lex_match_id(\"ALGORITHM\"))");
+  dump(1,"{");
+
+  dump (0, "lex_match ('=');");
+
+  dump(1,"if (lex_match_id(\"COMPATIBLE\"))");
+  dump(0,"set_cmd_algorithm(COMPATIBLE);");
+  outdent();
+  dump(1,"else if (lex_match_id(\"ENHANCED\"))");
+  dump(0,"set_cmd_algorithm(ENHANCED);");
+
+  dump (-1, "}");
+  outdent ();
+
+
   
   dump (1, "if (!lex_match ('/'))");
   dump (0, "break;");
@@ -1681,6 +1850,29 @@ dump_parser (void)
   dump (0, "goto lossage;");
   dump (-1, "}");
   dump (0, nullstr);
+
+  outdent ();
+
+  {
+    /*  Check that mandatory subcommands have been specified  */
+    subcommand *sbc;
+
+    for (sbc = subcommands; sbc; sbc = sbc->next)
+      {
+
+       if ( sbc->arity == ARITY_ONCE_EXACTLY ) 
+         {
+           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, "goto lossage;");
+           dump (-1, "}");
+           dump (0, nullstr);
+         }
+      }
+  }
+
   dump (-1, "return 1;");
   dump (0, nullstr);
   dump (-1, "lossage:");
@@ -1691,6 +1883,7 @@ dump_parser (void)
   dump (0, nullstr);
 }
 
+
 /* Write the output file header. */
 static void
 dump_header (void)
@@ -1709,12 +1902,11 @@ dump_header (void)
   dump (0, "   Generated by q2c from %s on %s.", ifn, timep);
   dump (0, "   Do not modify!");
   dump (0, " */");
-  dump (0, nullstr);
 }
 
 /* Write out commands to free variable state. */
 static void
-dump_free (void)
+dump_free (int persistent)
 {
   subcommand *sbc;
   int used;
@@ -1722,22 +1914,54 @@ dump_free (void)
   indent = 0;
 
   used = 0;
-  for (sbc = subcommands; sbc; sbc = sbc->next)
-    if (sbc->type == SBC_STRING)
-      used = 1;
+  if ( ! persistent ) 
+    {
+      for (sbc = subcommands; sbc; sbc = sbc->next)
+       {
+       if (sbc->type == SBC_STRING)
+         used = 1;
+       if (sbc->type == SBC_DBL_LIST)
+         used = 1;
+       }
+
+    }
 
   dump (0, "static void");
   dump (0, "free_%s (struct cmd_%s *p%s)", make_identifier (cmdname),
        make_identifier (cmdname), used ? "" : " UNUSED");
   dump (1, "{");
 
-  for (sbc = subcommands; sbc; sbc = sbc->next)
-    if (sbc->type == SBC_STRING)
-      dump (0, "free (p->s_%s);", st_lower (sbc->name));
+  if ( ! persistent ) 
+    {
+
+      for (sbc = subcommands; sbc; sbc = sbc->next)
+       {
+         switch (sbc->type) 
+           {
+            case SBC_VARLIST:
+             dump (0, "free (p->v_variables);");
+              break;
+           case SBC_STRING:
+             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));
+             outdent();
+             break;
+           default:
+             break;
+           }
+       }
+    }
 
   dump (-1, "}");
+
 }
 
+
+
 /* Returns the name of a directive found on the current input line, if
    any, or a null pointer if none found. */
 static const char *
@@ -1788,6 +2012,7 @@ main (int argc, char *argv[])
 
   dump_header ();
 
+
   indent = 0;
   dump (0, "#line %d \"%s\"", ln + 1, ifn);
   while (get_line ())
@@ -1799,7 +2024,7 @@ main (int argc, char *argv[])
          continue;
        }
       
-      dump (0, "#line %d \"%s\"", oln - 1, ofn);
+      dump (0, "#line %d \"%s\"", oln + 1, ofn);
       if (!strcmp (directive, "specification"))
        {
          /* Skip leading slash-star line. */
@@ -1815,21 +2040,31 @@ main (int argc, char *argv[])
        {
          indent = 0;
 
-         dump (0, "#include <assert.h>");
          dump (0, "#include <stdlib.h>");
          dump (0, "#include \"alloc.h\"");
          dump (0, "#include \"error.h\"");
          dump (0, "#include \"lexer.h\"");
+          dump (0, "#include \"settings.h\"");
          dump (0, "#include \"str.h\"");
+          dump (0, "#include \"subclist.h\"");
          dump (0, "#include \"var.h\"");
          dump (0, nullstr);
+
+          dump (0, "#include \"gettext.h\"");
+          dump (0, "#define _(msgid) gettext (msgid)");
+         dump (0, nullstr);
        }
       else if (!strcmp (directive, "declarations"))
        dump_declarations ();
       else if (!strcmp (directive, "functions"))
        {
-         dump_parser ();
-         dump_free ();
+         dump_parser (0);
+         dump_free (0); 
+       }
+      else if (!strcmp (directive, "_functions"))
+       {
+         dump_parser (1);
+         dump_free (1); 
        }
       else
        error ("unknown directive `%s'", directive);
@@ -1837,6 +2072,7 @@ main (int argc, char *argv[])
       dump (0, "#line %d \"%s\"", ln + 1, ifn);
     }
 
+
+
   return EXIT_SUCCESS;
 }
-