From: nishi Date: Wed, 22 May 2024 06:08:05 +0000 (+0000) Subject: creating parser X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=107e55c5b867283f4b96e7bbe60148b20ff049cf;p=dataworks.git creating parser git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@77 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Library/dw_util.h b/Library/dw_util.h index e6c97a3..ff9ba9a 100644 --- a/Library/dw_util.h +++ b/Library/dw_util.h @@ -46,6 +46,7 @@ extern "C" { #include "dataworks.h" char* __dw_strdup(const char* a); +char* __dw_strcat(const char* a, const char* b); bool __dw_strcaseequ(const char* a, const char* b); bool __dw_lockfile(FILE* fp); bool __dw_unlockfile(FILE* fp); diff --git a/Library/parser.c b/Library/parser.c index 489fbac..604633a 100644 --- a/Library/parser.c +++ b/Library/parser.c @@ -29,6 +29,7 @@ #include "dw_parser.h" #include "dw_database.h" +#include "dw_util.h" #include #include @@ -39,5 +40,49 @@ struct __dw_token* __dw_parser_parse(const char* str){ token->error = false; token->errnum = DW_ERR_SUCCESS; token->token = NULL; + char* buf = malloc(1); + buf[0] = 0; + int i; + bool dq = false; + char cbuf[2]; + cbuf[1] = 0; + int brace = 0; + char* br = malloc(1); + br[0] = 0; + for(i = 0; str[i] != 0; i++){ + cbuf[0] = str[i]; + if(brace > 0){ + if(str[i] == '(') brace++; + if(str[i] == ')') brace--; + if(brace > 0){ + char* tmp = br; + br = __dw_strcat(tmp, cbuf); + free(tmp); + }else{ + printf("%s\n", br); + __dw_parser_parse(br); + } + }else if(dq){ + char* tmp = buf; + buf = __dw_strcat(tmp, cbuf); + free(tmp); + }else if(str[i] == '('){ + printf("%s\n", buf); + free(buf); + buf = malloc(1); + buf[0] = 0; + brace++; + }else if(str[i] == ')'){ + brace--; + }else if(str[i] == '"'){ + dq = !dq; + }else{ + char* tmp = buf; + buf = __dw_strcat(tmp, cbuf); + free(tmp); + } + } + free(br); + free(buf); return token; } diff --git a/Library/util.c b/Library/util.c index b66e809..cf4b74f 100644 --- a/Library/util.c +++ b/Library/util.c @@ -45,6 +45,14 @@ char* __dw_strdup(const char* a) { return str; } +char* __dw_strcat(const char* a, const char* b){ + char* str = malloc(strlen(a) + strlen(b) + 1); + memcpy(str, a, strlen(a)); + memcpy(str + strlen(a), b, strlen(b)); + str[strlen(a) + strlen(b)] = 0; + return str; +} + bool __dw_strcaseequ(const char* a, const char* b) { if(strlen(a) != strlen(b)) return false; int i;