From 13b15cb07fbebb040b76ca983e4b81d530dac270 Mon Sep 17 00:00:00 2001 From: vx-clutch Date: Fri, 29 Aug 2025 16:26:36 -0400 Subject: [PATCH] save --- .clangd | 7 +- TODO | 22 +---- include/yait.h | 45 ++++----- src/create_project.c | 165 +------------------------------ src/library_contents.h | 40 -------- src/main.c | 178 ++++++++++++++++++++++------------ src/posix_contents.h | 215 ----------------------------------------- src/util.c | 41 ++++---- src/util.h | 2 +- tools/Cleanup | 1 + 10 files changed, 166 insertions(+), 550 deletions(-) delete mode 100644 src/library_contents.h delete mode 100644 src/posix_contents.h diff --git a/.clangd b/.clangd index 2dc4053..8d250ad 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,7 @@ CompileFlags: - Add: ["--std=c2x", "-xc"] + Add: [-std=c23] + +Diagnostics: + ClangTidy: + Add: [clang-diagnostic-*] + Remove: [] diff --git a/TODO b/TODO index 0d27e6f..73a88a4 100644 --- a/TODO +++ b/TODO @@ -1,26 +1,6 @@ VX yait - TODO Todo: - * Rework interface - > git (default) - > no-git - > lib - # create AS library - > both - > autotools - > cmake - > make (default) - > bare - > flat - # everything in root - > licence|l - > author - * extra - > extra-build - # extra-build=nob - > extra-tools - # extra-tools=format - # extra-tools=Cleanup - * write touprstr() + Vi er Ferdig! end of file TODO diff --git a/include/yait.h b/include/yait.h index 6f9948d..c739b62 100644 --- a/include/yait.h +++ b/include/yait.h @@ -9,39 +9,30 @@ #ifndef YAIT_H #define YAIT_H -typedef struct { - bool git; - bool clang; - bool editor; -} flag_t; - -typedef struct { - bool nob; - bool format; - bool cleanup; -} extras_t; - -typedef struct { - bool ncurses; - bool raylib; - bool stb; - bool uthash; - bool linenoise; -} libmap_t; - typedef enum { MIT, GPL, BSD, UNL, _LICENCE_COUNT_ } licence_t; -typedef enum { POSIX, SIMPLE, GNU, LIBRARY, FASM, _STYLE_COUNT_ } style_t; - typedef struct { - libmap_t libraries; licence_t licence; - flag_t flags; - extras_t extras; - style_t style; + + bool lib; + bool exe; + + bool git; + bool autotools; + bool cmake; + bool make; + bool bare; + bool flat; + bool open_editor; + + struct { + bool nob; + bool clang_format; + bool Cleanup; + } extra; char *project; - char *name; + char *author; char *editor; } manifest_t; diff --git a/src/create_project.c b/src/create_project.c index 8b1f188..4dbd103 100644 --- a/src/create_project.c +++ b/src/create_project.c @@ -8,15 +8,11 @@ #include #include -#include #include #include #include -#include #include "../include/yait.h" -#include "posix_contents.h" -#include "library_contents.h" #include "licences/licences.h" #include "util.h" @@ -33,162 +29,7 @@ int create_project(manifest_t manifest) if (status) return 1; - switch (manifest.style) { - case SIMPLE: - cfprintf( - "Makefile", - ".POSIX:\nCC ::= gcc\nCFLAGS ::= -Wall --std=c23 -Wpedantic\n\nall: %s", - manifest.project); - cfprintf("README", "%s", manifest.project); - - snprintf(buffer, BUFSIZ, "%s.c", manifest.project); - - flast = true; - cfprintf(buffer, ""); - - snprintf(buffer, BUFSIZ, "%s.c", manifest.project); - main_source = str_dup(buffer); - 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); - - flast = true; - cfprintf("doc/WHATNEXT", what_next); - - fprintf(stderr, "Changing permissions 1"); - if (chmod("configure", 0755) == -1) { - fprintf(stderr, "\n"); - perror("chmod"); - return 1; - } - fprintf(stderr, ", done.\n"); - - main_source = "src/main.c"; - 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(\"Who's that behind you?\");\n\treturn 0;\n}"); - flast = true; - cfprintf("TOOLS/build.sh", - "#!/bin/sh\n\ncc SOURCE/main.c -o %s", - manifest.project); - - fprintf(stderr, "Changing permissions 1"); - if (chmod("TOOLS/build.sh", 0755) == -1) { - fprintf(stderr, "\n"); - perror("chmod"); - return 1; - } - fprintf(stderr, ", done.\n"); - - main_source = "SOURCE/main.c"; - break; - case GNU: - cfprintf("AUTHORS", "%s", manifest.name); - cfprintf("INSTALL", - "autoreconf -i\n./configure\nmake\nmake install"); - cfprintf("COPYING", "%s", "(undefined)"); - - cfprintf( - "NEWS", - "%s (0.1) unstable; urgency=low\n\n * Initial release. It compiles!\n - Nothing else.\n", - manifest.project); - cfprintf( - "README", - "This is the README file for the %s distribution.\n %s does a thing.", - manifest.project, manifest.project); - cfprintf( - "configure.ac", - "AC_INIT([%s], [0.1], [you@example.com])\nAM_INIT_AUTOMAKE([-Wall -Wextra foreign])\nAC_PROG_CC\nAC_CONFIG_FILES([Makefile src/Makefile man/Makefile])\nAC_OUTPUT"); - cfprintf( - "src/main.c", - "#include \n\nint main(void) {\n\tputs(\"Who's that behind you?\");\n\treturn 0;\n}"); - - time_t t = time(NULL); - struct tm tm_info = *localtime(&t); - char date[11]; - strftime(date, sizeof(date), "%Y-%m-%d", &tm_info); - - snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project); - flast = true; - cfprintf( - buffer, - ".TH %s 1 \"%s\" \"0.1\" \"User Commands\"\n.SH NAME\n%s \\- a program that does a thing\n.SH SYNOPSIS\n.B %s\n.SH DESCRIPTION\nThis is a program that does a thing.\n.SH AUTHOR\nWritten by %s.", - manifest.project, date, manifest.project, - manifest.project, manifest.name); - - main_source = "src/main.c"; - break; - case LIBRARY: - snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project); - char *file_name_buffer = str_dup(buffer); - - snprintf(buffer, BUFSIZ, "%s", manifest.project); - for (int i = 0; buffer[i] != '\0'; ++i) - buffer[i] = toupper((unsigned char)buffer[i]); - - cfprintf(file_name_buffer, "#ifndef %s\n#define %s\n#endif", - buffer, buffer); - - snprintf(buffer, BUFSIZ, "src/%s.c", manifest.project); - main_source = str_dup(buffer); - cfprintf(buffer, ""); - - cfprintf("Makefile", makefile_lib, manifest.project, - manifest.project); - - cfprintf("README", "%s", manifest.project); - - break; - default: - abort(); - } - - if (manifest.libraries.ncurses) { - fprintf(stderr, "Pulling ncurses"); - system("git submodule add --quiet https://github.com/mirror/ncurses"); - fprintf(stderr, ", done.\n"); - } - if (manifest.libraries.raylib) { - fprintf(stderr, "Pulling raylib"); - system("git submodule add --quiet https://github.com/raysan5/raylib"); - fprintf(stderr, ", done.\n"); - } - if (manifest.libraries.stb) { - fprintf(stderr, "Pulling stb"); - system("git submodule add --quiet https://github.com/nothings/stb"); - fprintf(stderr, ", done.\n"); - } - if (manifest.libraries.uthash) { - fprintf(stderr, "Pulling uthash"); - system("git submodule add --quiet https://github.com/troydhanson/uthash"); - fprintf(stderr, ", done.\n"); - } - if (manifest.libraries.linenoise) { - fprintf(stderr, "Pulling linenoise"); - system("git submodule add --quiet https://github.com/antirez/linenoise"); - fprintf(stderr, ", done.\n"); - } - + flast = true; switch (manifest.licence) { case MIT: cfprintf("COPYING", "%s", MIT_txt); @@ -206,13 +47,13 @@ int create_project(manifest_t manifest) abort(); } - if (!manifest.flags.git) { + if (!manifest.git) { fprintf(stderr, "Initializing git reposity"); system("git init --quiet"); fprintf(stderr, ", done.\n"); } - if (manifest.flags.editor) { + if (manifest.open_editor) { snprintf(buffer, BUFSIZ, "nvim %s", main_source); system(buffer); } diff --git a/src/library_contents.h b/src/library_contents.h deleted file mode 100644 index 839d7fe..0000000 --- a/src/library_contents.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) vx-clutch - * - * This file is part of yait - * - * This project and file is licenced under the BSD-3-Clause licecne - * - */ - -// clang-format off -#ifndef LIBRARY_CONTENTS_H -#define LIBRARY_CONTENTS_H - -#define line(ln) ln "\n" - -char *makefile_lib = - line ("CC = gcc") - line ("CLFAGS = -Wall -Wextra -O2 -fPIC -Iinclude") - line ("AR = ar rcs") - line ("BUILD = build") - line ("") - line ("SRC = $(wildcard src/*.c)") - line ("OBJ = $(SRC:src/%%.c=$(BUILD)/obj/%%.o)") - line ("") - line ("STATIC = $(BUILD)/%s.a") - line ("SHARED = $(BUILD)/%s.so") - line ("") - line ("all: $(STAITC) $(SHARED)") - line ("") - line ("$(STATIC): $(OBJ)\n\t$(AR) $@ $^") - line ("") - line ("$(SHARED): $(OBJ)\n\t$(CC) -shared -o $@ $^") - line ("") - line ("$(BUILD)/%%.o: src/%%.c | $(BUILD)\n\t$(CC) $(CFLAGS) -c $< -o $@") - line ("") - line ("$(BUILD):\n\tmkdir -p $(BUILD)/obj") - line ("") - line ("clean:\n\t$(RM) -r $(BUILD)"); - -#endif -// clang-format on diff --git a/src/main.c b/src/main.c index 434b821..4c09e81 100644 --- a/src/main.c +++ b/src/main.c @@ -16,10 +16,12 @@ #include #include #include +#include #include "../include/yait.h" #include "standard.h" #include "util.h" +#include "../config.h" #define print_option(option, description) \ printf(" %-20s %-20s\n", option, description) @@ -35,78 +37,120 @@ static void usage(int status) puts("Creates a C project with opinionated defaults"); puts("When only given the first argument it will detect your name\n"); 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("--no-git", "Do not initialize git repository"); 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 author ( default git username )"); - print_option( - "--style=