add function to execute raw commands via argc and argv

This commit is contained in:
josch
2014-09-17 00:11:09 +02:00
parent c57ccd6df1
commit b25e4ad7d8
3 changed files with 20 additions and 10 deletions

View File

@@ -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;
}
}
retval = _execute(mfshell, argc, argv);
stringv_free(argv,STRINGV_FREE_ALL);

View File

@@ -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;

View File

@@ -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);