From: Nishi Date: Fri, 11 Oct 2024 14:16:36 +0000 (+0000) Subject: stuff X-Git-Url: https://git.chaotic.ninja/gitweb/nishi/?a=commitdiff_plain;h=7657e6d4eb73b5c0778e61cbfc1d67ef027ee26c;p=rbuild.git stuff git-svn-id: file:///raid/svn-personal/rbuild/trunk@4 c68d3453-7f82-0740-9748-1d72386a946b --- diff --git a/Client/Makefile b/Client/Makefile index b9530bf..be2d12d 100644 --- a/Client/Makefile +++ b/Client/Makefile @@ -1,3 +1,20 @@ # $Id$ include $(PWD)/Platform/$(PLATFORM).mk + +.PHONY: all clean +.SUFFIXES: .c .o + +OBJS = main.o +OBJS += ../Common/common.a + +all: rbuild$(EXEC) + +rbuild$(EXEC): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o *.exe rbuild diff --git a/Client/main.c b/Client/main.c new file mode 100644 index 0000000..989daf6 --- /dev/null +++ b/Client/main.c @@ -0,0 +1,4 @@ +/* $Id$ */ + +int main(){ +} diff --git a/Common/Makefile b/Common/Makefile index b9530bf..a97c433 100644 --- a/Common/Makefile +++ b/Common/Makefile @@ -1,3 +1,19 @@ # $Id$ include $(PWD)/Platform/$(PLATFORM).mk + +.PHONY: all clean +.SUFFIXES: .c .o + +OBJS = string.o + +all: common.a + +common.a: $(OBJS) + $(AR) rcs $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o *.a diff --git a/Common/cm_string.h b/Common/cm_string.h new file mode 100644 index 0000000..0132139 --- /dev/null +++ b/Common/cm_string.h @@ -0,0 +1,22 @@ +/* $Id$ */ + +#ifndef __CM_STRING_H__ +#define __CM_STRING_H__ + +#include + +int cm_hex(const char* str, int len); +bool cm_nocase_endswith(const char* str, const char* end); +bool cm_endswith(const char* str, const char* end); +char* cm_html_escape(const char* str); +char* cm_url_escape(const char* str); +char* cm_strcat(const char* a, const char* b); +char* cm_strcat3(const char* a, const char* b, const char* c); +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 new file mode 100644 index 0000000..f138160 --- /dev/null +++ b/Common/string.c @@ -0,0 +1,205 @@ +/* $Id$ */ + +#include +#include +#include +#include +#include + +char* cm_strcat(const char* a, const char* b) { + char* str; + if(a == NULL) a = ""; + if(b == NULL) b = ""; + str = malloc(strlen(a) + strlen(b) + 1); + memcpy(str, a, strlen(a)); + memcpy(str + strlen(a), b, strlen(b)); + str[strlen(a) + strlen(b)] = 0; + return str; +} + +char* cm_strcat3(const char* a, const char* b, const char* c) { + char* tmp = cm_strcat(a, b); + char* str = cm_strcat(tmp, c); + free(tmp); + return str; +} + +char* cm_strdup(const char* str) { return cm_strcat(str, ""); } + +bool cm_endswith(const char* str, const char* end) { + int i; + if(strlen(str) < strlen(end)) return false; + for(i = strlen(str) - strlen(end); i < strlen(str); i++) { + if(str[i] != end[i - strlen(str) + strlen(end)]) return false; + } + return true; +} + +bool cm_nocase_endswith(const char* str, const char* end) { + int i; + if(strlen(str) < strlen(end)) return false; + for(i = strlen(str) - strlen(end); i < strlen(str); i++) { + if(tolower(str[i]) != tolower(end[i - strlen(str) + strlen(end)])) return false; + } + return true; +} + +char* cm_trimstart(const char* str) { + int i; + for(i = 0; str[i] != 0; i++) { + if(str[i] != ' ' && str[i] != '\t') { + return cm_strdup(str + i); + } + } + return cm_strdup(""); +} + +char* cm_trimend(const char* str) { + char* s = cm_strdup(str); + int i; + for(i = strlen(s) - 1; i >= 0; i--) { + if(s[i] != '\t' && s[i] != ' ') { + s[i + 1] = 0; + break; + } + } + return s; +} + +char* cm_trim(const char* str) { + char* tmp = cm_trimstart(str); + char* s = cm_trimend(tmp); + free(tmp); + return s; +} + +char** cm_split(const char* str, const char* by) { + int i; + char** r = malloc(sizeof(*r)); + char* b = malloc(1); + char cbuf[2]; + bool dq = false; + bool sq = false; + r[0] = NULL; + b[0] = 0; + cbuf[1] = 0; + 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 { + char* tmp = b; + cbuf[0] = str[i]; + b = cm_strcat(tmp, cbuf); + free(tmp); + } + } + } + free(b); + return r; +} + +bool cm_strcaseequ(const char* a, const char* b) { + int i; + if(a == NULL) return false; + if(b == NULL) return false; + if(strlen(a) != strlen(b)) return false; + for(i = 0; a[i] != 0; i++) { + if(tolower(a[i]) != tolower(b[i])) return false; + } + return true; +} + +int cm_hex(const char* str, int len) { + int n = 0; + int i; + for(i = 0; i < len; i++) { + char c = str[i]; + n *= 16; + if('0' <= c && c <= '9') { + n += c - '0'; + } else if('a' <= c && c <= 'f') { + n += c - 'a' + 10; + } else if('A' <= c && c <= 'F') { + n += c - 'A' + 10; + } + } + return n; +} + +char* cm_html_escape(const char* str) { + int i; + char* result = malloc(1); + char cbuf[2]; + result[0] = 0; + cbuf[1] = 0; + for(i = 0; str[i] != 0; i++) { + cbuf[0] = str[i]; + if(str[i] == '&') { + char* tmp = result; + result = cm_strcat(tmp, "&"); + free(tmp); + } else if(str[i] == '<') { + char* tmp = result; + result = cm_strcat(tmp, "<"); + free(tmp); + } else if(str[i] == '>') { + char* tmp = result; + result = cm_strcat(tmp, ">"); + free(tmp); + } else { + char* tmp = result; + result = cm_strcat(tmp, cbuf); + free(tmp); + } + } + return result; +} + +char* cm_url_escape(const char* str) { + int i; + char* result = malloc(1); + char cbuf[2]; + result[0] = 0; + cbuf[1] = 0; + for(i = 0; str[i] != 0; i++) { + cbuf[0] = str[i]; + if('!' <= str[i] && str[i] <= '@' && str[i] != '.' && str[i] != '-' && str[i] != '/' && !('0' <= str[i] && str[i] <= '9')) { + char code[4]; + char* tmp = result; + sprintf(code, "%%%02X", str[i]); + result = cm_strcat(tmp, code); + free(tmp); + } else { + char* tmp = result; + result = cm_strcat(tmp, cbuf); + free(tmp); + } + } + return result; +} diff --git a/Makefile b/Makefile index bb53fec..6cd4790 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,6 @@ all: ./Common ./Server ./Client $(MAKE) -C $@ $(FLAGS) clean: - $(MAKE) -C ./Common clean - $(MAKE) -C ./Server clean - $(MAKE) -C ./Client clean + $(MAKE) -C ./Common clean $(FLAGS) + $(MAKE) -C ./Server clean $(FLAGS) + $(MAKE) -C ./Client clean $(FLAGS) diff --git a/Platform/generic.mk b/Platform/generic.mk index fbbab2d..3dfe007 100644 --- a/Platform/generic.mk +++ b/Platform/generic.mk @@ -1 +1,8 @@ # $Id$ + +CC = cc +AR = ar +CFLAGS = -I $(PWD)/Common -fPIC +LDFLAGS = +LIBS = +EXEC = diff --git a/Server/Makefile b/Server/Makefile index b9530bf..92cc9cb 100644 --- a/Server/Makefile +++ b/Server/Makefile @@ -1,3 +1,20 @@ # $Id$ include $(PWD)/Platform/$(PLATFORM).mk + +.PHONY: all clean +.SUFFIXES: .c .o + +OBJS = main.o +OBJS += ../Common/common.a + +all: rbuild-server$(EXEC) + +rbuild-server$(EXEC): $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o *.exe rbuild-server diff --git a/Server/main.c b/Server/main.c new file mode 100644 index 0000000..989daf6 --- /dev/null +++ b/Server/main.c @@ -0,0 +1,4 @@ +/* $Id$ */ + +int main(){ +}