]> git.draconx.ca Git - cdecl99.git/blobdiff - src/execute.gperf
Port to use getline.h from dxcommon.
[cdecl99.git] / src / execute.gperf
index b1e7d5931ee2e4746c3c04bf80050cb1ab6583c6..51443ba0b31b46f10be9a395b75f7d2585821f8f 100644 (file)
@@ -1,6 +1,6 @@
 %{
 /*
- * Copyright © 2021 Nick Bowler
+ * Copyright © 2021, 2023-2024 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <config.h>
 #include <stdio.h>
 #include <string.h>
-#include <stdint.h>
+#include <inttypes.h>
 #include <assert.h>
 
 #include "cdecl99.h"
 #include "commands.h"
+#include "help.h"
 
 typedef
 #if STRTAB_MAX_OFFSET < UINT_LEAST8_MAX
@@ -71,18 +72,18 @@ static int run_cmd_help(void)
                int w;
 
                w = printf("  %s", stringpool+c->name);
-               if (w < 0 || w > 13) {
+               if (w <= 0 || w > 13) {
                        putchar('\n');
                        w = 0;
                }
 
-               print_block(gettext(strtab+c->cmd), 15, w);
+               help_print_desc(NULL, gettext(strtab+c->cmd), 15, w);
        }
 
        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");
@@ -95,7 +96,7 @@ int run_command(const char *line, int interactive)
        c = in_word_set(cmd, arg-cmd);
        if (!c) {
                print_error(_("unknown command %.*s"), (int)(arg-cmd), cmd);
-               if (interactive) {
+               if (!batch) {
                        fprintf(stderr, "%s\n",
                                _("Try \"help\" for a list of possible commands."));
                }
@@ -103,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);