]> git.tue.mpg.de Git - paraslash.git/commitdiff
play: Remove support for non-lopsub commands.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 7 Sep 2015 21:40:58 +0000 (23:40 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2017 09:02:28 +0000 (11:02 +0200)
This cleans up play.c to get rid of struct pp_command, the array of
command handlers and the compatibility code for non-lopsub commands
in run_command() and com_help().

Also the FOR_EACH_COMMAND() macro to iterate over all non-lopsub
commands can go away and we no longer need to include the
play.command_list.h header generated by command_util.bash.

play.c

diff --git a/play.c b/play.c
index c6a785980e93be6cd9fa558ee70dc0b5dfb4e65f..1ab4010160cac7e22988111d361de5e745dcd75c 100644 (file)
--- a/play.c
+++ b/play.c
@@ -665,22 +665,6 @@ static char **get_mapped_keyseqs(void)
        return result;
 }
 
-#include "play.command_list.h"
-
-typedef int play_command_handler_t(struct play_task *, int, char**);
-
-/* defines one command of para_play */
-struct pp_command {
-       const char *name;
-       play_command_handler_t *handler;
-       const char *description;
-       const char *usage;
-       const char *help;
-};
-
-static struct pp_command pp_cmds[] = {DEFINE_PLAY_CMD_ARRAY};
-#define FOR_EACH_COMMAND(c) for (c = 0; pp_cmds[c].name; c++)
-
 static struct i9e_completer pp_completers[];
 
 I9E_DUMMY_COMPLETER(jmp);
@@ -755,11 +739,6 @@ static int com_help(struct play_task *pt, struct lls_parse_result *lpr)
                                        lls_command_name(cmd), lls_purpose(cmd));
                                btr_add_output(buf, sz, pt->btrn);
                        }
-                       FOR_EACH_COMMAND(i) {
-                               sz = xasprintf(&buf, "%s\t%s\n", pp_cmds[i].name,
-                               pp_cmds[i].description);
-                               btr_add_output(buf, sz, pt->btrn);
-                       }
                        return 0;
                }
                FOR_EACH_MAPPED_KEY(i) {
@@ -1015,7 +994,7 @@ EXPORT_PLAY_CMD_HANDLER(ff);
 
 static int run_command(char *line, struct play_task *pt)
 {
-       int i, ret, argc;
+       int ret, argc;
        char **argv = NULL;
        char *errctx = NULL;
        const struct play_command_info *pci;
@@ -1029,26 +1008,16 @@ static int run_command(char *line, struct play_task *pt)
        if (ret == 0)
                goto out;
        argc = ret;
-
        ret = lls(lls_lookup_subcmd(argv[0], play_cmd_suite, &errctx));
-       if (ret >= 0) {
-               cmd = lls_cmd(ret, play_cmd_suite);
-               ret = lls(lls_parse(argc, argv, cmd, &lpr, &errctx));
-               if (ret < 0)
-                       goto out;
-               pci = lls_user_data(cmd);
-               ret = pci->handler(pt, lpr);
-               lls_free_parse_result(lpr, cmd);
-       } else {
-               FOR_EACH_COMMAND(i) {
-                       if (strcmp(pp_cmds[i].name, argv[0]))
-                               continue;
-                       free(errctx);
-                       errctx = NULL;
-                       ret = pp_cmds[i].handler(pt, argc, argv);
-                       break;
-               }
-       }
+       if (ret < 0)
+               goto out;
+       cmd = lls_cmd(ret, play_cmd_suite);
+       ret = lls(lls_parse(argc, argv, cmd, &lpr, &errctx));
+       if (ret < 0)
+               goto out;
+       pci = lls_user_data(cmd);
+       ret = pci->handler(pt, lpr);
+       lls_free_parse_result(lpr, cmd);
 out:
        if (errctx)
                PARA_ERROR_LOG("%s\n", errctx);