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/>.
29 #if STRTAB_MAX_OFFSET < UINT_LEAST8_MAX
31 #elif STRTAB_MAX_OFFSET < UINT_LEAST16_MAX
34 #error do not know what type to use
38 static const struct command *in_word_set();
54 simplify, cmd_simplify
63 static int run_cmd_help(void)
65 static const unsigned char offsets[] = CMD_SEQ;
68 printf("Commands:\n");
69 for (i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
70 const struct command *c = &wordlist[offsets[i]];
73 w = printf(" %s", stringpool+c->name);
74 if (w < 0 || w > 13) {
79 print_block(gettext(strtab+c->cmd), 15, w);
85 int run_command(const char *line, int interactive)
87 const char *cmd = line + strspn(line, " \t");
88 const char *arg = cmd + strcspn(cmd, " \t");
89 const struct command *c;
95 c = in_word_set(cmd, arg-cmd);
97 print_error(_("unknown command %.*s"), (int)(arg-cmd), cmd);
99 fprintf(stderr, "%s\n",
100 _("Try \"help\" for a list of possible commands."));
106 case cmd_help: return run_cmd_help();
107 case cmd_declare: case cmd_type: return run_command_declare(cmd);
108 case cmd_simplify: return run_command_simplify(arg);
109 case cmd_explain: return run_command_explain(arg);
110 case cmd_quit: return 1;