#include <language/lexer/lexer.h>
#include <language/line-buffer.h>
#include <libpspp/alloc.h>
+#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/message.h>
#include <libpspp/message.h>
enum states states; /* States in which command is allowed. */
enum flags flags; /* Other command requirements. */
const char *name; /* Command name. */
- int (*function) (void); /* Function to call. */
+ int (*function) (struct dataset *); /* Function to call. */
};
/* Define the command array. */
/* Command parser. */
static const struct command *parse_command_name (void);
-static enum cmd_result do_parse_command (enum cmd_state);
+static enum cmd_result do_parse_command (struct dataset *ds, enum cmd_state);
/* Parses an entire command, from command name to terminating
dot. On failure, skips to the terminating dot.
Returns the command's success or failure result. */
enum cmd_result
-cmd_parse (enum cmd_state state)
+cmd_parse (struct dataset *ds, enum cmd_state state)
{
int result;
som_new_series ();
- result = do_parse_command (state);
+ result = do_parse_command (ds, state);
if (cmd_result_is_failure (result))
lex_discard_rest_of_command ();
unset_cmd_algorithm ();
- dict_clear_aux (default_dict);
+ dict_clear_aux (dataset_dict (ds));
return result;
}
/* Parses an entire command, from command name to terminating
dot. */
static enum cmd_result
-do_parse_command (enum cmd_state state)
+do_parse_command (struct dataset *ds, enum cmd_state state)
{
const struct command *command;
enum cmd_result result;
command = parse_command_name ();
if (command == NULL)
return CMD_FAILURE;
- else if (command->function == NULL)
- return CMD_NOT_IMPLEMENTED;
+ else if (command->function == NULL)
+ {
+ msg (SE, _("%s is unimplemented."), command->name);
+ return CMD_NOT_IMPLEMENTED;
+ }
else if ((command->flags & F_TESTING) && !get_testing_mode ())
{
msg (SE, _("%s may be used only in testing mode."), command->name);
/* Execute command. */
msg_set_command_name (command->name);
tab_set_command_name (command->name);
- result = command->function ();
+ result = command->function (ds);
tab_set_command_name (NULL);
msg_set_command_name (NULL);
return string;
}
-/* Returns nonzero if strings A and B can be confused based on
+/* Returns true if strings A and B can be confused based on
their first three letters. */
-static int
+static bool
conflicting_3char_prefixes (const char *a, const char *b)
{
size_t aw_len, bw_len;
/* Words that are the same don't conflict. */
if (aw_len == bw_len && !buf_compare_case (aw, bw, aw_len))
- return 0;
+ return false;
/* Words that are otherwise the same in the first three letters
do conflict. */
|| (bw_len == 3 && aw_len > 3)) && !buf_compare_case (aw, bw, 3);
}
-/* Returns nonzero if CMD can be confused with another command
+/* Returns true if CMD can be confused with another command
based on the first three letters of its first word. */
-static int
+static bool
conflicting_3char_prefix_command (const struct command *cmd)
{
assert (cmd >= commands && cmd < commands + command_cnt);
for (cmd = commands; cmd < commands + command_cnt; cmd++)
if (!strcmp (cmd->name, name))
return cmd;
- abort ();
+ NOT_REACHED ();
}
/* Frees the WORD_CNT words in WORDS. */
else if (allowed_cnt == 3)
s = xasprintf (_("%s, %s, or %s"), allowed[0], allowed[1], allowed[2]);
else
- abort ();
+ NOT_REACHED ();
msg (SE, _("%s is allowed only %s."), command->name, s);
/* Parse and execute FINISH command. */
int
-cmd_finish (void)
+cmd_finish (struct dataset *ds UNUSED)
{
return CMD_FINISH;
}
/* Parses the N command. */
int
-cmd_n_of_cases (void)
+cmd_n_of_cases (struct dataset *ds)
{
/* Value for N. */
int x;
x = lex_integer ();
lex_get ();
if (!lex_match_id ("ESTIMATED"))
- dict_set_case_limit (default_dict, x);
+ dict_set_case_limit (dataset_dict (ds), x);
return lex_end_of_command ();
}
/* Parses, performs the EXECUTE procedure. */
int
-cmd_execute (void)
+cmd_execute (struct dataset *ds)
{
- if (!procedure (NULL, NULL))
+ if (!procedure (ds, NULL, NULL))
return CMD_CASCADING_FAILURE;
return lex_end_of_command ();
}
/* Parses, performs the ERASE command. */
int
-cmd_erase (void)
+cmd_erase (struct dataset *ds UNUSED)
{
if (get_safer_mode ())
{
/* Parses, performs the HOST command. */
int
-cmd_host (void)
+cmd_host (struct dataset *ds UNUSED)
{
int code;
/* Parses, performs the NEW FILE command. */
int
-cmd_new_file (void)
+cmd_new_file (struct dataset *ds)
{
- discard_variables ();
+ discard_variables (ds);
return lex_end_of_command ();
}
/* Parses a comment. */
int
-cmd_comment (void)
+cmd_comment (struct dataset *ds UNUSED)
{
lex_skip_comment ();
return CMD_SUCCESS;