Mercurial > mplayer.hg
comparison input/input.c @ 8225:c032962b51a1
Add quoting support for string arguments (fix loading of file with space in
the name) and add a new command for the console
author | albeu |
---|---|
date | Mon, 18 Nov 2002 00:11:56 +0000 |
parents | 419bdbfdb660 |
children | 772d6d27fd66 |
comparison
equal
deleted
inserted
replaced
8224:fefc56153615 | 8225:c032962b51a1 |
---|---|
99 { MP_CMD_MENU, "menu",1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } }, | 99 { MP_CMD_MENU, "menu",1, { {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } }, |
100 { MP_CMD_SET_MENU, "set_menu",1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } }, | 100 { MP_CMD_SET_MENU, "set_menu",1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_STRING, {0}}, {-1,{0}} } }, |
101 { MP_CMD_CHELP, "help", 0, { {-1,{0}} } }, | 101 { MP_CMD_CHELP, "help", 0, { {-1,{0}} } }, |
102 { MP_CMD_CEXIT, "exit", 0, { {-1,{0}} } }, | 102 { MP_CMD_CEXIT, "exit", 0, { {-1,{0}} } }, |
103 { MP_CMD_CHIDE, "hide", 0, { {MP_CMD_ARG_INT,{3000}}, {-1,{0}} } }, | 103 { MP_CMD_CHIDE, "hide", 0, { {MP_CMD_ARG_INT,{3000}}, {-1,{0}} } }, |
104 { MP_CMD_CRUN, "run", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } }, | |
104 #endif | 105 #endif |
105 | 106 |
106 { 0, NULL, 0, {} } | 107 { 0, NULL, 0, {} } |
107 }; | 108 }; |
108 | 109 |
511 if(errno != 0) { | 512 if(errno != 0) { |
512 mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d isn't a float\n",cmd_def->name,i+1); | 513 mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d isn't a float\n",cmd_def->name,i+1); |
513 ptr = NULL; | 514 ptr = NULL; |
514 } | 515 } |
515 break; | 516 break; |
516 case MP_CMD_ARG_STRING: | 517 case MP_CMD_ARG_STRING: { |
517 e = strchr(ptr,' '); | 518 char term; |
518 if(!e) e = ptr+strlen(ptr); | 519 char* ptr2 = ptr, *start; |
519 l = e-ptr; | 520 |
521 if(ptr[0] == '\'' || ptr[0] == '"') { | |
522 term = ptr[0]; | |
523 ptr2++; | |
524 } else | |
525 term = ' '; | |
526 start = ptr2; | |
527 while(1) { | |
528 e = strchr(ptr2,term); | |
529 if(!e) break; | |
530 if(e <= ptr2 || *(e - 1) != '\\') break; | |
531 ptr2 = e + 1; | |
532 } | |
533 | |
534 if(term != ' ' && (!e || e[0] == '\0')) { | |
535 mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d is unterminated\n",cmd_def->name,i+1); | |
536 ptr = NULL; | |
537 break; | |
538 } else if(!e) e = ptr+strlen(ptr); | |
539 l = e-start; | |
520 cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char)); | 540 cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char)); |
521 strncpy(cmd->args[i].v.s,ptr,l); | 541 strncpy(cmd->args[i].v.s,start,l); |
522 cmd->args[i].v.s[l] = '\0'; | 542 cmd->args[i].v.s[l] = '\0'; |
523 break; | 543 ptr2 = start; |
544 for(e = strchr(ptr2,'\\') ; e ; e = strchr(ptr2,'\\')) { | |
545 memmove(e,e+1,strlen(e)); | |
546 ptr2 = e + 1; | |
547 } | |
548 } break; | |
524 case -1: | 549 case -1: |
525 ptr = NULL; | 550 ptr = NULL; |
526 default : | 551 default : |
527 mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown argument %d\n",i); | 552 mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown argument %d\n",i); |
528 } | 553 } |
700 | 725 |
701 static mp_cmd_t* | 726 static mp_cmd_t* |
702 mp_input_get_cmd_from_keys(int n,int* keys, int paused) { | 727 mp_input_get_cmd_from_keys(int n,int* keys, int paused) { |
703 char* cmd = NULL; | 728 char* cmd = NULL; |
704 mp_cmd_t* ret; | 729 mp_cmd_t* ret; |
705 // In pause mode we return pause for the first key which come | |
706 if(paused) | |
707 return mp_input_parse_cmd("pause"); | |
708 | 730 |
709 if(cmd_binds) | 731 if(cmd_binds) |
710 cmd = mp_input_find_bind_for_key(cmd_binds,n,keys); | 732 cmd = mp_input_find_bind_for_key(cmd_binds,n,keys); |
711 if(cmd == NULL) | 733 if(cmd == NULL) |
712 cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); | 734 cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); |