From 38f90d7bd6669bd6f48be178669a6186e40b30de Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 20:36:14 +0100 Subject: Makefile: Use a more complete dependency graph Use the compiler to generate make-compatible dependency files and include them to ensure targets are recompiled when a header file changes. Also make objects depend on the Makefile explicitly to ensure objects are re-built when the makefile changes. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 242e93f..9176f4d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TARGET := stem SRCEXT := c SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) -CFLAGS := +CFLAGS := -MMD -MP LIB := -L lib -lm INC := -I include @@ -13,7 +13,7 @@ $(TARGET): $(OBJECTS) @echo " Linking..." @echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB) -O3 -$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) +$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile @echo " Building..." @mkdir -p $(BUILDDIR) @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< -save-temps -O3 @@ -33,3 +33,5 @@ doc: site: doxygen rsync -uvrP --delete-after "html/" root@nullring.xyz:/var/www/stemdoc + +-include $(OBJECTS:.o=.d) -- cgit From 476044b4947632ba2b03bc368a513cba55cb1103 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:04:36 +0100 Subject: Makefile: Add support for generating compile_flags.txt This helps tools like clangd understand where the header files are such that they can be used to navigate the codebase quickly and easily. --- .gitignore | 1 + Makefile | 3 +++ include/stem.h | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b9c9055..992f404 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tmp/ /latex/** stem compile_commands.json +compile_flags.txt diff --git a/Makefile b/Makefile index 9176f4d..9ee2833 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile @mkdir -p $(BUILDDIR) @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< -save-temps -O3 +compile_flags.txt: Makefile + printf "%s\n" $(CFLAGS) $(INC) >$@ + clean: @echo " Cleaning..."; @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) diff --git a/include/stem.h b/include/stem.h index f4aff54..06f7351 100644 --- a/include/stem.h +++ b/include/stem.h @@ -55,7 +55,7 @@ typedef struct PARSER_STRUCT { /*! @brief Index of current character */ int i; /*! @brief The current character */ - char c; + int c; } parser_t; /*! @brief This structure is to be used in singly linked lists that hold -- cgit From c4ee664d0b2f4e118106fdd49eb50d9fb3eaeee3 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:08:11 +0100 Subject: Don't check parser_t.c against EOF parser_t.c is a char which may be unsigned on some platforms and therefore incapable of holding EOF. This field is only ever set from parser_t.source which is a char array, which only ever originates from {main,strquote,include} -> parser_pp -> {init_parser,parser_reset} which all assign it from char arrays. This means it should never be EOF, so the check can be dropped. Also update the documentation so it matches. --- include/stem.h | 4 ++-- src/stem.c | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/stem.h b/include/stem.h index 06f7351..c467286 100644 --- a/include/stem.h +++ b/include/stem.h @@ -48,7 +48,7 @@ struct VALUE_STRUCT { /*! @brief Parser implementation directly parses without lexer */ /*! the parser data structure parses a string of valid stem code and - * returns a value until it reaches EOF or end of string. */ + * returns a value until it reaches end of string. */ typedef struct PARSER_STRUCT { /*! @brief The string that contains valid stem code. */ char *source; @@ -181,7 +181,7 @@ value_t *parse_word(parser_t *p); /*! Error in parsing strings can occur if wrong escape code. */ void parser_error(parser_t *p); -/*! Gets the next value_t from the string, returns NULL if EOF. */ +/*! Gets the next value_t from the string, returns NULL if end of string. */ value_t *parser_get_next(parser_t *p); /*! Allocates memory for new node struct. */ diff --git a/src/stem.c b/src/stem.c index 651d624..f623ae7 100644 --- a/src/stem.c +++ b/src/stem.c @@ -331,8 +331,6 @@ value_t *parser_get_next(parser_t *p) { return parse_quote(p); case '\0': return NULL; - case EOF: - return NULL; default: return parse_word(p); } -- cgit From 94f7d92631d87f968ffd559b2302aa1eb7cf840c Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:24:20 +0100 Subject: Initialise getdelim buf pointers to NULL getdelim can either be passed NULL or a malloc allocated buffer. I am not sure why on glibc on linux this doesn't outright crash, but it does crash on my ARM phone. By initialising to NULL, getdelim correctly allocates a buffer for the data rather than reallocating a string literal. --- src/builtins.c | 4 ++-- src/main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index caf18c2..d6049f3 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -540,7 +540,7 @@ void stemfread(value_t *v) { eval_error("EMPTY STACK"); return; } - char *val = ""; + char *val = NULL; size_t len = 0; FILE *fp = fopen(v1->str_word->value, "rb"); if (!fp) { @@ -1341,7 +1341,7 @@ void include(value_t *v) { eval_error("EMPTY STACK"); return; } - char *val = ""; + char *val = NULL; size_t len = 0; string_t *strval = init_string("/usr/local/share/stem/stemlib/"); string_concat(strval, v1->str_word); diff --git a/src/main.c b/src/main.c index de0abe7..2a6ed6b 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,7 @@ void sigint_handler(int signum) { int main(int argc, char **argv) { value_t *v; size_t len = 0; - char *buf = ""; + char *buf = NULL; /* Parsing arguments */ if (argc < 2) { -- cgit From 3f6e346cfb9cce3e24c27c400e345eccc34697d9 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:27:07 +0100 Subject: Use https for stemlib submodule. Using SSH requires the end-user has both a github account and an SSH key enrolled into it which may be inconvenient or impossible. Using https ensures the submodule can be cloned without needing to have a github account with a configured SSH key. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index cf2ae3c..0752188 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/jothepro/doxygen-awesome-css.git [submodule "stemlib"] path = stemlib - url = git@github.com:ret2pop/stemlib + url = https://github.com/ret2pop/stemlib.git -- cgit