mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 23:02:37 +00:00
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
This commit is contained in:
parent
dc7759b0a8
commit
32b44ba835
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user