]> Nishi Git Mirror - rbuild.git/commitdiff
stuff
authorNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 14:16:36 +0000 (14:16 +0000)
committerNishi <nishi@nishi.boats>
Fri, 11 Oct 2024 14:16:36 +0000 (14:16 +0000)
git-svn-id: file:///raid/svn-personal/rbuild/trunk@4 c68d3453-7f82-0740-9748-1d72386a946b

Client/Makefile
Client/main.c [new file with mode: 0644]
Common/Makefile
Common/cm_string.h [new file with mode: 0644]
Common/string.c [new file with mode: 0644]
Makefile
Platform/generic.mk
Server/Makefile
Server/main.c [new file with mode: 0644]

index b9530bf7fd0c57fa01a42a63e2aba6718ec9cde8..be2d12d9222e0d149739b466b1c9071ef54afc04 100644 (file)
@@ -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 (file)
index 0000000..989daf6
--- /dev/null
@@ -0,0 +1,4 @@
+/* $Id$ */
+
+int main(){
+}
index b9530bf7fd0c57fa01a42a63e2aba6718ec9cde8..a97c433571c7cea53c26a30b73fb2ec39fd17e0e 100644 (file)
@@ -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 (file)
index 0000000..0132139
--- /dev/null
@@ -0,0 +1,22 @@
+/* $Id$ */
+
+#ifndef __CM_STRING_H__
+#define __CM_STRING_H__
+
+#include <stdbool.h>
+
+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 (file)
index 0000000..f138160
--- /dev/null
@@ -0,0 +1,205 @@
+/* $Id$ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <ctype.h>
+
+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, "&amp;");
+                       free(tmp);
+               } else if(str[i] == '<') {
+                       char* tmp = result;
+                       result = cm_strcat(tmp, "&lt;");
+                       free(tmp);
+               } else if(str[i] == '>') {
+                       char* tmp = result;
+                       result = cm_strcat(tmp, "&gt;");
+                       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;
+}
index bb53fecd19c17575e2cf0cfc53036c06e76a238a..6cd4790d94a02aaa3b14bb5348fa19f5bc9386b6 100644 (file)
--- 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)
index fbbab2d1199b1de168c7f25fb5e7eac727b3d066..3dfe0071ef481833ceaac2da84597d562510d4eb 100644 (file)
@@ -1 +1,8 @@
 # $Id$
+
+CC = cc
+AR = ar
+CFLAGS = -I $(PWD)/Common -fPIC
+LDFLAGS =
+LIBS =
+EXEC =
index b9530bf7fd0c57fa01a42a63e2aba6718ec9cde8..92cc9cbf44f49885f7cc4d8fc8866620a4883352 100644 (file)
@@ -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 (file)
index 0000000..989daf6
--- /dev/null
@@ -0,0 +1,4 @@
+/* $Id$ */
+
+int main(){
+}