- Timestamp:
- Sep 13, 2024, 7:08:00 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/cm_string.h
r4 r5 3 3 #ifndef __CM_STRING_H__ 4 4 #define __CM_STRING_H__ 5 6 #include <stdbool.h> 5 7 6 8 char* cm_strcat(const char* a, const char* b); … … 9 11 char* cm_trimend(const char* str); 10 12 char* cm_trim(const char* str); 13 char** cm_split(const char* str, const char* by); 14 bool cm_strcaseequ(const char* a, const char* b); 11 15 12 16 #endif -
trunk/Common/string.c
r4 r5 3 3 #include <string.h> 4 4 #include <stdlib.h> 5 #include <stdbool.h> 6 #include <ctype.h> 5 7 6 8 char* cm_strcat(const char* a, const char* b) { … … 42 44 return s; 43 45 } 46 47 char** cm_split(const char* str, const char* by){ 48 int i; 49 char** r = malloc(sizeof(*r)); 50 r[0] = NULL; 51 char* b = malloc(1); 52 b[0] = 0; 53 char cbuf[2]; 54 cbuf[1] = 0; 55 bool dq = false; 56 bool sq = false; 57 for(i = 0;; i++){ 58 int j; 59 bool has = false; 60 for(j = 0; by[j] != 0; j++){ 61 if(by[j] == str[i]){ 62 has = true; 63 break; 64 } 65 } 66 if(!(dq || sq) && (has || str[i] == 0)){ 67 if(strlen(b) > 0){ 68 char** old = r; 69 int j; 70 for(j = 0; old[j] != NULL; j++); 71 r = malloc(sizeof(*r) * (j + 2)); 72 for(j = 0; old[j] != NULL; j++) r[j] = old[j]; 73 r[j] = b; 74 r[j + 1] = NULL; 75 free(old); 76 } 77 b = malloc(1); 78 b[0] = 0; 79 if(str[i] == 0) break; 80 }else{ 81 if(str[i] == '"' && !sq){ 82 dq = !dq; 83 }else if(str[i] == '\'' && !dq){ 84 sq = !sq; 85 }else{ 86 cbuf[0] = str[i]; 87 char* tmp = b; 88 b = cm_strcat(tmp, cbuf); 89 free(tmp); 90 } 91 } 92 } 93 free(b); 94 return r; 95 } 96 97 bool cm_strcaseequ(const char* a, const char* b){ 98 if(a == NULL) return false; 99 if(b == NULL) return false; 100 if(strlen(a) != strlen(b)) return false; 101 int i; 102 for(i = 0; a[i] != 0; i++){ 103 if(tolower(a[i]) != tolower(b[i])) return false; 104 } 105 return true; 106 } -
trunk/Server/config.c
r4 r5 23 23 char* l = cm_trim(line); 24 24 if(strlen(l) > 0 && l[0] != '#'){ 25 printf("[%s]\n", l); 25 char** r = cm_split(l, " \t"); 26 int i; 27 if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")){ 28 for(i = 1; r[i] != NULL; i++){ 29 if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")){ 30 for(i = 0; r[i] != NULL; i++) free(r[i]); 31 free(r); 32 free(line); 33 free(l); 34 fclose(f); 35 return 1; 36 } 37 } 38 } 39 for(i = 0; r[i] != NULL; i++) free(r[i]); 40 free(r); 26 41 } 27 42 free(l); … … 40 55 return 0; 41 56 }else{ 57 cm_log("Config", "Could not open the file"); 42 58 return 1; 43 59 }
Note:
See TracChangeset
for help on using the changeset viewer.