Changeset 6 in Main for trunk/Common
- Timestamp:
- Sep 13, 2024, 7:28:20 PM (2 months ago)
- Location:
- trunk/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Makefile
r3 r6 11 11 12 12 common.a: $(OBJS) 13 arrcs $@ $(OBJS)13 $(AR) rcs $@ $(OBJS) 14 14 15 15 .c.o: -
trunk/Common/log.c
r3 r6 40 40 result = cm_strcat(tmp, va_arg(args, char*)); 41 41 free(tmp); 42 } else if(log[i] == 'd') { 43 int a = va_arg(args, int); 44 char buf[128]; 45 sprintf(buf, "%d", a); 46 char* tmp = result; 47 result = cm_strcat(tmp, buf); 48 free(tmp); 42 49 } 43 50 } else { -
trunk/Common/string.c
r5 r6 16 16 char* cm_strdup(const char* str) { return cm_strcat(str, ""); } 17 17 18 char* cm_trimstart(const char* str) {18 char* cm_trimstart(const char* str) { 19 19 int i; 20 for(i = 0; str[i] != 0; i++) {21 if(str[i] != ' ' && str[i] != '\t') {20 for(i = 0; str[i] != 0; i++) { 21 if(str[i] != ' ' && str[i] != '\t') { 22 22 return cm_strdup(str + i); 23 23 } … … 26 26 } 27 27 28 char* cm_trimend(const char* str) {28 char* cm_trimend(const char* str) { 29 29 char* s = cm_strdup(str); 30 30 int i; 31 for(i = strlen(s) - 1; i >= 0; i--) {32 if(s[i] != '\t' && s[i] != ' ') {31 for(i = strlen(s) - 1; i >= 0; i--) { 32 if(s[i] != '\t' && s[i] != ' ') { 33 33 s[i + 1] = 0; 34 34 break; … … 38 38 } 39 39 40 char* cm_trim(const char* str) {40 char* cm_trim(const char* str) { 41 41 char* tmp = cm_trimstart(str); 42 42 char* s = cm_trimend(tmp); … … 45 45 } 46 46 47 char** cm_split(const char* str, const char* by) {47 char** cm_split(const char* str, const char* by) { 48 48 int i; 49 49 char** r = malloc(sizeof(*r)); … … 55 55 bool dq = false; 56 56 bool sq = false; 57 for(i = 0;; i++) {57 for(i = 0;; i++) { 58 58 int j; 59 59 bool has = false; 60 for(j = 0; by[j] != 0; j++) {61 if(by[j] == str[i]) {60 for(j = 0; by[j] != 0; j++) { 61 if(by[j] == str[i]) { 62 62 has = true; 63 63 break; 64 64 } 65 65 } 66 if(!(dq || sq) && (has || str[i] == 0)) {67 if(strlen(b) > 0) {66 if(!(dq || sq) && (has || str[i] == 0)) { 67 if(strlen(b) > 0) { 68 68 char** old = r; 69 69 int j; 70 for(j = 0; old[j] != NULL; j++); 70 for(j = 0; old[j] != NULL; j++) 71 ; 71 72 r = malloc(sizeof(*r) * (j + 2)); 72 73 for(j = 0; old[j] != NULL; j++) r[j] = old[j]; … … 78 79 b[0] = 0; 79 80 if(str[i] == 0) break; 80 } else{81 if(str[i] == '"' && !sq) {81 } else { 82 if(str[i] == '"' && !sq) { 82 83 dq = !dq; 83 } else if(str[i] == '\'' && !dq){84 } else if(str[i] == '\'' && !dq) { 84 85 sq = !sq; 85 } else{86 } else { 86 87 cbuf[0] = str[i]; 87 88 char* tmp = b; … … 95 96 } 96 97 97 bool cm_strcaseequ(const char* a, const char* b) {98 bool cm_strcaseequ(const char* a, const char* b) { 98 99 if(a == NULL) return false; 99 100 if(b == NULL) return false; 100 101 if(strlen(a) != strlen(b)) return false; 101 102 int i; 102 for(i = 0; a[i] != 0; i++) {103 for(i = 0; a[i] != 0; i++) { 103 104 if(tolower(a[i]) != tolower(b[i])) return false; 104 105 }
Note:
See TracChangeset
for help on using the changeset viewer.