3 * Copyright © 2021 Nick Bowler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 #if STRTAB_MAX_OFFSET < UINT_LEAST8_MAX
32 #elif STRTAB_MAX_OFFSET < UINT_LEAST16_MAX
35 #error do not know what type to use
39 static const struct command *in_word_set();
55 simplify, cmd_simplify
64 static int run_cmd_help(void)
66 static const unsigned char offsets[] = CMD_SEQ;
69 printf("Commands:\n");
70 for (i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
71 const struct command *c = &wordlist[offsets[i]];
74 w = printf(" %s", stringpool+c->name);
75 if (w < 0 || w > 13) {
80 help_print_desc(NULL, gettext(strtab+c->cmd), 15, w);
86 int run_command(const char *line, int batch)
88 const char *cmd = line + strspn(line, " \t");
89 const char *arg = cmd + strcspn(cmd, " \t");
90 const struct command *c;
96 c = in_word_set(cmd, arg-cmd);
98 print_error(_("unknown command %.*s"), (int)(arg-cmd), cmd);
100 fprintf(stderr, "%s\n",
101 _("Try \"help\" for a list of possible commands."));
107 case cmd_help: return run_cmd_help();
108 case cmd_declare: case cmd_type: return run_command_declare(cmd);
109 case cmd_simplify: return run_command_simplify(arg);
110 case cmd_explain: return run_command_explain(arg);
111 case cmd_quit: return 1;