From 32b44ba835543997110ace2b894648118034fbd9 Mon Sep 17 00:00:00 2001 From: albeu Date: Mon, 18 Nov 2002 00:11:56 +0000 Subject: [PATCH] Add quoting support for string arguments (fix loading of file with space in the name) and add a new command for the console git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8226 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/input.c | 40 +++++++++++++++++++++++++++++++--------- input/input.h | 1 + 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/input/input.c b/input/input.c index b54a008c78..8e54686162 100644 --- a/input/input.c +++ b/input/input.c @@ -101,6 +101,7 @@ static mp_cmd_t mp_cmds[] = { { MP_CMD_CHELP, "help", 0, { {-1,{0}} } }, { MP_CMD_CEXIT, "exit", 0, { {-1,{0}} } }, { MP_CMD_CHIDE, "hide", 0, { {MP_CMD_ARG_INT,{3000}}, {-1,{0}} } }, + { MP_CMD_CRUN, "run", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } }, #endif { 0, NULL, 0, {} } @@ -513,14 +514,38 @@ mp_input_parse_cmd(char* str) { ptr = NULL; } break; - case MP_CMD_ARG_STRING: - e = strchr(ptr,' '); - if(!e) e = ptr+strlen(ptr); - l = e-ptr; + case MP_CMD_ARG_STRING: { + char term; + char* ptr2 = ptr, *start; + + if(ptr[0] == '\'' || ptr[0] == '"') { + term = ptr[0]; + ptr2++; + } else + term = ' '; + start = ptr2; + while(1) { + e = strchr(ptr2,term); + if(!e) break; + if(e <= ptr2 || *(e - 1) != '\\') break; + ptr2 = e + 1; + } + + if(term != ' ' && (!e || e[0] == '\0')) { + mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d is unterminated\n",cmd_def->name,i+1); + ptr = NULL; + break; + } else if(!e) e = ptr+strlen(ptr); + l = e-start; cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char)); - strncpy(cmd->args[i].v.s,ptr,l); + strncpy(cmd->args[i].v.s,start,l); cmd->args[i].v.s[l] = '\0'; - break; + ptr2 = start; + for(e = strchr(ptr2,'\\') ; e ; e = strchr(ptr2,'\\')) { + memmove(e,e+1,strlen(e)); + ptr2 = e + 1; + } + } break; case -1: ptr = NULL; default : @@ -702,9 +727,6 @@ static mp_cmd_t* mp_input_get_cmd_from_keys(int n,int* keys, int paused) { char* cmd = NULL; mp_cmd_t* ret; - // In pause mode we return pause for the first key which come - if(paused) - return mp_input_parse_cmd("pause"); if(cmd_binds) cmd = mp_input_find_bind_for_key(cmd_binds,n,keys); diff --git a/input/input.h b/input/input.h index f81f42a0ce..76e826f3a7 100644 --- a/input/input.h +++ b/input/input.h @@ -58,6 +58,7 @@ #define MP_CMD_CHELP 7000 #define MP_CMD_CEXIT 7001 #define MP_CMD_CHIDE 7002 +#define MP_CMD_CRUN 7003 // The args types #define MP_CMD_ARG_INT 0