changeset 22133:66fa884c46cd

str_list separator backslash-escaping
author reimar
date Mon, 05 Feb 2007 18:03:12 +0000
parents 2de97f5f0662
children 71cb05a537e1
files m_option.c
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/m_option.c	Mon Feb 05 17:53:10 2007 +0000
+++ b/m_option.c	Mon Feb 05 18:03:12 2007 +0000
@@ -511,9 +511,22 @@
   return 1;
 }
   
+static char *get_nextsep(char *ptr, char sep, int modify) {
+    char *last_ptr = ptr;
+    for(;;){
+        ptr = strchr(ptr, sep);
+        if(ptr && ptr>last_ptr && ptr[-1]=='\\'){
+            if (modify) memmove(ptr-1, ptr, strlen(ptr)+1);
+            else ptr++;
+        }else
+            break;
+    }
+    return ptr;
+}
 
 static int parse_str_list(m_option_t* opt,char *name, char *param, void* dst, int src) {
   int n = 0,len = strlen(opt->name);
+  char *str;
   char *ptr = param, *last_ptr, **res;
   int op = OP_NONE;
 
@@ -544,7 +557,7 @@
 
 
   while(ptr[0] != '\0') {
-    ptr = strchr(ptr,LIST_SEPARATOR);
+    ptr = get_nextsep(ptr, LIST_SEPARATOR, 0);
     if(!ptr) {
       n++;
       break;
@@ -561,12 +574,12 @@
   if(!dst) return 1;
 
   res = malloc((n+2)*sizeof(char*));
-  ptr = param;
+  ptr = str = strdup(param);
   n = 0;
 
   while(1) {
     last_ptr = ptr;
-    ptr = strchr(ptr,LIST_SEPARATOR);
+    ptr = get_nextsep(ptr, LIST_SEPARATOR, 1);
     if(!ptr) {
       res[n] = strdup(last_ptr);
       n++;
@@ -580,6 +593,7 @@
     n++;
   }
   res[n] = NULL;
+  free(str);
 
   switch(op) {
   case OP_ADD:
@@ -1671,13 +1685,7 @@
 
   while(ptr[0] != '\0') {
     last_ptr = ptr;
-    for(;;){
-        ptr = strchr(ptr,LIST_SEPARATOR);
-        if(ptr && ptr>last_ptr && ptr[-1]=='\\'){
-            memmove(ptr-1, ptr, strlen(ptr)+1);
-        }else
-            break;
-    }
+    ptr = get_nextsep(ptr, LIST_SEPARATOR, 1);
 
     if(!ptr) {
       r = parse_obj_settings(name,last_ptr,opt->priv,dst ? &res : NULL,n);