From 116fb662c872bc2d2aab89bc0db33aafa55a64fd Mon Sep 17 00:00:00 2001 From: vx-clutch Date: Tue, 4 Nov 2025 21:14:47 -0500 Subject: [PATCH] save --- Makefile | 32 +++++++++++++++++++------------- TODO | 4 ++-- src/flat.c | 20 ++++++++++++++++++++ src/flat.h | 8 ++++++++ src/license.h | 4 ++-- src/shell.h | 4 ++-- src/yait.c | 32 +++++++++++++++++++++++++++++--- t/Makefile.x | 2 +- t/README.x | 2 +- t/main.x | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 src/flat.c create mode 100644 src/flat.h create mode 100644 t/main.x diff --git a/Makefile b/Makefile index 37827c8..6ec9f82 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PACKAGE := yait SRCS := $(wildcard src/*.c) $(wildcard lib/*.c) -OBJS := $(patsubst src/%.c,build/obj/%.o,$(SRCS)) +OBJS := $(patsubst %.c,build/obj/%.o,$(SRCS)) BIN := bin/$(PACKAGE) @@ -21,23 +21,29 @@ all: @exit 1 else -all: build $(BIN) doc +all: $(BIN) -build: - mkdir -p bin - mkdir -p build/obj +bin: + @mkdir -p bin -build/obj/%.o: src/%.c config.mak - $(CC) $(FLAGS) $(CFLAGS) -c $< -o $@ +build/obj: + @mkdir -p build/obj/src + @mkdir -p build/obj/lib -$(BIN): $(OBJS) - $(CC) $(FLAGS) $(CFLAGS) $^ -o $@ +build/obj/%.o: %.c config.mak | build/obj + @printf " CC %s\n" $(notdir $@) + @$(CC) $(FLAGS) $(CFLAGS) -c $< -o $@ + +$(BIN): $(OBJS) | bin + @printf " LINK %s\n" "$(notdir $@)" + @$(CC) $(FLAGS) $(CFLAGS) $^ -o $@ -endif install: $(BIN) cp $(BIN) $(PREFIX) +endif + doc: $(MAKE) -C doc all @@ -54,10 +60,10 @@ distclean: clean $(RM) $(TARBALL) $(MAKE) -C doc clean -release: clean all +release: distclean all tar -czf $(TARBALL) $(RELEASE_FILES) test: - @$(BIN) --version > /dev/null 2>&1 && echo "intact"|| echo "defective" + @$(BIN) --version > /dev/null 2>&1 && echo "intact" || echo "defective" -.PHONY: all clean distclean install uninstall build release doc +.PHONY: all clean distclean install uninstall doc diff --git a/TODO b/TODO index e518558..85fe182 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ GCK yait --- TODO Todo: - * fix 't' so that it handles names correctly - * write all templates + * fix 't' so that it handles names correctly and special in-file characters + * write all templates sources end of file TODO diff --git a/src/flat.c b/src/flat.c new file mode 100644 index 0000000..aea3c77 --- /dev/null +++ b/src/flat.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifer: BSD-3-Clause +/* + * A uemacs derided and inspired layout and format for smaller projects; + * such as, a small library, or CLI. + */ +#include +#include + +#include +#include "flat.h" + +int generate_flat(char *package, char *author, int year, char *license, + char *desc) +{ + char *main; + asprintf(&main, "%s.c", package); + fs_write("Makefile", templ_flat_MAKEFILE, package); + fs_write(main, templ_main, license); + return 0; +} diff --git a/src/flat.h b/src/flat.h new file mode 100644 index 0000000..35ab1fe --- /dev/null +++ b/src/flat.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: BSD-3-Clause +#ifndef FLAT_H_ +#define FLAT_H_ + +int generate_flat(char *package, char *author, int year, char *license, + char *desc); + +#endif diff --git a/src/license.h b/src/license.h index 03a8305..96bc889 100644 --- a/src/license.h +++ b/src/license.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BSD-3-Clause -#ifndef LICENCES_H -#define LICENCES_H +#ifndef LICENCES_H_ +#define LICENCES_H_ const char *fBSD = "\ BSD 3-Clause License\n\ diff --git a/src/shell.h b/src/shell.h index 36dd4f9..fa9f9ac 100644 --- a/src/shell.h +++ b/src/shell.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BSD-3-Clause -#ifndef SHELL_H -#define SHELL_H +#ifndef SHELL_H_ +#define SHELL_H_ int write_shell(char *package, char *license, int year, char *author, char *m); diff --git a/src/yait.c b/src/yait.c index a4b2d86..40c07b5 100644 --- a/src/yait.c +++ b/src/yait.c @@ -3,7 +3,6 @@ * Copyright (C) 2025, GCK. * Written by vx-clutch (vx-clutch) */ - #include #include #include @@ -23,12 +22,14 @@ #include "shell.h" #include "license.h" +#include typedef enum { MIT, GPL, BSD, UNL } license_t; static const struct option longopts[] = { { "author", required_argument, 0, 'a' }, { "license", required_argument, 0, 'l' }, + { "flat", no_argument, 0, 'f' }, { 0, 0, 0, 0 } }; @@ -96,6 +97,7 @@ int main(int argc, char **argv) int lose = 0; char *m = str_dup("Does a thing"), *package; bool shell = false; + bool flat = false; char *author = get_name(); exit_status = EXIT_SUCCESS; int year = get_year(); @@ -147,6 +149,9 @@ int main(int argc, char **argv) case 'S': shell = true; break; + case 'f': + flat = true; + break; default: lose = 1; } @@ -175,9 +180,30 @@ int main(int argc, char **argv) if (chdir(project_dir)) fatalfa(errno); + switch (license) { + case MIT: + fs_write("COPYING", fMIT, year, author); + break; + case GPL: + fs_write("COPYING", fGPL); + break; + case BSD: + fs_write("COPYING", fBSD, year, author); + break; + case UNL: + default: + fs_write("COPYING", fUNL); + } + fs_write("README", templ_README, author, package, package, m, year, - author, author, package); - fs_write("README-dev", templ_README_dev, year, author); + package, author, package); + + if (flat) + exit_status = + generate_flat(package, author, year, license_str, m); + else + exit_status = + generate_regular(package, author, year, license_str, m); return exit_status; } diff --git a/t/Makefile.x b/t/Makefile.x index 81de4f4..55fd924 100644 --- a/t/Makefile.x +++ b/t/Makefile.x @@ -1,4 +1,4 @@ - Format_Index: p +Format_Index: p # SPDX-License-Identifier: BSD-3-Clause PACKAGE := %s diff --git a/t/README.x b/t/README.x index 89d9232..d19a068 100644 --- a/t/README.x +++ b/t/README.x @@ -1,4 +1,4 @@ -Format_Index: a, p, p, d, y, a, a, p +Format_Index: a, p, p, d, y, p, a, p This is the README file for the %s %s distribution. %s %s diff --git a/t/main.x b/t/main.x new file mode 100644 index 0000000..627c827 --- /dev/null +++ b/t/main.x @@ -0,0 +1,50 @@ +Format_Index: l, y, a, d, a +// SPDX-License-Identifier: %s +/* + * Copyright (C) %d, %s. + * Written by YOU (you@example.com) + */ + #include + + static int exit_status; + + static void print_help(); + static void print_version(); + + int main(int argc, char **argv) + { + exit_status = EXIT_SUCCESS; + + return exit_status; + } + +static void print_help() +{ + printf("Usage: %%s [OPTION]...\n", PROGRAM); + fputs("\ +%s.\n", + stdout); + puts(""); + fputs("\ + --help display this help and exit\n\ + --version display version information and exit\n", + stdout); + /* + puts(""); + fputs("\ + --foo Enable the foo directive\n", + stdout); + */ + exit(exit_status); +} + +static void print_version() +{ + printf("%%s %%s %%d\n", prog_name, VERSION, COMMIT); + + printf("Copyright (C) %%d %s.\n", YEAR); + + puts("This is free software: you are free to change and redistribute it."); + puts("There is NO WARRANTY, to the extent permitted by law."); + exit(exit_status); +}