From: nishi Date: Thu, 23 May 2024 06:07:12 +0000 (+0000) Subject: parser is working X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=fb21527c76583e42ee9448bfefcd4f0fc10ec19a;p=dataworks.git parser is working git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@86 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Client/main.c b/Client/main.c index 42bc13d..abe1f3b 100644 --- a/Client/main.c +++ b/Client/main.c @@ -233,9 +233,6 @@ int main(int argc, char** argv) { } else { printf("Parser returned NULL. Help!\n"); } - if(fprog != NULL){ - printf("%s\n", line); - } free(line); if(strlen(linebuf) > 0){ char* newbuf = malloc(strlen(linebuf) - i); diff --git a/Library/parser.c b/Library/parser.c index 5a31c15..3d72a35 100644 --- a/Library/parser.c +++ b/Library/parser.c @@ -34,6 +34,7 @@ #include #include #include +#include struct __dw_token* __dw_parser_parse(const char* name, const char* str) { struct __dw_token* token = malloc(sizeof(*token)); @@ -55,10 +56,49 @@ struct __dw_token* __dw_parser_parse(const char* name, const char* str) { if(str[i] == '(') brace++; if(str[i] == ')') brace--; if(brace > 0) { + if(str[i] == ','){ + i++; + for(; str[i] != 0 && (str[i] == '\t' || str[i] == ' '); i++); + i--; + } char* tmp = br; br = __dw_strcat(tmp, cbuf); free(tmp); } else { + int j; + for(j = 0; buf[j] != 0; j++){ + if(buf[j] != ' ' && buf[j] != '\t'){ + char* newbuf = __dw_strdup(buf + j); + free(buf); + buf = newbuf; + break; + } + } + for(j = 0; br[j] != 0; j++){ + if(br[j] != ' ' && br[j] != '\t'){ + char* newbr = __dw_strdup(br + j); + free(br); + br = newbr; + break; + } + } + for(j = strlen(buf) - 1; j >= 0; j--){ + if(buf[j] != ' ' && buf[j] != '\t'){ + buf[j + 1] = 0; + break; + } + } + for(j = strlen(br) - 1; j >= 0; j--){ + if(br[j] != ' ' && br[j] != '\t'){ + br[j + 1] = 0; + break; + } + } + if(buf[0] == ','){ + char* newbuf = __dw_strdup(buf + 1); + free(buf); + buf = newbuf; + } printf("%s:%s\n", buf, br); __dw_parser_parse(buf, br); free(br); @@ -69,9 +109,13 @@ struct __dw_token* __dw_parser_parse(const char* name, const char* str) { buf[0] = 0; } } else if(dq) { - char* tmp = buf; - buf = __dw_strcat(tmp, cbuf); - free(tmp); + if(str[i] == '"'){ + dq = !dq; + }else{ + char* tmp = buf; + buf = __dw_strcat(tmp, cbuf); + free(tmp); + } } else if(str[i] == '(') { brace++; } else if(str[i] == ')') {