]> git.draconx.ca Git - cdecl99.git/blobdiff - src/execute.gperf
libcdecl: reduce snprintf reliance for error reporting.
[cdecl99.git] / src / execute.gperf
index e8a066547b73ff7e3cd85927ffeb04f50d8c7ae1..bf9a080748764b886117152b01fbaa9cb36c1c8d 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "cdecl99.h"
 #include "commands.h"
+#include "help.h"
 
 typedef
 #if STRTAB_MAX_OFFSET < UINT_LEAST8_MAX
@@ -73,16 +74,16 @@ static int run_cmd_help(void)
                w = printf("  %s", stringpool+c->name);
                if (w < 0 || w > 13) {
                        putchar('\n');
-                        0;
+                       w = 0;
                }
 
-               print_block(gettext(strtab+c->cmd), 15, w);
+               help_print_desc(NULL, gettext(strtab+c->cmd), 15, w);
        }
 
-       return 1;
+       return 0;
 }
 
-int run_command(const char *line, int interactive)
+int run_command(const char *line, int batch)
 {
        const char *cmd = line + strspn(line, " \t");
        const char *arg = cmd + strcspn(cmd, " \t");
@@ -90,13 +91,12 @@ int run_command(const char *line, int interactive)
 
        /* empty command */
        if (cmd[0] == '\0')
-               return 1;
+               return 0;
 
        c = in_word_set(cmd, arg-cmd);
        if (!c) {
-               fprintf(stderr, _("unknown command %.*s\n"),
-                               (int)(arg-cmd), cmd);
-               if (interactive) {
+               print_error(_("unknown command %.*s"), (int)(arg-cmd), cmd);
+               if (!batch) {
                        fprintf(stderr, "%s\n",
                                _("Try \"help\" for a list of possible commands."));
                }
@@ -104,11 +104,16 @@ int run_command(const char *line, int interactive)
        }
 
        switch (c->cmd) {
-       case cmd_help: return run_cmd_help();
-       case cmd_declare: case cmd_type: return run_command_declare(cmd);
-       case cmd_simplify: return run_command_simplify(arg);
-       case cmd_explain: return run_command_explain(arg);
-       case cmd_quit: return 1;
+       case cmd_help:
+               return run_cmd_help();
+       case cmd_declare: case cmd_type:
+               return run_command_cdecl(cmd, INPUT_ENGLISH, OUTPUT_C);
+       case cmd_simplify:
+               return run_command_cdecl(arg, INPUT_C, OUTPUT_C);
+       case cmd_explain:
+               return run_command_cdecl(arg, INPUT_C, OUTPUT_ENGLISH);
+       case cmd_quit:
+               return 1;
        }
 
        assert(0);