diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Maakbestand | 7 | ||||
-rw-r--r-- | main.c | 32 | ||||
-rw-r--r-- | src/waar.c | 12 |
4 files changed, 49 insertions, 3 deletions
@@ -1,3 +1,4 @@ drukkedoos obj/ .ccls-cache/ +compile_commands.json diff --git a/Maakbestand b/Maakbestand index e760b65..98e0798 100644 --- a/Maakbestand +++ b/Maakbestand @@ -1,5 +1,5 @@ CC := gcc -CFLAGS := -Wall -Wextra -std=c11 -O2 +CFLAGS := -Wall -Wextra -std=c2x -O2 LDFLAGS := OBJDIR := obj @@ -9,6 +9,8 @@ SOURCES := $(shell find src -type f -name '*.c') HEADERS := $(shell find src -type f -name '*.h') OBJECTS := $(patsubst src/%.c,obj/%.o,$(SOURCES)) +PROGNAMES_X := $(patsubst src/%.c,X(%),$(wildcard src/*.c)) + .PHONY: all clean all: $(TARGET) @@ -17,7 +19,8 @@ clean: rm -rf $(OBJDIR) $(TARGET) $(TARGET): main.c $(OBJECTS) - $(CC) -o $@ $^ $(LDFLAGS) + $(CC) -o $@ $^ $(LDFLAGS) -DPROGNAMES_XLIST="$(PROGNAMES_X)" $(OBJECTS): obj/%.o: src/%.c $(HEADERS) + @mkdir -p $(dir $@) $(CC) $(CFLAGS) -c -o $@ $< @@ -1,5 +1,35 @@ #include <stdio.h> +#include <string.h> + +#define X(name) int entry_ ## name (int argc, char **argv); +PROGNAMES_XLIST +#undef X + +static char* basename(char *path) { + size_t len = strlen(path); + for (size_t i = len - 1; i != 0; i--) { + if (path[i] == '/') return path + (i + 1); + } + return path; +} int main(int argc, char **argv) { - fprintf(stderr, "Drukkedoos moet nog geïmplementeerd worden\n"); + const char *prognamearg = basename(argv[0]); + + if (strcmp(prognamearg, "drukkedoos") == 0) { + argv++; + argc--; + if (argc == 0) { + fprintf(stderr, "Gebruik: drukkedoos <commando>\n"); + return 1; + } + prognamearg = basename(argv[0]); + } + +#define X(name) if (strcmp(argv[0], #name) == 0) return entry_ ## name (argc, argv); +PROGNAMES_XLIST +#undef X + + fprintf(stderr, "Onbekend hulpmiddel: '%s'\n", prognamearg); + return 1; } diff --git a/src/waar.c b/src/waar.c new file mode 100644 index 0000000..6fa570c --- /dev/null +++ b/src/waar.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include <string.h> + +int entry_waar(int argc, char **argv) { + if (argc == 2 && strcmp(argv[1], "-h") == 0) { + fprintf(stderr, "Gebruik: waar\n" + "\n" + "Geeft waarheid terug.\n"); + return 0; + } + return 0; +} |