diff options
Diffstat (limited to 'tbl_qcmd.c')
-rw-r--r-- | tbl_qcmd.c | 57 |
1 files changed, 53 insertions, 4 deletions
@@ -30,6 +30,8 @@ tbl_exec *tbl_exec_list_c(int size) //TODO check if command allready excists int tbl_exec_add(tbl_exec *tbl, tble_exec *cmd) { + int i; + if (tbl == NULL || cmd == NULL) { return -1; @@ -61,9 +63,19 @@ int tbl_exec_in_s(tbl_exec *tbl, char *cmd) for (i=0; i<tbl->size; i++) { el = tbl->cmd[i]; + //check first part of the string, and then check that after command there is whitespace if (strncmp(el->cmd, cmd, strlen(el->cmd))==0) { - return i; + if (strlen(cmd)>strlen(el->cmd)) + { + if (cmd[strlen(el->cmd)]==' ') + { + return i; + } + } if (strlen(cmd)==strlen(el->cmd)) + { + return i; + } } } @@ -73,6 +85,8 @@ int tbl_exec_in_s(tbl_exec *tbl, char *cmd) int tbl_exec_run(tbl_exec *tbl, char *cmd, void **resp) { int ret=-1; + void *clbk_data=NULL; + char *char_iter=NULL; int i; tble_exec *el=NULL; @@ -86,13 +100,43 @@ int tbl_exec_run(tbl_exec *tbl, char *cmd, void **resp) for (i=0;i<tbl->size;i++) { el = tbl->cmd[i]; + PRINT("CALLBACK CMD %s\n",cmd); if (strncmp(el->cmd, cmd, strlen(el->cmd))==0) { void *ret_resp=NULL; //execute callback - PRINT("EXEC CLB ID %d\n",i); - ret_resp = el->callback(NULL); //no params for now + //PRINT("EXEC CLB ID %d\n",i); + + //little hack need proper messaging system + //for now pass pointer with data + if (strlen(cmd)>strlen(el->cmd)) + { + if (cmd[strlen(el->cmd)]==' ') + { + char_iter = cmd; + while ((*char_iter!=' ')&&(*char_iter!=0x00)) + { + char_iter++; + } + + while ((*char_iter==' ')&&(*char_iter!=0x00)) + { + char_iter++; + } + + clbk_data = char_iter; + if (strlen(char_iter)==0) + { + clbk_data = NULL; + } + + } + } + + PRINT("CALLBACK PARAMS %s\n", clbk_data); + + ret_resp = el->callback(clbk_data); //no params for now //return if (ret_resp != NULL) @@ -425,23 +469,28 @@ int tbl_qcmd_del_by_id(tbl_qcmd *tbl, int id) if (iter->id == id) { + //PRINT("Found id\n"); // if its just last element reduce size and no other logic if (i == tbl->size-1) { + //PRINT("Remove last element\n"); tbl_qcmd_destroy_cmd(tbl->cmd[i]); + tbl->cmd[i] = NULL; tbl->size -= 1; return 1; } else //if element not last one { replace_cmd = tbl->cmd[tbl->size-1]; + tbl->cmd[tbl->size-1] = NULL; tbl->size -= 1; //free before replace remove_cmd = iter; tbl_qcmd_destroy_cmd(remove_cmd); - iter = replace_cmd; + tbl->cmd[i] = replace_cmd; + return 1; //yea yea i know } } |