From: Nishi Date: Fri, 13 Sep 2024 10:08:00 +0000 (+0000) Subject: can handle include now X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e8ba2c3751f77dff388a38059d85581cfc0bbaa4;p=tewi.git can handle include now git-svn-id: file:///raid/svn-personal/tewi/trunk@5 8739d7e6-ffea-ec47-b151-bdff447c6205 --- diff --git a/Common/cm_string.h b/Common/cm_string.h index c055ec3..01f7f18 100644 --- a/Common/cm_string.h +++ b/Common/cm_string.h @@ -3,10 +3,14 @@ #ifndef __CM_STRING_H__ #define __CM_STRING_H__ +#include + char* cm_strcat(const char* a, const char* b); char* cm_strdup(const char* str); char* cm_trimstart(const char* str); char* cm_trimend(const char* str); char* cm_trim(const char* str); +char** cm_split(const char* str, const char* by); +bool cm_strcaseequ(const char* a, const char* b); #endif diff --git a/Common/string.c b/Common/string.c index f35c330..d5eccb0 100644 --- a/Common/string.c +++ b/Common/string.c @@ -2,6 +2,8 @@ #include #include +#include +#include char* cm_strcat(const char* a, const char* b) { char* str = malloc(strlen(a) + strlen(b) + 1); @@ -41,3 +43,64 @@ char* cm_trim(const char* str){ free(tmp); return s; } + +char** cm_split(const char* str, const char* by){ + int i; + char** r = malloc(sizeof(*r)); + r[0] = NULL; + char* b = malloc(1); + b[0] = 0; + char cbuf[2]; + cbuf[1] = 0; + bool dq = false; + bool sq = false; + for(i = 0;; i++){ + int j; + bool has = false; + for(j = 0; by[j] != 0; j++){ + if(by[j] == str[i]){ + has = true; + break; + } + } + if(!(dq || sq) && (has || str[i] == 0)){ + if(strlen(b) > 0){ + char** old = r; + int j; + for(j = 0; old[j] != NULL; j++); + r = malloc(sizeof(*r) * (j + 2)); + for(j = 0; old[j] != NULL; j++) r[j] = old[j]; + r[j] = b; + r[j + 1] = NULL; + free(old); + } + b = malloc(1); + b[0] = 0; + if(str[i] == 0) break; + }else{ + if(str[i] == '"' && !sq){ + dq = !dq; + }else if(str[i] == '\'' && !dq){ + sq = !sq; + }else{ + cbuf[0] = str[i]; + char* tmp = b; + b = cm_strcat(tmp, cbuf); + free(tmp); + } + } + } + free(b); + return r; +} + +bool cm_strcaseequ(const char* a, const char* b){ + if(a == NULL) return false; + if(b == NULL) return false; + if(strlen(a) != strlen(b)) return false; + int i; + for(i = 0; a[i] != 0; i++){ + if(tolower(a[i]) != tolower(b[i])) return false; + } + return true; +} diff --git a/Server/config.c b/Server/config.c index eba0c2c..96b5b7f 100644 --- a/Server/config.c +++ b/Server/config.c @@ -22,7 +22,22 @@ int tw_config_read(const char* path){ if(cbuf[0] == '\n' || c <= 0){ char* l = cm_trim(line); if(strlen(l) > 0 && l[0] != '#'){ - printf("[%s]\n", l); + char** r = cm_split(l, " \t"); + int i; + if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")){ + for(i = 1; r[i] != NULL; i++){ + if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")){ + for(i = 0; r[i] != NULL; i++) free(r[i]); + free(r); + free(line); + free(l); + fclose(f); + return 1; + } + } + } + for(i = 0; r[i] != NULL; i++) free(r[i]); + free(r); } free(l); free(line); @@ -39,6 +54,7 @@ int tw_config_read(const char* path){ fclose(f); return 0; }else{ + cm_log("Config", "Could not open the file"); return 1; } }