#include <time.h>
#include <errno.h>
#include <unistd.h>
+#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/str.h>
#include "exit.h"
char *program_name;
/* Have the input and output files been opened yet? */
-int is_open;
+bool is_open;
/* Input, output files. */
FILE *in, *out;
{
if (!is_open)
return;
- is_open = 0;
+ is_open = false;
fclose (in);
fclose (out);
if (remove (ofn) == -1)
/* Read one line from the input file into buf. Lines having special
formats are handled specially. */
-static int
+static bool
get_line (void)
{
ln++;
{
if (ferror (in))
fail ("%s: fgets: %s", ifn, strerror (errno));
- return 0;
+ return false;
}
cp = strchr (buf, '\n');
*cp = '\0';
cp = buf;
- return 1;
+ return true;
}
\f
/* Symbol table manager. */
}
/* Checks whether the current token is the identifier S; if so, skips
- the token and returns 1; otherwise, returns 0. */
-static int
+ the token and returns true; otherwise, returns false. */
+static bool
match_id (const char *s)
{
if (token == T_ID && !strcmp (tokstr, s))
{
lex_get ();
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/* Checks whether the current token is T. If so, skips the token and
- returns 1; otherwise, returns 0. */
-static int
+ returns true; otherwise, returns false. */
+static bool
match_token (int t)
{
if (token == t)
{
lex_get ();
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/* Force the current token to be T, and skip it. */
static void
parse_subcommand (subcommand *sbc)
{
- sbc->arity = ARITY_MANY;
-
if (match_token ('*'))
{
if (def)
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 ;
}
}
-/* Returns 1 if string T is a PSPP keyword, 0 otherwise. */
-static int
+/* Returns true if string T is a PSPP keyword, false otherwise. */
+static bool
is_keyword (const char *t)
{
static const char *kw[] =
for (cp = kw; *cp; cp++)
if (!strcmp (t, *cp))
- return 1;
- return 0;
+ return true;
+ return false;
}
/* Transforms a string NAME into a valid C identifier: makes
/* Write out prototypes for custom_*() functions as necessary. */
{
- int seen = 0;
+ bool seen = false;
subcommand *sbc;
for (sbc = subcommands; sbc; sbc = sbc->next)
{
if (!seen)
{
- seen = 1;
+ seen = true;
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));
}
/* 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));
break;
default:
- assert (0);
+ NOT_REACHED ();
}
}
}
dump (0, "int x;");
}
dump (1, "if (!lex_force_string ())");
- dump (0, "return 0;");
+ dump (0, "return false;");
outdent ();
if (sbc->restriction)
{
}
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:");
dump (0, "goto lossage;");
dump (-1, "default:");
indent ();
- dump (0, "assert (0);");
+ dump (0, "NOT_REACHED ();");
dump (-1, "}");
outdent ();
}
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, "{");
}
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:");
dump (0, "break;");
dump (-1, "default:");
indent ();
- dump (0, "assert (0);");
+ dump (0, "NOT_REACHED ();");
dump (-1, "}");
outdent ();
}
}
}
- dump (-1, "return 1;");
+ dump (-1, "return true;");
dump (0, nullstr);
dump (-1, "lossage:");
indent ();
dump (0, "free_%s (p);", make_identifier (cmdname));
- dump (0, "return 0;");
+ dump (0, "return false;");
dump (-1, "}");
dump (0, nullstr);
}
if (!out)
fail ("%s: open: %s.", ofn, strerror (errno));
- is_open = 1;
+ is_open = true;
buf = xmalloc (MAX_LINE_LEN);
tokstr = xmalloc (MAX_TOK_LEN);
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>");