diff --git a/console.c b/console.c index 2a39c9c..ff7602b 100644 --- a/console.c +++ b/console.c @@ -91,6 +91,17 @@ console_get_metrics(int *height,int *width) return 0; } +int +_execute(mfshell_t *mfshell, int argc, char **argv) +{ + _cmd_t* curr_cmd; + for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) { + if (strcmp(argv[0], curr_cmd->name) == 0) { + return curr_cmd->handler(mfshell, argc, argv); + } + } +} + int _execute_shell_command(mfshell_t *mfshell,char *command) { @@ -125,14 +136,8 @@ _execute_shell_command(mfshell_t *mfshell,char *command) argc = stringv_len(argv); - _cmd_t* curr_cmd; - for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) { - if (strcmp(argv[0], curr_cmd->name) == 0) { - // TODO: handle retval - retval = curr_cmd->handler(mfshell, argc, argv); - break; - } - } + // TODO: handle retval + retval = _execute(mfshell, argc, argv); stringv_free(argv,STRINGV_FREE_ALL); diff --git a/mfshell.c b/mfshell.c index 5b3bf1c..c50c1c2 100644 --- a/mfshell.c +++ b/mfshell.c @@ -89,7 +89,8 @@ mfshell_create(int app_id,char *app_key,char *server) mfshell->create_call_signature = _create_call_signature; mfshell->create_signed_get = _create_signed_get; - mfshell->exec = _execute_shell_command; + mfshell->exec = _execute; + mfshell->exec_string = _execute_shell_command; // configure REST API callbacks mfshell->get_session_token = _get_session_token; diff --git a/private.h b/private.h index 980d510..f2c248d 100644 --- a/private.h +++ b/private.h @@ -84,7 +84,8 @@ struct _mfshell_s char* (*create_signed_get) (_mfshell_t*,int,char*,char*,...); char* (*create_signed_post) (_mfshell_t*,int,char*,char*,...); - int (*exec) (_mfshell_t*,char*); + int (*exec) (_mfshell_t*, int argc, char **argv); + int (*exec_string) (_mfshell_t*,char*); /* REST API calls */ int (*get_session_token) (_mfshell_t*); @@ -120,6 +121,9 @@ _create_call_signature(_mfshell_t *mfshell,char *url,char *args); char* _create_signed_get(_mfshell_t *mfshell,int ssl,char *api,char *fmt,...); +int +_execute(_mfshell_t *mfshell, int argc, char **argv); + int _execute_shell_command(_mfshell_t *mfshell,char *command);