Changeset 212 in Main for trunk/Common
- Timestamp:
- Oct 3, 2024, 2:44:55 AM (6 weeks ago)
- Location:
- trunk/Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Makefile
r21 r212 1 1 # $Id$ 2 2 3 OBJ=o 4 STATIC=a 5 AR_FLAGS=rcs 3 6 include $(PWD)/Platform/$(PLATFORM).mk 4 7 5 8 .PHONY: all clean 6 .SUFFIXES: .c . o9 .SUFFIXES: .c .$(OBJ) 7 10 8 OBJS = string. o log.o dir.o11 OBJS = string.$(OBJ) log.$(OBJ) dir.$(OBJ) 9 12 10 all: common. a13 all: common.$(STATIC) 11 14 12 common. a: $(OBJS)13 $(AR) rcs$@ $(OBJS)15 common.$(STATIC): $(OBJS) 16 $(AR) $(AR_FLAGS)$@ $(OBJS) 14 17 15 .c. o:18 .c.$(OBJ): 16 19 $(CC) $(CFLAGS) -c -o $@ $< 17 20 18 21 clean: 19 rm -f *.o *.a 22 rm -f *.o *.a *.lib -
trunk/Common/dir.c
r150 r212 6 6 7 7 #include <sys/stat.h> 8 #ifndef _MSC_VER 8 9 #include <dirent.h> 10 #endif 9 11 #include <stdlib.h> 10 12 #include <string.h> … … 17 19 18 20 char** cm_scandir(const char* path) { 21 #ifdef _MSC_VER 22 return NULL; 23 #else 19 24 DIR* dir = opendir(path); 20 25 if(dir != NULL) { 21 26 char** r = malloc(sizeof(*r)); 27 struct dirent* d; 22 28 r[0] = NULL; 23 struct dirent* d;24 29 while((d = readdir(dir)) != NULL) { 25 30 if(strcmp(d->d_name, ".") != 0 && strcmp(d->d_name, "..") != 0) { … … 61 66 return NULL; 62 67 } 68 #endif 63 69 } -
trunk/Common/log.c
r191 r212 42 42 43 43 void cm_log(const char* name, const char* log, ...) { 44 va_list args; 45 char namebuf[LOGNAME_LENGTH + 1]; 46 int i; 47 char* result; 48 char cbuf[2]; 44 49 if(!cm_do_log) return; 45 va_list args;46 50 va_start(args, log); 47 char namebuf[LOGNAME_LENGTH + 1];48 51 memset(namebuf, '.', LOGNAME_LENGTH); 49 52 namebuf[LOGNAME_LENGTH] = 0; 50 int i;51 53 for(i = 0; name[i] != 0 && i < LOGNAME_LENGTH; i++) { 52 54 namebuf[i] = name[i]; 53 55 } 54 56 55 char*result = malloc(1);57 result = malloc(1); 56 58 result[0] = 0; 57 59 58 char cbuf[2];59 60 cbuf[1] = 0; 60 61 … … 70 71 int a = va_arg(args, int); 71 72 char buf[128]; 73 char* tmp = result; 72 74 sprintf(buf, "%d", a); 73 char* tmp = result;74 75 result = cm_strcat(tmp, buf); 75 76 free(tmp); 76 77 } 77 78 } else { 79 char* tmp = result; 78 80 cbuf[0] = log[i]; 79 char* tmp = result;80 81 result = cm_strcat(tmp, cbuf); 81 82 free(tmp); -
trunk/Common/string.c
r70 r212 8 8 9 9 char* cm_strcat(const char* a, const char* b) { 10 char* str; 10 11 if(a == NULL) a = ""; 11 12 if(b == NULL) b = ""; 12 char*str = malloc(strlen(a) + strlen(b) + 1);13 str = malloc(strlen(a) + strlen(b) + 1); 13 14 memcpy(str, a, strlen(a)); 14 15 memcpy(str + strlen(a), b, strlen(b)); … … 27 28 28 29 bool cm_endswith(const char* str, const char* end) { 30 int i; 29 31 if(strlen(str) < strlen(end)) return false; 30 int i;31 32 for(i = strlen(str) - strlen(end); i < strlen(str); i++) { 32 33 if(str[i] != end[i - strlen(str) + strlen(end)]) return false; … … 36 37 37 38 bool cm_nocase_endswith(const char* str, const char* end) { 39 int i; 38 40 if(strlen(str) < strlen(end)) return false; 39 int i;40 41 for(i = strlen(str) - strlen(end); i < strlen(str); i++) { 41 42 if(tolower(str[i]) != tolower(end[i - strlen(str) + strlen(end)])) return false; … … 76 77 int i; 77 78 char** r = malloc(sizeof(*r)); 78 r[0] = NULL;79 79 char* b = malloc(1); 80 b[0] = 0;81 80 char cbuf[2]; 82 cbuf[1] = 0;83 81 bool dq = false; 84 82 bool sq = false; 83 r[0] = NULL; 84 b[0] = 0; 85 cbuf[1] = 0; 85 86 for(i = 0;; i++) { 86 87 int j; … … 113 114 sq = !sq; 114 115 } else { 116 char* tmp = b; 115 117 cbuf[0] = str[i]; 116 char* tmp = b;117 118 b = cm_strcat(tmp, cbuf); 118 119 free(tmp); … … 125 126 126 127 bool cm_strcaseequ(const char* a, const char* b) { 128 int i; 127 129 if(a == NULL) return false; 128 130 if(b == NULL) return false; 129 131 if(strlen(a) != strlen(b)) return false; 130 int i;131 132 for(i = 0; a[i] != 0; i++) { 132 133 if(tolower(a[i]) != tolower(b[i])) return false; … … 155 156 int i; 156 157 char* result = malloc(1); 158 char cbuf[2]; 157 159 result[0] = 0; 158 char cbuf[2];159 160 cbuf[1] = 0; 160 161 for(i = 0; str[i] != 0; i++) { … … 184 185 int i; 185 186 char* result = malloc(1); 187 char cbuf[2]; 186 188 result[0] = 0; 187 char cbuf[2];188 189 cbuf[1] = 0; 189 190 for(i = 0; str[i] != 0; i++) { … … 191 192 if('!' <= str[i] && str[i] <= '@' && str[i] != '.' && str[i] != '-' && str[i] != '/' && !('0' <= str[i] && str[i] <= '9')) { 192 193 char code[4]; 194 char* tmp = result; 193 195 sprintf(code, "%%%02X", str[i]); 194 char* tmp = result;195 196 result = cm_strcat(tmp, code); 196 197 free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.