yait

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 13b15cb07fbebb040b76ca983e4b81d530dac270
parent 266c5232e987d05b4edbb9039fc0963fd1eba07b
Author: vx-clutch <[email protected]>
Date:   Fri, 29 Aug 2025 16:26:36 -0400

save

Diffstat:
M.clangd | 7++++++-
MTODO | 22+---------------------
Minclude/yait.h | 45++++++++++++++++++---------------------------
Msrc/create_project.c | 165++-----------------------------------------------------------------------------
Dsrc/library_contents.h | 40----------------------------------------
Msrc/main.c | 176+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Dsrc/posix_contents.h | 215-------------------------------------------------------------------------------
Msrc/util.c | 37++++++++++++++++++-------------------
Msrc/util.h | 2+-
Mtools/Cleanup | 1+
10 files changed, 163 insertions(+), 547 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -8,15 +8,11 @@ #include <stdint.h> #include <stdlib.h> -#include <time.h> #include <unistd.h> #include <sys/stat.h> #include <stdio.h> -#include <ctype.h> #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, - "<https://github.com/tgrysztar/fasm/blob/master/FASM.TXT>"); - cfprintf( - "SOURCE/main.c", - "#include <stdio.h>\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], [[email protected]])\nAM_INIT_AUTOMAKE([-Wall -Wextra foreign])\nAC_PROG_CC\nAC_CONFIG_FILES([Makefile src/Makefile man/Makefile])\nAC_OUTPUT"); - cfprintf( - "src/main.c", - "#include <stdio.h>\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 @@ -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 - * <https://opensource.org/licence/bsd-3-clause> - */ - -// 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 @@ -16,10 +16,12 @@ #include <limits.h> #include <string.h> #include <unistd.h> +#include <stdarg.h> #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 <licence>", "Set licence. This list can be found by passing 'list'"); - print_option("-l <library>", - "Add a library. This list can be found by passing 'list'"); - print_option("-n <name>", - "Set the name of the author ( default git username )"); - print_option( - "--style=<style>", - "Pick from a list of built in styles. This list can be found by passing 'list'"); print_option("-E", "Open editor after project creation"); puts(" --help display this help text and exit\n"); puts(" --version output version information and exit\n"); } +void print_lines(const char *first, ...) +{ + va_list args; + const char *s; + + va_start(args, first); + + for (s = first; s != NULL; s = va_arg(args, const char *)) + printf("%s\n", s); + + va_end(args); +} + +static inline int parse_extras_token(manifest_t *conf, char *s) +{ + if (!strcmp(s, "list")) { + print_lines("nob", "Cleanup", "format", NULL); + exit(EXIT_SUCCESS); + } + + if (!strcmp(s, "nob")) + return conf->extra.nob = true, 0; + if (!strcmp(s, "Cleanup")) + return conf->extra.Cleanup = true, 0; + if (!strcmp(s, "format")) + return conf->extra.clang_format = true, 0; + fprintf(stderr, "Option '%s' is not valid. See %s --extras=list\n", s, + PROGRAM); + return 1; +} + static int parse_arguments(manifest_t *conf, int argc, char **argv) { - int opt; + int opt, option_index; // clang-format off static struct option long_opts[] = { - { "style", required_argument, 0, 's' }, - { "no-git", no_argument, 0, 'g' }, - { "clang", no_argument, 0, 'c' }, + { "git", no_argument, 0, 'g' }, + { "no-git", no_argument, 0, 'G' }, + { "lib", no_argument, 0, 'L' }, + { "both", no_argument, 0, 'b' }, + { "autotools", no_argument, 0, 'a' }, + { "cmake", no_argument, 0, 'c' }, + { "make", no_argument, 0, 'm' }, + { "bare", no_argument, 0, 'B' }, + { "flat", no_argument, 0, 'f' }, + { "author", required_argument, 0, 'A' }, + { "extras", required_argument, 0, 0 }, { 0, 0, 0, 0 } }; // clang-format on - while ((opt = getopt_long(argc, argv, "s:gcn:L:l:En:", long_opts, - NULL)) != -1) { - switch (opt) { - case 's': - if (strcmp(optarg, "list") == 0) { - puts("posix\nsimple\nGNU\nlib\nfasm\nlib"); - exit(EXIT_SUCCESS); + while ((opt = getopt_long(argc, argv, "gGLbacmBfAl:E", long_opts, + &option_index)) != -1) { + if (opt == 0 && + strcmp(long_opts[option_index].name, "extras") == 0) { + int err; + char *arg = optarg; + char *token = strtok(arg, ","); + while (token) { + err = parse_extras_token(conf, token); + if (err) + exit(err); + token = strtok(NULL, ","); } - conf->style = TOstyle(optarg); - break; + } + switch (opt) { case 'g': - conf->flags.git = false; + conf->git = true; + break; + case 'G': + conf->git = false; + break; + case 'L': + conf->lib = true; + break; + case 'b': + conf->lib = true; + conf->exe = true; + break; + case 'a': + conf->autotools = true; break; case 'c': - conf->flags.clang = true; + conf->cmake = true; break; - case 'n': - conf->name = str_dup(optarg); + case 'm': + conf->make = true; break; - case 'L': - conf->licence = TOlicence(optarg); + case 'B': + conf->bare = true; + break; + case 'f': + conf->flat = true; + break; + case 'A': + conf->author = optarg; break; case 'l': - if (strcmp(optarg, "list") == 0) { - puts("ncurses\nraylib\nstb\nuthash\nlinenoise"); + if (!strcmp(optarg, "list")) { + print_lines("MIT", "BSD", "GPL", "UNL", NULL); exit(EXIT_SUCCESS); } - if (strcmp(optarg, "ncurses") == 0) - conf->libraries.ncurses = true; - else if (strcmp(optarg, "raylib") == 0) - conf->libraries.raylib = true; - else if (strcmp(optarg, "stb") == 0) - conf->libraries.stb = true; - else if (strcmp(optarg, "uthash") == 0) - conf->libraries.uthash = true; - else if (strcmp(optarg, "linenoise") == 0) - conf->libraries.linenoise = true; - else - fprintf(stderr, - "warning: %s is not a support library", - optarg); + conf->licence = TOlicence(optarg); break; case 'E': - conf->flags.editor = true; + conf->open_editor = true; conf->editor = getenv("EDITOR"); break; default: @@ -115,7 +159,7 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv) } if (optind >= argc) { - fputs("error: missing required positional argument\n", stderr); + fputs("error: missing project name\n", stderr); return 1; } conf->project = str_dup(argv[optind]); @@ -162,20 +206,22 @@ int main(int argc, char **argv) int status; manifest_t manifest = { .project = "Project", - .name = "author", - .editor = "nano", + .author = "author", + .editor = "vim", + .licence = UNL, - .style = POSIX, - .libraries.ncurses = false, - .libraries.raylib = false, - .libraries.stb = false, - .libraries.uthash = false, - .libraries.linenoise = false, + .git = true, + .autotools = false, + .cmake = false, + .make = true, + .bare = false, + .flat = false, + .open_editor = false, - .flags.git = true, - .flags.clang = false, - .flags.editor = false, + .extra.nob = false, + .extra.clang_format = false, + .extra.Cleanup = false, }; status = parse_standard_options(usage, argc, argv); @@ -188,7 +234,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - get_name(&manifest.name); + get_name(&manifest.author); status = create_project(manifest); if (status) { @@ -196,9 +242,17 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - char buffer[PATH_MAX]; - getcwd(buffer, PATH_MAX); - fprintf(stderr, "Created %s at\n %s\n", manifest.project, buffer); + char *cwd; + + cwd = getcwd(NULL, 0); + if (cwd == NULL) { + perror("getcwd"); + exit(EXIT_FAILURE); + } + + fprintf(stderr, "Created %s at\n %s\n", manifest.project, cwd); + + free(cwd); return EXIT_SUCCESS; } diff --git a/src/posix_contents.h b/src/posix_contents.h @@ -1,215 +0,0 @@ -/* Copyright (C) vx_clutch - * - * This file is part of yait - * - * This project and file is licenced under the BSD-3-Clause licence. - * <https://opensource.org/license/bsd-3-clause> - */ - -// clang-format off -#ifndef POSIX_CONTENTS_H -#define POSIX_CONTENTS_H - -#define line(ln) ln "\n" - -char *readme = - line ("%s ( concise description )") - line () - line ("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor") - line ("incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis") - line ("nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.") - line ("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu") - line ("fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in") - line ("culpa qui officia deserunt mollit anim id est laborum."); - -char *configure = - line ("#!/bin/sh") - line () - line ("usage() {") - line ("cat <<EOF") - line ("Usage: $0 [OPTION]... [VAR=VALUE]...") - line () - line ("To assign environment variables (e.g., CC, CFLAGS...), specify them as") - line ("VAR=VALUE.") - line () - line (" CC C compiler command [detected]") - line (" CFLAGS C compiler flags [-g, ...]") - line () - line ("EOF") - line ("exit 0") - line ("}") - line () - line ("echo () { printf \"%%s\\n\" \"$*\" ; }") - line ("cmdexists () { type \"$1\" >/dev/null 2>&1 ; }") - line ("trycc () { test -z \"$CC\" && cmdexists \"$1\" && CC=$1 ; }") - line () - line ("prefix=/usr/bin/") - line ("CFLAGS=\"-Wall -Wextra -O2 --std=c23 -Wpedantic\"") - line ("LDFLAGS=") - line ("CC=") - line () - line ("for arg ; do") - line ("case \"$arg\" in") - line ("--help|h) usage ;;") - line ("--prefix=*) prefix=${arg#*=} ;;") - line ("CFLAGS=*) CFLAGS=${arg#*=} ;;") - line ("LDFLAGS=*) LDFLAGS=${arg#*=} ;;") - line ("esac") - line ("done") - line () - line ("printf \"checking for C compiler... \"") - line ("%%s") - line ("printf \"%%s\\n\" \"$CC\"") - line () - line ("printf \"checking weather C compiler works... \"") - line ("status=\"fail\"") - line ("tmpc=\"$(mktemp -d)/test.c\"") - line ("echo \"typedef int x;\" > \"$tmpc\"") - line ("if output=$($CC $CFLAGS -c -o /dev/null \"$tmpc\" 2>&1) ; then") - line ("printf \"yes\\n\"") - line ("else") - line ("printf \"no; %%s\\n\" \"$output\"") - line ("exit 1") - line ("fi") - line () - line ("printf \"creating config.mak... \"") - line ("printf \"PREFIX=%%s\\n\" \"$prefix\" > config.mak") - line ("printf \"CFLAGS=%%s\\n\" \"$CFLAGS\" >> config.mak") - line ("printf \"LDFLAGS=%%s\\n\" \"$LDFLAGS\" >> config.mak") - line ("printf \"CC=%%s\\n\" \"$CC\" >> config.mak") - line ("printf \"done\\n\""); - -char *makefile = - line ("prefix = /usr/bin") - line () - line ("%s_SRCS := $(wildcard %s/*.c)") - line ("%s_OBJS := $(patsubst ./%s/%%.c,c-out/obj/%%.o,$(%s_SRCS))") - line () - line ("%s := c-out/bin/%s") - line () - line ("-include config.mak") - line () - line ("ifeq ($(wildcard config.mak),)") - line ("all:") - line ("\t@echo \"File config.mak not found, run configure\"") - line ("\t@exit 1") - line ("else") - line () - line ("all: build $(%s)") - line () - line ("build:") - line ("\tmkdir -p c-out/bin") - line ("\tmkdir -p c-out/obj") - line () - line ("c-out/obj/%%.o: %s/%%.c") - line ("\t$(CC) $(CFLAGS) -c $< -o $@") - line () - line ("$(%s): $(%s_OBJS)") - line ("\t$(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all 2>/dev/null || echo 0) $^ -o $@") - line () - line ("endif") - line () - line ("install:") - line ("\t@echo \"NOT IMPL\"") - line ("\texit 1") - line () - line ("uninstall:") - line ("\t@echo \"NOT IMPL\"") - line ("\texit 1") - line () - line ("clean:") - line ("\trm -rf c-out") - line () - line ("dist-clean: clean") - line ("\trm -f config.mak") - line () - line (".PHONY: all clean dist-clean install uninstall"); - -char *clang_format = - line ("BasedOnStyle: GNU"); - -char *config_h = - line ("#ifndef CONFIG_H") - line ("#define CONFIG_H") - line () - line ("/* Program information */") - line ("#define PROGRAM \"%s\"") - line ("#define LICENSE_LINE \"%s\"") - line ("#define AUTHORS \"%s\"") - line ("#define VERSION \"pre-alpha\"") - line ("#define YEAR 2025") - line () - line ("#define HELP_REQUESTED 2") - line ("#define ERROR_MEMORY_ALLOCATION 3") - line ("#define ERROR_DIRECTORY_CREATION 4") - line () - line ("#endif"); - -char *main_c = - line ("#include <stdio.h>") - line () - line ("int main(void) {") - line (" printf(\"%s: Hello %s!\\n\");") - line (" return 0;") - line ("}"); - -char *main_c_gnu = - line ("#include <stdio.h>") - line ("#include \"standard.h\"") - line () - line ("void usage(int status) {") - line (" fprintf(stderr, \"Usage: %s [OPTION...]\\n\");") - line (" fprintf(stderr, \" --help\\tdisplay the help text and exit\\n\");") - line (" fprintf(stderr, \" --version\\toutput version information and exit\\n\");") - line ("}") - line () - line ("int main(int argc, char **argv) {") - line (" parse_standard_options(usage, argc, argv);") - line (" printf(\"%s: Hello %s!\\n\");") - line (" return 0;") - line ("}"); - -char *standard_c = - line ("#include \"standard.h\"") - line ("#include \"../config.h\"") - line ("#include <stdio.h>") - line ("#include <stdlib.h>") - line ("#include <string.h>") - line () - line ("int") - line ("parse_standard_options (void (*usage) (int), int argc, char **argv)") - line ("{") - line (" for (int i = 1; i < argc; ++i)") - line (" {") - line (" if (strcmp (argv[i], \"--help\") == 0)") - line (" {") - line (" usage (0);") - line (" exit (EXIT_SUCCESS);") - line (" }") - line (" else if (strcmp (argv[i], \"--version\") == 0)") - line (" {") - line (" printf (\"%s %s %d\\nCopyright (C) %d %s.\\n%s\\nThis is free software: you are free to change and redistribute it.\\nThere is NO WARRNTY, to the extent permitted by law.\\n\", PROGRAM, VERSION, COMMIT, YEAR, AUTHORS, LICENSE_line );") - line (" exit (EXIT_SUCCESS);") - line (" }") - line (" }") - line (" return HELP_REQUESTED;") - line ("}"); - -char *standard_h = - line ("#ifndef STANDARD_H") - line ("#define STANDARD_H") - line () - line ("int parse_standard_options(void (*usage_func)(), int argc, char **argv);") - line () - line ("#endif"); - -char *what_next = - line ("# What next?") - line ("") - line ("## Steps") - line (" - Write a description in the README") - line (" - Write the usage function ( write to stderr )") - line (" - Start writing your program"); - -#endif -// clang-format on diff --git a/src/util.c b/src/util.c @@ -6,49 +6,48 @@ * <https://opensource.org/licence/bsd-3-clause> */ -#include <string.h> +#include <ctype.h> #include <stdio.h> #include <getopt.h> #include <stdlib.h> +#include <string.h> #include "util.h" #include "../include/yait.h" -int fno = 0; +int fno = 1; bool flast = false; -licence_t TOlicence(char *s) +licence_t TOlicence(char *src) { - if (!strcmp(s, "mit")) + char *s = tostrupr(src); + if (!strcmp(s, "MIT")) return MIT; - if (!strcmp(s, "gpl")) + if (!strcmp(s, "GPL")) return GPL; - if (!strcmp(s, "bsd")) + if (!strcmp(s, "BSD")) return BSD; + free(s); return UNL; } -style_t TOstyle(char *s) +char *str_dup(char *s) { - if (!strcmp(s, "posix")) - return POSIX; - if (!strcmp(s, "simple")) - return SIMPLE; - if (!strcmp(s, "GNU")) - return GNU; - if (!strcmp(s, "lib")) - return LIBRARY; - if (!strcmp(s, "fasm")) - return FASM; - return SIMPLE; + char *new = malloc(strlen(s) + 1); + if (!new) + return NULL; + strcpy(new, s); + return new; } -char *str_dup(char *s) +char *tostrupr(char *s) { char *new = malloc(strlen(s) + 1); if (!new) return NULL; strcpy(new, s); + for (int i = 0; new[i] != '\0'; ++i) + new[i] = toupper((unsigned char)new[i]); return new; } diff --git a/src/util.h b/src/util.h @@ -12,12 +12,12 @@ #include "../include/yait.h" licence_t TOlicence(char *s); -style_t TOstyle(char *s); int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex); char *str_dup(char *s); +char *tostrupr(char *s); extern int fno; extern bool flast; diff --git a/tools/Cleanup b/tools/Cleanup @@ -15,6 +15,7 @@ fi sh ./tools/format || fatal Could not run './tools/format' rm -rf .cache || fatal Could not run 'rm -rf .cache' +rm -f compile_commands.json || fatal Could not run 'rm -f compile_commands.json' make dist-clean || fatal Could not run 'make dist-clean' echo done.