diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2017-09-23 00:41:30 +0100 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2017-11-23 21:34:11 +0000 |
commit | ab862e33add80efae9da080df9369dd3c254cb54 (patch) | |
tree | 0a46c8e2c709717dbfdd691ae5d2c6d0df5e16db /src | |
parent | 6d000e51014a2c34a510539ed9f4e8b9a0c8c059 (diff) | |
download | imv-ab862e33add80efae9da080df9369dd3c254cb54.tar.gz |
Give commands the full arg string too
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 8 | ||||
-rw-r--r-- | src/commands.h | 2 | ||||
-rw-r--r-- | src/imv.c | 56 |
3 files changed, 34 insertions, 32 deletions
diff --git a/src/commands.c b/src/commands.c index 83ca4bc..6f1e2f4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. struct command { char* command; - void (*handler)(struct imv_list *args, void *data); + void (*handler)(struct imv_list *args, const char *argstr, void *data); char* alias; }; @@ -45,7 +45,7 @@ void imv_commands_free(struct imv_commands *cmds) free(cmds); } -void imv_command_register(struct imv_commands *cmds, const char *command, void (*handler)(struct imv_list*, void*)) +void imv_command_register(struct imv_commands *cmds, const char *command, void (*handler)(struct imv_list*, const char*, void*)) { struct command *cmd = malloc(sizeof(struct command)); cmd->command = strdup(command); @@ -73,7 +73,9 @@ int imv_command_exec(struct imv_commands *cmds, const char *command, void *data) struct command *cmd = cmds->command_list->items[i]; if(!strcmp(cmd->command, args->items[0])) { if(cmd->handler) { - cmd->handler(args, data); + /* argstr = all args as a single string */ + const char *argstr = command + strlen(cmd->command) + 1; + cmd->handler(args, argstr, data); ret = 0; } else if(cmd->alias) { ret = imv_command_exec(cmds, cmd->alias, data); diff --git a/src/commands.h b/src/commands.h index a955fac..2da0617 100644 --- a/src/commands.h +++ b/src/commands.h @@ -26,7 +26,7 @@ struct imv_commands { struct imv_commands *imv_commands_create(void); void imv_commands_free(struct imv_commands *cmds); -void imv_command_register(struct imv_commands *cmds, const char *command, void (*handler)(struct imv_list*, void*)); +void imv_command_register(struct imv_commands *cmds, const char *command, void (*handler)(struct imv_list*, const char*, void*)); void imv_command_alias(struct imv_commands *cmds, const char *command, const char *alias); int imv_command_exec(struct imv_commands *cmds, const char *command, void *data); @@ -98,15 +98,15 @@ enum config_section { CFG_BINDS }; -void command_quit(struct imv_list *args, void *data); -void command_pan(struct imv_list *args, void *data); -void command_select_rel(struct imv_list *args, void *data); -void command_select_abs(struct imv_list *args, void *data); -void command_zoom(struct imv_list *args, void *data); -void command_remove(struct imv_list *args, void *data); -void command_fullscreen(struct imv_list *args, void *data); -void command_overlay(struct imv_list *args, void *data); -void command_exec(struct imv_list *args, void *data); +void command_quit(struct imv_list *args, const char *argstr, void *data); +void command_pan(struct imv_list *args, const char *argstr, void *data); +void command_select_rel(struct imv_list *args, const char *argstr, void *data); +void command_select_abs(struct imv_list *args, const char *argstr, void *data); +void command_zoom(struct imv_list *args, const char *argstr, void *data); +void command_remove(struct imv_list *args, const char *argstr, void *data); +void command_fullscreen(struct imv_list *args, const char *argstr, void *data); +void command_overlay(struct imv_list *args, const char *argstr, void *data); +void command_exec(struct imv_list *args, const char *argstr, void *data); static bool setup_window(struct imv *imv); static void handle_event(struct imv *imv, SDL_Event *event); @@ -966,15 +966,17 @@ bool imv_load_config(struct imv *imv) return true; } -void command_quit(struct imv_list *args, void *data) +void command_quit(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; struct imv *imv = data; imv->quit = true; } -void command_pan(struct imv_list *args, void *data) +void command_pan(struct imv_list *args, const char *argstr, void *data) { + (void)argstr; struct imv *imv = data; if(args->len != 3) { return; @@ -986,8 +988,9 @@ void command_pan(struct imv_list *args, void *data) imv_viewport_move(imv->view, x, y, imv->texture); } -void command_select_rel(struct imv_list *args, void *data) +void command_select_rel(struct imv_list *args, const char *argstr, void *data) { + (void)argstr; struct imv *imv = data; if(args->len != 2) { return; @@ -999,21 +1002,24 @@ void command_select_rel(struct imv_list *args, void *data) imv->slideshow_time_elapsed = 0; } -void command_select_abs(struct imv_list *args, void *data) +void command_select_abs(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; (void)data; } -void command_zoom(struct imv_list *args, void *data) +void command_zoom(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; (void)data; } -void command_remove(struct imv_list *args, void *data) +void command_remove(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; struct imv *imv = data; char* path = strdup(imv_navigator_selection(imv->navigator)); imv_navigator_remove(imv->navigator, path); @@ -1022,34 +1028,28 @@ void command_remove(struct imv_list *args, void *data) imv->slideshow_time_elapsed = 0; } -void command_fullscreen(struct imv_list *args, void *data) +void command_fullscreen(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; struct imv *imv = data; imv_viewport_toggle_fullscreen(imv->view); } -void command_overlay(struct imv_list *args, void *data) +void command_overlay(struct imv_list *args, const char *argstr, void *data) { (void)args; + (void)argstr; struct imv *imv = data; imv->overlay_enabled = !imv->overlay_enabled; imv->need_redraw = true; } -void command_exec(struct imv_list *args, void *data) +void command_exec(struct imv_list *args, const char *argstr, void *data) { + (void)args; (void)data; - char *cmd = calloc(4096, 1); - for(size_t i = 0; i < args->len; ++i) { - strcat(cmd, args->items[i]); - - if(i + 1 != args->len) { - strcat(cmd, " "); - } - } - system(cmd); - free(cmd); + system(argstr); } /* vim:set ts=2 sts=2 sw=2 et: */ |