From 2abf5178e4957c18ee9f83490eff5e4135199ff1 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 31 Mar 2025 17:05:36 +0300 Subject: Some style improvments - Rename readfile to allocfile (as it actually contains cccl_allocfile function) - Add cccl_ prefix for functions defined in str.c --- Makefile | 2 +- allocfile.c | 19 +++++++++++++++++++ cccl.h | 6 +++--- executor.c | 4 ++-- parser.c | 2 +- readfile.c | 19 ------------------- str.c | 6 +++--- 7 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 allocfile.c delete mode 100644 readfile.c diff --git a/Makefile b/Makefile index 0f5e2f3..ca51ad7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ +OBJS += allocfile.o OBJS += cccl.o OBJS += executor.o OBJS += main.o OBJS += parser.o -OBJS += readfile.o OBJS += str.o OBJS += tokenizer.o diff --git a/allocfile.c b/allocfile.c new file mode 100644 index 0000000..d4d17f8 --- /dev/null +++ b/allocfile.c @@ -0,0 +1,19 @@ +#include "cccl.h" + +#include + +#include + + +int cccl_allocfile(const char *path, struct cccl_File *file) +{ + struct stat st; + int err = stat(path, &st); + if (err) + return err; + + file->size = st.st_size; + file->buffer = malloc(file->size); + + return !file->buffer; +} diff --git a/cccl.h b/cccl.h index eb08298..de67e5e 100644 --- a/cccl.h +++ b/cccl.h @@ -101,8 +101,8 @@ struct cccl_Node *cccl_parse(struct cccl_Token tokens[], size_t tokens_length, e enum cccl_ExecutorStatus cccl_execute(struct cccl_Node *code, struct cccl_Variables *scope, size_t depth); void cccl_dump(FILE *f); -const char *strtoken(enum cccl_TokenType type); -const char *strnode(enum cccl_NodeType type); -const char *strstatus(enum cccl_ExecutorStatus status); +const char *cccl_strtoken(enum cccl_TokenType type); +const char *cccl_strnode(enum cccl_NodeType type); +const char *cccl_strstatus(enum cccl_ExecutorStatus status); #endif /* __CCCL_H__ */ diff --git a/executor.c b/executor.c index 144ad2c..e748a8c 100644 --- a/executor.c +++ b/executor.c @@ -72,9 +72,9 @@ enum cccl_ExecutorStatus cccl_execute(struct cccl_Node *code, struct cccl_Variab { if (verbose) if (code->value) - fprintf(stderr, "Executing %s with %d [%c], %lu nodes, depth %lu\n", strnode(code->type), code->value, code->value, code->in_length, depth); + fprintf(stderr, "Executing %s with %d [%c], %lu nodes, depth %lu\n", cccl_strnode(code->type), code->value, code->value, code->in_length, depth); else - fprintf(stderr, "Executing %s, %lu nodes, depth %lu\n", strnode(code->type), code->in_length, depth); + fprintf(stderr, "Executing %s, %lu nodes, depth %lu\n", cccl_strnode(code->type), code->in_length, depth); if (interactive) { ssize_t length = getline(&line.buf, &line.length, stdin); diff --git a/parser.c b/parser.c index 126d716..09f0f34 100644 --- a/parser.c +++ b/parser.c @@ -55,7 +55,7 @@ struct cccl_Node *cccl_parse(struct cccl_Token tokens[], size_t tokens_length, e for (size_t i = 0; i < tokens_length; ++i) { if (verbose) - fprintf(stderr, "T:[%c:%s] ", tokens[i].value, strtoken(tokens[i].type)); + fprintf(stderr, "T:[%c:%s] ", tokens[i].value, cccl_strtoken(tokens[i].type)); switch (tokens[i].type) { case cccl_Token_COMMAND: case cccl_Token_COMMANDWITHARG: case cccl_Token_BLOCKSTART: diff --git a/readfile.c b/readfile.c deleted file mode 100644 index d4d17f8..0000000 --- a/readfile.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "cccl.h" - -#include - -#include - - -int cccl_allocfile(const char *path, struct cccl_File *file) -{ - struct stat st; - int err = stat(path, &st); - if (err) - return err; - - file->size = st.st_size; - file->buffer = malloc(file->size); - - return !file->buffer; -} diff --git a/str.c b/str.c index a8d85bd..4ea84b3 100644 --- a/str.c +++ b/str.c @@ -3,7 +3,7 @@ #include -const char *strtoken(enum cccl_TokenType type) +const char *cccl_strtoken(enum cccl_TokenType type) { switch (type) { @@ -16,7 +16,7 @@ const char *strtoken(enum cccl_TokenType type) return NULL; } -const char *strnode(enum cccl_NodeType type) +const char *cccl_strnode(enum cccl_NodeType type) { switch (type) { @@ -44,7 +44,7 @@ const char *strnode(enum cccl_NodeType type) return NULL; } -const char *strstatus(enum cccl_ExecutorStatus status) +const char *cccl_strstatus(enum cccl_ExecutorStatus status) { switch (status) { -- cgit 1.4.1