diff --git a/code/entry_windows.c b/code/entry_windows.c index 3ceac60..a457d5c 100644 --- a/code/entry_windows.c +++ b/code/entry_windows.c @@ -1,6 +1,5 @@ - -#include<_platform.h> -#include +#include <_platform.h> +#include extern int main(); diff --git a/code/string.c b/code/string.c index 349467b..ca2a99c 100644 --- a/code/string.c +++ b/code/string.c @@ -1,10 +1,57 @@ +#include -int strcmp(const char *s1, const char *s2) -{ - while(*s1 != 0 && *s2 != 0) { - if(*s1 != *s2) break; +void *memcpy(void *restrict s1, const void *restrict s2, size_t n) { + const unsigned char *restrict c2 = s2; + unsigned char *restrict c1 = s1; + + while (n--) { + *c1++ = *c2++; + } + return s1; +} + +int memcmp(const void *s1, const void *s2, size_t n) { + const unsigned char *u1 = s1; + const unsigned char *u2 = s2; + + for (; n--; u1++, u2++) { + if (*u1 != *u2) return *u1 - *u2; } - if(*s1 > *s2) return 1; - if(*s1 < *s2) return -1; + return 0; } + +void *memset(void *s, int c, size_t n) { + unsigned char *restrict buf = s; + while (n--) { + *buf++ = c; + } + return s; +} + +int strcmp(const char *s1, const char *s2) { + while (*s1 != 0 && *s2 != 0) { + if (*s1 != *s2) break; + } + + if(*s1 > *s2) return 1; + if(*s1 < *s2) return -1; + return 0; +} + +size_t strlen(const char *s) { + size_t i = 0; + while (s[i]) { + i++; + } + return i; +} + +// __STDC_WANT_LIB_EXT1__ +size_t strnlen_s(const char *s, size_t maxsize) { + size_t i = 0; + while (s[i] && i < maxsize) { + i++; + } + return i; +} diff --git a/inc/string.h b/inc/string.h index eef4a5d..45b2c87 100644 --- a/inc/string.h +++ b/inc/string.h @@ -24,18 +24,15 @@ char *strerror(int errnum); size_t strlen(const char *s); #if __STDC_WANT_LIB_EXT1__ - errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n); - errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n); - errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2); - errno_t strncpy_s(char * restrict s1, rsize_t s1max, - const char * restrict s2, rsize_t n); - errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2); - errno_t strncat_s(char * restrict s1, rsize_t s1max, - const char * restrict s2, rsize_t n); - char *strtok_s(char * restrict s1, rsize_t * restrict s1max, - const char * restrict s2, char ** restrict ptr); - errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n); - errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum); - size_t strerrorlen_s(errno_t errnum); - size_t strnlen_s(const char *s, size_t maxsize); -#endif \ No newline at end of file +errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n); +errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n); +errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2); +errno_t strncpy_s(char * restrict s1, rsize_t s1max,const char * restrict s2, rsize_t n); +errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2); +errno_t strncat_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n); +char *strtok_s(char * restrict s1, rsize_t * restrict s1max, const char * restrict s2, char ** restrict ptr); +errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n); +errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum); +size_t strerrorlen_s(errno_t errnum); +size_t strnlen_s(const char *s, size_t maxsize); +#endif diff --git a/makefile b/makefile index 833f0d3..7429823 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ -GNUFLAGS=-Werror -Wall -Iinc -Icode -CLFLAGS=/I:inc /link /incremental:no /subsystem:windows /nodefaultlib kernel32.lib +GNUFLAGS=-g -gcodeview -Werror -Wall -Iinc -Icode +CLFLAGS=/Zi /I:inc /link /incremental:no /subsystem:windows /nodefaultlib kernel32.lib CC=clang CFLAGS=$(GNUFLAGS) diff --git a/project.4coder b/project.4coder new file mode 100644 index 0000000..03c29c1 --- /dev/null +++ b/project.4coder @@ -0,0 +1,63 @@ +version(1); + +project_name = "Ciabatta"; + +patterns = { + "*.c", + "*.cpp", + "*.ds", + "*.h", + "*.bat", + "*.vert", + "*.frag", + "*.geom", + "*.sh", + "*.4coder", +}; + +blacklist_patterns = { + ".*", +}; + +load_paths = { + { + { {"."}, .recursive = true, .relative = true }, .os = "win" + }, +}; + +command_list = { + { + .name = "build", + .out = "*compilation*", + .footer_panel = true, + .save_dirty_files = true, + .cursor_at_end = true, + .cmd = { + { "make", .os = "win" }, + }, + }, + { + .name = "bake", + .out = "*compilation*", + .footer_panel = true, + .save_dirty_files = true, + .cursor_at_end = true, + .cmd = { + { "test\\bake.bat", .os = "win" }, + }, + }, + { + .name = "debug", + .out = "*compilation*", + .footer_panel = true, + .save_dirty_files = true, + .cursor_at_end = true, + .cmd = { + { "remedybg.exe test.rdbg", .os = "win" }, + }, + }, +}; + +fkey_command[1] = "build"; +fkey_command[2] = "bake"; +fkey_command[3] = "debug"; diff --git a/test/bake.bat b/test/bake.bat index 3f407e7..4e42cc8 100644 --- a/test/bake.bat +++ b/test/bake.bat @@ -6,10 +6,10 @@ inctoarg > temp set /P includes= -#include +#include +#include -int main() -{ +int main() { char *include = getenv("INCLUDE"); printf(" "); - while(*include != 0) { + while (*include != 0) { printf("-I \""); - while(*include != ';' && *include != 0) { + while (*include != ';' && *include != 0) { if (*include == '\\') { printf("/"); } else { @@ -15,7 +14,7 @@ int main() } *include++; } - if(*include == ';') { + if (*include == ';') { ++include; } printf("\" "); diff --git a/test/test.c b/test/test.c index b41e98f..8fe2724 100644 --- a/test/test.c +++ b/test/test.c @@ -1,10 +1,9 @@ - #include #include -int main() -{ - for(char c = 'a'; c != 'z'; ++c) { - assert(isupper(toupper(c))); + +int main(void) { + for (char c = 'a'; c != 'z'; ++c) { + assert(isupper(toupper(c))); } return 0; -} \ No newline at end of file +}