From 2e1ccff01cf89539b621ac786898229307847f4b Mon Sep 17 00:00:00 2001 From: thing 1 Date: Thu, 14 Nov 2024 08:11:18 +0000 Subject: made too many changes to note --- comp/lucas-standen-NEA/code2/Makefile | 37 +++++++++---------- comp/lucas-standen-NEA/code2/Makefile.new | 25 +++++++++++++ comp/lucas-standen-NEA/code2/fileread.c | 41 +++++++++++++++++++++ comp/lucas-standen-NEA/code2/fileread.h | 13 +++++++ comp/lucas-standen-NEA/code2/parser.c | 41 --------------------- comp/lucas-standen-NEA/code2/parser.h | 13 ------- comp/lucas-standen-NEA/code2/stdlib/Makefile | 28 ++++++++------ .../lucas-standen-NEA/code2/stdlib/String/String.c | 6 +-- comp/lucas-standen-NEA/code2/stdlib/zpylib.c | 2 +- comp/lucas-standen-NEA/code2/zpy | Bin 0 -> 22360 bytes comp/lucas-standen-NEA/code2/zpy.c | 4 +- 11 files changed, 120 insertions(+), 90 deletions(-) create mode 100644 comp/lucas-standen-NEA/code2/Makefile.new create mode 100644 comp/lucas-standen-NEA/code2/fileread.c create mode 100644 comp/lucas-standen-NEA/code2/fileread.h delete mode 100644 comp/lucas-standen-NEA/code2/parser.c delete mode 100644 comp/lucas-standen-NEA/code2/parser.h create mode 100755 comp/lucas-standen-NEA/code2/zpy (limited to 'comp/lucas-standen-NEA/code2') diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile index cfd4254..e01a111 100644 --- a/comp/lucas-standen-NEA/code2/Makefile +++ b/comp/lucas-standen-NEA/code2/Makefile @@ -1,26 +1,25 @@ -CC = cc -CFLAGS =-O3 +CC=cc +CFLAGS=-O3 -zpy: zpy.c comp.c parser.c tokenizer.c util.c - ${CC} *.c -c ${CFLAGS} - ${CC} *.o -o zpy ${CFLAGS} - cd stdlib && make -clean: - rm -rf zpy *.o *.core sample out stdlib/*.o - cd stdlib && make clean - cd examples && make clean +SRC = zpy.c comp.c tokenizer.c fileread.c util.c appendsnprintf.c +OBJ = ${SRC:.c=.o} -install: zpy - mkdir -p /usr/local/share/zpylib - mkdir -p /usr/local/share/zpylib/include - cp ./zpy /usr/local/bin/zpy +all: zpy +.c.o: + ${CC} -c ${CFLAGS} $< +zpy: ${OBJ} + ${CC} -o $@ ${OBJ} + cd stdlib && make +install: all + cp zpy /usr/local/bin/zpy cd stdlib && make install cd zpypkg && make install - -example: zpy - cd examples && make - +clean: + rm -rf zpy*.o + cd stdlib && make clean + cd examples && make clean uninstall: rm /usr/local/bin/zpy - rm -rf /usr/local/share/zpylib + +.PHONY: all clean install uninstall diff --git a/comp/lucas-standen-NEA/code2/Makefile.new b/comp/lucas-standen-NEA/code2/Makefile.new new file mode 100644 index 0000000..8dcb4db --- /dev/null +++ b/comp/lucas-standen-NEA/code2/Makefile.new @@ -0,0 +1,25 @@ +CC=cc +CFLAGS=-O3 + +SRC = zpy.c comp.c tokenizer.c fileread.c util.c appendsnprintf.c +OBJ = ${SRC:.c=.o} + +all: zpy + +.c.o: + ${CC} -c ${CFLAGS} $< +zpy: ${OBJ} + ${CC} -o $@ ${OBJ} + cd stdlib && make +install: all + cp zpy /usr/local/bin/zpy + cd stdlib && make install + cd zpypkg && make install +clean: + rm -rf zpy*.o + cd stdlib && make clean + cd examples && make clean +uninstall: + rm /usr/local/bin/zpy + +.PHONY: all clean install uninstall diff --git a/comp/lucas-standen-NEA/code2/fileread.c b/comp/lucas-standen-NEA/code2/fileread.c new file mode 100644 index 0000000..0bfc497 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/fileread.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include "util.h" + +typedef struct strings { + char **strs; + int count; +} strings; + +//# counts the number of times c ocurrs in s +int countChars(char *s, char c){ + int count = 0; + for (int i = 0; i < strlen(s); i++){ + if (s[i] == c) count++; + } + return count; +} + +//# returns an array of strings (type strings) of the file contents, split by line +strings *fileread(FILE *f){ + strings *strs = malloc(sizeof(strings)); + strs->strs = malloc(sizeof(char **)); + + char *line = alloca(256); + int count = 0; + while (fgets(line, 256, f) != NULL){ + if (line[0] != '\n' && line[0] != '/'){ + while (line[0] == '\t') line++; + line[strlen(line)-1] = '\0'; + strs->strs[count] = malloc(256); + memcpy(strs->strs[count], line, 256); + count++; + } + } + strs->count = count; + + return strs; +} diff --git a/comp/lucas-standen-NEA/code2/fileread.h b/comp/lucas-standen-NEA/code2/fileread.h new file mode 100644 index 0000000..fe47f25 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/fileread.h @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +#include "util.h" + +typedef struct strings { + char **strs; + int count; +} strings; + +strings *fileread(FILE *f); diff --git a/comp/lucas-standen-NEA/code2/parser.c b/comp/lucas-standen-NEA/code2/parser.c deleted file mode 100644 index a84291b..0000000 --- a/comp/lucas-standen-NEA/code2/parser.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include - -#include "util.h" - -typedef struct strings { - char **strs; - int count; -} strings; - -//# counts the number of times c ocurrs in s -int countChars(char *s, char c){ - int count = 0; - for (int i = 0; i < strlen(s); i++){ - if (s[i] == c) count++; - } - return count; -} - -//# returns an array of strings (type strings) of the file contents, split by line -strings *parse(FILE *f){ - strings *strs = malloc(sizeof(strings)); - strs->strs = malloc(sizeof(char **)); - - char *line = alloca(256); - int count = 0; - while (fgets(line, 256, f) != NULL){ - if (line[0] != '\n' && line[0] != '/'){ - while (line[0] == '\t') line++; - line[strlen(line)-1] = '\0'; - strs->strs[count] = malloc(256); - memcpy(strs->strs[count], line, 256); - count++; - } - } - strs->count = count; - - return strs; -} diff --git a/comp/lucas-standen-NEA/code2/parser.h b/comp/lucas-standen-NEA/code2/parser.h deleted file mode 100644 index 80a5f08..0000000 --- a/comp/lucas-standen-NEA/code2/parser.h +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -#include "util.h" - -typedef struct strings { - char **strs; - int count; -} strings; - -strings *parse(FILE *f); diff --git a/comp/lucas-standen-NEA/code2/stdlib/Makefile b/comp/lucas-standen-NEA/code2/stdlib/Makefile index 9d4bfd6..c69992c 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/Makefile +++ b/comp/lucas-standen-NEA/code2/stdlib/Makefile @@ -1,17 +1,23 @@ CC=cc CFLAGS=-O3 -stdlib: - cd String && make - ${CC} zpylib.c -c -o zpylib.o ${CFLAGS} +SRC = zpylib.c +OBJ = ${SRC:.c=.o} -clean: - rm -rf *.o - cd String && make clean +all: zpy -install: - cp *.o /usr/local/share/zpylib/ - cp *.h /usr/local/share/zpylib/include/ - cp String/String.o /usr/local/share/zpylib - cp String/String.h /usr/local/share/zpylib/include +.c.o: + ${CC} -c ${CFLAGS} $< + cd String && make +install: all + cp zpy /usr/local/bin/zpy + cd stdlib && make install + cd zpypkg && make install +clean: + rm -rf zpy*.o + cd stdlib && make clean + cd examples && make clean +uninstall: + rm /usr/local/bin/zpy +.PHONY: all clean install uninstall diff --git a/comp/lucas-standen-NEA/code2/stdlib/String/String.c b/comp/lucas-standen-NEA/code2/stdlib/String/String.c index 6f11119..c273351 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/String/String.c +++ b/comp/lucas-standen-NEA/code2/stdlib/String/String.c @@ -16,7 +16,7 @@ void __stringprint(string *self){ } void __stringinput(string *self, size_t len){ - char *tmp = calloc(0, len); + char *tmp = calloc(1, len); fgets(tmp, len, stdin); self->fromcstring(self, tmp); } @@ -109,7 +109,7 @@ string **__stringsplit(string *self, char delim){ int j = 0; for (int i = 0; i < splitcount; i++){ - char *str = calloc(0, self->_len); + char *str = calloc(1, self->_len); int charcount = 0; for (; self->_str[j] != delim && j < self->_len; j++){ str[charcount] = self->_str[j]; @@ -129,7 +129,7 @@ string *String(char *cstring){ // returns an allocated String from a C string in size_t len = strlen(cstring); string *str = malloc(sizeof(string)); - str->_str = calloc(0, len); + str->_str = calloc(1, len); memcpy(str->_str, cstring, len); str->_len = len; diff --git a/comp/lucas-standen-NEA/code2/stdlib/zpylib.c b/comp/lucas-standen-NEA/code2/stdlib/zpylib.c index 86f0dc3..7b512dd 100644 --- a/comp/lucas-standen-NEA/code2/stdlib/zpylib.c +++ b/comp/lucas-standen-NEA/code2/stdlib/zpylib.c @@ -21,7 +21,7 @@ void printfloat(double f){ } char *readstr(){ - char *str = calloc(0, 256); + char *str = calloc(1, 256); fgets(str, 256, stdin); return str; } diff --git a/comp/lucas-standen-NEA/code2/zpy b/comp/lucas-standen-NEA/code2/zpy new file mode 100755 index 0000000..85eb8a2 Binary files /dev/null and b/comp/lucas-standen-NEA/code2/zpy differ diff --git a/comp/lucas-standen-NEA/code2/zpy.c b/comp/lucas-standen-NEA/code2/zpy.c index b96615b..65fd7ae 100644 --- a/comp/lucas-standen-NEA/code2/zpy.c +++ b/comp/lucas-standen-NEA/code2/zpy.c @@ -3,7 +3,7 @@ #include #include "util.h" -#include "parser.h" +#include "fileread.h" #include "comp.h" #include "appendsnprintf.h" @@ -61,7 +61,7 @@ int main(int argc, char **argv){ if (fout == NULL) die("no such file or directory"); - strings *stringTokens = parse(f); + strings *stringTokens = fileread(f); if (stringTokens == NULL) die("couldn't parse file, is it formated properly?"); -- cgit v1.2.3