changeset 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 fefc56153615
children 4b8fcc2af8f1
files input/input.c input/input.h
diffstat 2 files changed, 32 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Mon Nov 18 00:09:37 2002 +0000
+++ b/input/input.c	Mon Nov 18 00:11:56 2002 +0000
@@ -101,6 +101,7 @@
   { 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 @@
 	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 @@
 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);
--- a/input/input.h	Mon Nov 18 00:09:37 2002 +0000
+++ b/input/input.h	Mon Nov 18 00:11:56 2002 +0000
@@ -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