#include <unistd.h>
#include <data/dictionary.h>
+#include <data/procedure.h>
#include <data/settings.h>
#include <data/variable.h>
#include <language/lexer/lexer.h>
#include <libpspp/str.h>
#include <output/manager.h>
#include <output/table.h>
-#include <procedure.h>
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
\f
+/* Returns true if RESULT is a valid "enum cmd_result",
+ false otherwise. */
+static inline bool
+cmd_result_is_valid (enum cmd_result result)
+{
+ return (result == CMD_SUCCESS || result == CMD_EOF || result == CMD_FINISH
+ || (result >= CMD_PRIVATE_FIRST && result <= CMD_PRIVATE_LAST)
+ || result == CMD_FAILURE || result == CMD_NOT_IMPLEMENTED
+ || result == CMD_CASCADING_FAILURE);
+}
+
/* Returns true if RESULT indicates success,
false otherwise. */
bool
cmd_result_is_success (enum cmd_result result)
{
- return (result == CMD_SUCCESS || result == CMD_EOF
- || result == CMD_QUIT || result == CMD_END_SUBLOOP);
+ assert (cmd_result_is_valid (result));
+ return result > 0;
}
/* Returns true if RESULT indicates failure,
bool
cmd_result_is_failure (enum cmd_result result)
{
- return !cmd_result_is_success (result);
+ assert (cmd_result_is_valid (result));
+ return result < 0;
}
\f
/* Command processing states. */
tab_set_command_name (NULL);
msg_set_command_name (NULL);
+ assert (cmd_result_is_valid (result));
return result;
}
struct string s;
size_t i;
- ds_init (&s, 0);
+ ds_init_empty (&s);
for (i = 0; i < word_cnt; i++)
{
if (i != 0)
- ds_putc (&s, ' ');
- ds_puts (&s, words[i]);
+ ds_put_char (&s, ' ');
+ ds_put_cstr (&s, words[i]);
}
- msg (SE, _("Unknown command %s."), ds_c_str (&s));
+ msg (SE, _("Unknown command %s."), ds_cstr (&s));
ds_destroy (&s);
}
assert (word_cnt < sizeof words / sizeof *words);
if (token == T_ID)
{
- words[word_cnt] = xstrdup (ds_c_str (&tokstr));
+ words[word_cnt] = ds_xstrdup (&tokstr);
str_uppercase (words[word_cnt]);
}
else if (token == '-')
int
cmd_finish (void)
{
- return CMD_QUIT;
+ return CMD_FINISH;
}
/* Parses the N command. */
if (!lex_force_string ())
return CMD_FAILURE;
- if (remove (ds_c_str (&tokstr)) == -1)
+ if (remove (ds_cstr (&tokstr)) == -1)
{
msg (SW, _("Error removing `%s': %s."),
- ds_c_str (&tokstr), strerror (errno));
+ ds_cstr (&tokstr), strerror (errno));
return CMD_FAILURE;
}
lex_get ();
if (!lex_force_string ())
return CMD_FAILURE;
- cmd = ds_c_str (&tokstr);
+ cmd = ds_cstr (&tokstr);
string = 1;
}
else