]> Nishi Git Mirror - dataworks.git/commitdiff
creating parser
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 22 May 2024 06:08:05 +0000 (06:08 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 22 May 2024 06:08:05 +0000 (06:08 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@77 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Library/dw_util.h
Library/parser.c
Library/util.c

index e6c97a3eafed4cbb214eb8b6ce4d3b4f0ae844e5..ff9ba9a8ef12cb62f6f7ec29779c6a2d28209b41 100644 (file)
@@ -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);
index 489fbace1c913deca10fb925dc95ae4b544b716a..604633ae2ac86959956558662015636349cab4a5 100644 (file)
@@ -29,6 +29,7 @@
 #include "dw_parser.h"
 
 #include "dw_database.h"
+#include "dw_util.h"
 
 #include <stddef.h>
 #include <stdlib.h>
@@ -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;
 }
index b66e809d81e4779ffe53a35475623bdb94f6cca4..cf4b74fb16a483db8ace367d7a07ebbdf78f6856 100644 (file)
@@ -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;