From: Nishi Date: Fri, 11 Oct 2024 21:18:18 +0000 (+0000) Subject: proper arg parser X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=a2061e3c6558ae38d09509434760f23f74c20687;p=rbuild.git proper arg parser git-svn-id: file:///raid/svn-personal/rbuild/trunk@16 c68d3453-7f82-0740-9748-1d72386a946b --- diff --git a/Server/task.c b/Server/task.c index c8efe54..abd27f8 100644 --- a/Server/task.c +++ b/Server/task.c @@ -43,10 +43,11 @@ char** rbs_parse_args(const char* cmd, const char* arg) { char** stack = malloc(sizeof(*stack)); int i; int incr = 0; + CMBOOL dq = CMFALSE; stack[0] = NULL; rbs_push(&stack, cmd); for(i = 0;; i++) { - if(str[i] == 0 || str[i] == ' ') { + if(str[i] == 0 || (str[i] == ' ' && !dq)) { char oldc = str[i]; char* got = str + incr; str[i] = 0; @@ -66,6 +67,19 @@ char** rbs_parse_args(const char* cmd, const char* arg) { incr = i + 1; if(oldc == 0) break; + } else if(str[i] == '"') { + int oldi = i; + dq = !dq; + for(; str[i] != 0; i++) { + str[i] = str[i + 1]; + } + i = oldi - 1; + } else if(str[i] == '\\') { + int oldi = i; + for(; str[i] != 0; i++) { + str[i] = str[i + 1]; + } + i = oldi; } } free(str);