diff --git a/Makefile b/Makefile index bd4f22a..ca8295a 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ all: build $(YAIT) build: mkdir -p bin -$(YAIT): $(YAIT_SRCS) - $(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@ +$(YAIT): $(YAIT_SRCS) config.mak + $(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $(YAIT_SRCS) -o $@ endif diff --git a/TODO b/TODO index 8e02fa0..15e1fd9 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ Todo: * Project formats * GNU * FASM - * POSIX * LIBRARY end of file TODO diff --git a/include/yait.h b/include/yait.h index 73f1971..7b46d3a 100644 --- a/include/yait.h +++ b/include/yait.h @@ -22,20 +22,9 @@ typedef struct { bool linenoise; } libmap_t; -typedef enum { - MIT, - GPL, - BSD, - UNL, -} licence_t; +typedef enum { MIT, GPL, BSD, UNL, _LICENCE_COUNT_ } licence_t; -typedef enum { - POSIX, - SIMPLE, - GNU, - LIBRARY, - FASM, -} style_t; +typedef enum { POSIX, SIMPLE, GNU, LIBRARY, FASM, _STYLE_COUNT_ } style_t; typedef struct { libmap_t libraries; diff --git a/src/create_project.c b/src/create_project.c index 8bd72d6..f3b28cd 100644 --- a/src/create_project.c +++ b/src/create_project.c @@ -6,51 +6,80 @@ * */ +#include #include #include +#include #include "../include/yait.h" #include "util.h" #include "contents.h" -char buffer[BUFSIZ]; +#define emit_progress_file \ + fprintf(stderr, "Created files %d\r", a); \ + a++ int create_project(manifest_t manifest) { - mkdir_p(manifest.project); - chdir(manifest.project); + int status, a = 1; + char buffer[BUFSIZ]; - if (manifest.style == SIMPLE) { - /* This only works if the source - files's root name is the same as the target on all of the Makefile becuase of how it checks for files. */ + status = mkdir_p(manifest.project); + if (status) + return 1; + + status = chdir(manifest.project); + if (status) + return 1; + + switch (manifest.style) { + case SIMPLE: cfprintf( "Makefile", ".POSIX:\nCC ::= gcc\nCFLAGS ::= -Wall --std=c23 -Wpedantic\n\nall: %s", manifest.project); - fprintf(stderr, "Created files 1\r"); + emit_progress_file; cfprintf("README", "%s", manifest.project); - fprintf(stderr, "Created files 2\r"); + emit_progress_file; snprintf(buffer, BUFSIZ, "%s.c", manifest.project); cfprintf(buffer, ""); - fputs("Created files 3, done.\n", stderr); - /* We exit early because the simple flag is an overridding flag. */ - return 0; + fprintf(stderr, "Created files %d, done.\n", a); + break; + + case POSIX: + cfprintf("Makefile", ""); + cfprintf("configure", configure); + cfprintf(".clang-format", ""); + cfprintf("README", readme, manifest.name); + cfprintf("src/main.c", ""); + + snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project); + cfprintf(buffer, ""); + + snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project); + cfprintf(buffer, ".\\\" %s.1 - Manual page for %s", + manifest.project, manifest.project); + + cfprintf("doc/WHATNEXT", what_next); + break; + case FASM: + snprintf(buffer, BUFSIZ, "%s.txt", manifest.project); + for (int i = 0; buffer[i] != '\0'; ++i) + buffer[i] = toupper((unsigned char)buffer[i]); + cfprintf( + buffer, + ""); + cfprintf( + "SOURCE/main.c", + "#include \n\nint main() {\n\tputs(\"Hei!\");\n\treturn 0;\n}"); + cfprintf("TOOLS/build.sh", + "#!/bin/sh\n\ncc SOURCE/main.c -o %s", + manifest.project); + break; + default: + abort(); } - cfprintf("Makefile", ""); - cfprintf("configure", configure); - cfprintf(".clang-format", ""); - cfprintf("README", readme, manifest.name); - cfprintf("src/main.c", ""); - - snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project); - cfprintf(buffer, ""); - - snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project); - cfprintf(buffer, ""); - - cfprintf("doc/WHATNEXT", what_next); - return 0; } diff --git a/src/main.c b/src/main.c index ad4ffd9..aa6c0dc 100644 --- a/src/main.c +++ b/src/main.c @@ -24,15 +24,6 @@ #define print_option(option, description) \ printf(" %-20s %-20s\n", option, description) -char *str_dup(char *s) -{ - char *new = malloc(strlen(s) + 1); - if (!new) - return NULL; - strcpy(new, s); - return new; -} - static void usage(int status) { if (status != 0) { @@ -46,8 +37,10 @@ static void usage(int status) puts("Mandatory arguments to long options are mandatory for short options too"); print_option("--no-git", "Do not inititize git reposity"); print_option("--clang", "Add clang-format files and tooling"); - print_option("-L ", "Set licence"); - print_option("-l ", "Add a library"); + print_option("-L ", + "Set licence. This list can be found by passing 'list'"); + print_option("-l ", + "Add a library. This list can be found by passing 'list'"); print_option("-n ", "Set the name of the project"); print_option( "--style=