]> Nishi Git Mirror - tewi.git/commitdiff
can handle include now
authorNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 10:08:00 +0000 (10:08 +0000)
committerNishi <nishi@nishi.boats>
Fri, 13 Sep 2024 10:08:00 +0000 (10:08 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@5 8739d7e6-ffea-ec47-b151-bdff447c6205

Common/cm_string.h
Common/string.c
Server/config.c

index c055ec352a33daa4e6899860163972d27ddb5d38..01f7f18e0cdfcd105ed3ff2ef0a580726cce34fa 100644 (file)
@@ -3,10 +3,14 @@
 #ifndef __CM_STRING_H__
 #define __CM_STRING_H__
 
+#include <stdbool.h>
+
 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
index f35c3307d9cacca2c5578f4f0fd1348a758454e1..d5eccb058648102efa6ee4521ca8734da9991be6 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
+#include <ctype.h>
 
 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;
+}
index eba0c2c2a23b346ace031e216424e35d0969d452..96b5b7f96d60f42f2a12037777c182dc498a2239 100644 (file)
@@ -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;
        }
 }