commit bfefb223f177342c9113f5841f1475da89f17483
parent 561753df419bf21bcd98c4d2a0c836be8c58647b
Author: vx-clutch <[email protected]>
Date: Sun, 9 Nov 2025 21:55:07 -0500
wip
Diffstat:
| M | .gitignore | | | 6 | +----- |
| A | Makefile | | | 38 | ++++++++++++++++++++++++++++++++++++++ |
| A | README | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | estruct.h | | | 12 | ++++++++++++ |
| A | file.c | | | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | file.h | | | 8 | ++++++++ |
| A | globals.h | | | 6 | ++++++ |
| A | input.c | | | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | input.h | | | 9 | +++++++++ |
| A | main.c | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | proj.c | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | proj.h | | | 6 | ++++++ |
| A | shell.c | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | shell.h | | | 6 | ++++++ |
| A | usage.c | | | 22 | ++++++++++++++++++++++ |
| A | usage.h | | | 6 | ++++++ |
| A | version.c | | | 7 | +++++++ |
| A | version.h | | | 12 | ++++++++++++ |
18 files changed, 546 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,6 +1,2 @@
-bin/
-build/
+yait
*.o
-config.mak
-config.status
-*cache*
diff --git a/Makefile b/Makefile
@@ -0,0 +1,38 @@
+# Makefile for yait
+
+# Make the build silent by default
+V =
+
+ifeq ($(strip $(V)),)
+ E = @echo
+ Q = @
+else
+ E = @\#
+ Q =
+endif
+export E Q
+
+PROGRAM = yait
+SRC = $(wildcard *.c)
+OBJ = $(SRC:.c=.o)
+
+CC = gcc
+WARNINGS = -Wall -Wstrict-prototypes
+CFLAGS = -O2 $(WARNINGS) -g
+DEFINES =
+LIBS =
+LDFLAGS =
+BINDIR = /usr/bin
+LIBDIR = /usr/lib
+
+$(PROGRAM): $(OBJ)
+ $(E) " LINK " $@
+ $(Q) $(CC) $(LDFLAGS) $(DEFINES) -o $@ $(OBJ) $(LIBS)
+
+clean:
+ $(E) " CLEAN"
+ $(Q) rm -f $(PROGRAM) $(OBJ)
+
+.c.o:
+ $(E) " CC " $@
+ $(Q) $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
diff --git a/README b/README
@@ -0,0 +1,49 @@
++---------------+
+| yait/fSD 1.0 |
++---------------+
+
+ Highly opinionated C and SH project generator
+
+ yait was written by vx-clutch
+
+ Copyright Notices:
+
+ yait 1.0 (c) Copyright 2025 fSD.
+ Reference the COPYING file for detailed information
+
+
+WHAT IS yait/fSD?
+
+yait/fSD 1.0 is an optionated C and SH project generator. For C project
+generation is produces a similar layout to the source of this project. On
+SH it generates a shell script with useful useful scaffolding for a
+script.
+
+
+WHAT IS NEW
+
+Features:
+
+o This is the inital commit, EVERYTHING is new!
+
+Bug fixes - not very interesting:
+
+o None
+
+Something is gone:
+
+o None
+
+
+HOW TO BUILD yait/fSD?
+
+o UNIX: Compile the packge with make and install manually with for your
+ given system.
+
+
+ACKNOWLEDGEMENTS AND STATUS
+
+This project's file strucutre, file format, and certain contents are
+derived from uEmacs/PK 4.0 specifically from the Linux Torvalds
+distribution on GitHub. The README on from uEmacs/PK 4.0 has greater and
+more accurate attributions, if you desire.
diff --git a/estruct.h b/estruct.h
@@ -0,0 +1,12 @@
+#ifndef ESTRUCT_H_
+#define ESTRUCT_H_
+
+/* Configuration options */
+
+#define QLICENSE 0 /* Force use the default license option */
+#define LICENSE "BSD-3-Clause" /* Default SPDX-License-Identifier */
+
+#define QAUTHOR 0 /* Force use the default author option */
+#define AUTHOR "fSD" /* Default author*/
+
+#endif /* ESTRUCT_H_ */
diff --git a/file.c b/file.c
@@ -0,0 +1,78 @@
+/* file.c
+ *
+ * The routines in this file handle the reading, writing
+ * and lookup of disk files. All of details about the
+ * reading and writing of the disk are in "fileio.c".
+ *
+ * written by vx-clutch
+ */
+
+#include <errno.h>
+#include <libgen.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "file.h"
+#include "globals.h"
+
+int ffwrite(char *path, char *fmt, ...) {
+ FILE *f;
+ va_list ap;
+ int r;
+
+ f = fopen(path, "w");
+ if (!f)
+ return -1;
+
+ va_start(ap, fmt);
+ r = vfprintf(f, fmt, ap);
+ va_end(ap);
+
+ fclose(f);
+ return r < 0 ? -1 : 0;
+}
+
+int fmkdir(char *fmt, ...)
+{
+ va_list ap;
+ char path[NPAT];
+ char tmp[NPAT];
+ char *p;
+
+ va_start(ap, fmt);
+ vsnprintf(path, sizeof(path), fmt, ap);
+ va_end(ap);
+
+ strncpy(tmp, path, sizeof(tmp) - 1);
+ tmp[sizeof(tmp) - 1] = '\0';
+
+ for (p = tmp + 1; *p; p++) {
+ if (*p == '/') {
+ *p = '\0';
+ if (mkdir(tmp, 0755) < 0 && errno != EEXIST)
+ return -1;
+ *p = '/';
+ }
+ }
+
+ if (mkdir(tmp, 0755) < 0 && errno != EEXIST)
+ return -1;
+
+ return 0;
+}
+
+int ffexist(char *fmt, ...) {
+ char path[NPAT];
+ va_list ap;
+ struct stat st;
+
+ va_start(ap, fmt);
+ vsnprintf(path, sizeof(path), fmt, ap);
+ va_end(ap);
+
+ return stat(path, &st) == 0;
+}
diff --git a/file.h b/file.h
@@ -0,0 +1,8 @@
+#ifndef FILE_H_
+#define FILE_H_
+
+int ffwrite(char *path, char *fmt, ...);
+int fmkdir(char *path, ...);
+int ffexist(char *fmt, ...);
+
+#endif /* FILE_H_ */
diff --git a/globals.h b/globals.h
@@ -0,0 +1,6 @@
+#ifndef GLOBALS_H_
+#define GLOBALS_H_
+
+#define NPAT 4096 /* number of bytes for path buffer */
+
+#endif /* GLOBALS_H_ */
diff --git a/input.c b/input.c
@@ -0,0 +1,70 @@
+/* input.c
+ *
+ * Various input routines
+ *
+ * written by vx-clutch
+ */
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "input.h"
+
+char *getstring(char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+
+ printf("? ");
+ vprintf(fmt, args);
+ putc(' ', stdout);
+
+ va_end(args);
+ fflush(stdout);
+
+ char *buf = NULL;
+ size_t size = 0;
+ ssize_t len = getline(&buf, &size, stdin);
+
+ if (len < 0) {
+ free(buf);
+ return NULL;
+ }
+
+ if (len > 0 && buf[len - 1] == '\n')
+ buf[len - 1] = '\0';
+
+ return buf;
+}
+
+int yes_no_prompt(const char *fmt, ...) {
+ char prompt[256];
+
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(prompt, sizeof prompt, fmt, ap);
+ va_end(ap);
+
+ char buf[64];
+ for (;;) {
+ fprintf(stderr, "? %s", prompt);
+ fputs(" (y/n) ", stdout);
+ fflush(stdout);
+
+ if (!fgets(buf, sizeof buf, stdin))
+ return 0;
+
+ size_t i = 0;
+ while (buf[i] && isspace((unsigned char)buf[i]))
+ i++;
+ if (!buf[i])
+ continue;
+
+ char c = tolower((unsigned char)buf[i]);
+ if (c == 'y')
+ return 1;
+ if (c == 'n')
+ return 0;
+ }
+}
diff --git a/input.h b/input.h
@@ -0,0 +1,9 @@
+#ifndef INPUT_H_
+#define INPUT_H_
+
+enum { TRUE, FALSE, GUARANTEE };
+
+char *getstring(char *fmt, ...);
+int mlyesno(char *fmt, ...);
+
+#endif /* INPUT_H_ */
diff --git a/main.c b/main.c
@@ -0,0 +1,74 @@
+/*
+ * main.c
+ *
+ * yait/fSD 1.0
+ *
+ * Copying policy:
+ *
+ * yait 1.0 can be copied and distributed freely for any
+ * non-commercial purposes. yait 1.0 can only be incorporated
+ * into commercial software with the permission of the current author.
+ *
+ * This file contains the main driving routine, and some handling
+ * for C/SH distinction.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "shell.h"
+#include "usage.h"
+#include "version.h"
+#include "proj.h"
+
+void usage(int status)
+{
+ printf("Usage: %s filename\n", PROGRAM_NAME);
+ printf(" or: %s [options]\n\n", PROGRAM_NAME);
+ fputs(" -S enable shell creation mode\n", stdout);
+ fputs(" --help display this help and exit\n", stdout);
+ fputs(" --version output version information and exit\n", stdout);
+
+ exit(status);
+}
+
+int main(int argc, char **argv)
+{
+ int c = 0;
+ int S = 0;
+ int carg;
+
+ if (argc == 2) {
+ if (strcmp(argv[1], "--help") == 0) {
+ usage(EXIT_FAILURE);
+ }
+ if (strcmp(argv[1], "--version") == 0) {
+ version();
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ for (carg = 0; carg < argc; ++carg) {
+ if (argv[carg][0] == '-') {
+ switch (argv[carg][1]) {
+ case 'S':
+ S = 1;
+ break;
+ }
+ }
+ }
+
+ if (argc < 2 || c)
+ die("not enough arguments");
+
+ char *package = argv[carg - 1];
+
+ if (S)
+ makeshell(package);
+ else
+ makeproj(package);
+
+ return 0;
+}
diff --git a/proj.c b/proj.c
@@ -0,0 +1,74 @@
+/* proj.c
+ *
+ * The routines in this file generater an
+ * opinionated C project.
+ *
+ * written by vx-clutch
+ */
+
+#include <unistd.h>
+
+#include "estruct.h"
+#include "file.h"
+#include "input.h"
+#include "proj.h"
+#include "usage.h"
+
+int makeproj(char *src)
+{
+ if (ffexist(src))
+ die("%s already exists", src);
+
+ fmkdir(src);
+ if (chdir(src))
+ die("could not cd into %s", src);
+
+ ffwrite("main.c", "\
+/*\n\
+ * main.c\n\
+ *\n\
+ * package/Author 1.0\n\
+ *\n\
+ * Copying policy\n\
+ *\n\
+ * yait 1.0 can be copied and distributed freely for any\n\
+ * non-commercial purposes. yait 1.0 can only be incorporated\n\
+ * into commercial software with the permission of the current author.\n\
+ *\n\
+ * This file contains the main driving routine.\n\
+ *\n\
+ */\n\
+\n\
+#include <stdio.h>\n\
+#include <stdlib.h>\n\
+#include <string.h>\n\
+\n\
+void usage(int status)\n\
+{\n\
+ printf(\"Usage: %%s REQUIRED POSITIONAL ARGUMENT\\n\", PROGRAM_NAME);\n\
+ printf(\" or: %%s [options]\\n\\n\", PROGRAM_NAME);\n\
+ fputs(\" --help display this help and exit\\n\", stdout);\n\
+ fputs(\" --version output version information and exit\\n\", stdout);\n\
+\n\
+ exit(status);\n\
+}\n\
+\n\
+int main(int argc, char **argv)\n\
+{\n\
+ int carg;\n\
+\n\
+ if (argc == 2) {\n\
+ if (strcmp(argv[1], \"--help\") == 0) {\n\
+ usage(EXIT_FAILURE);\n\
+ }\n\
+ if (strcmp(argv[1], \"--version\") == 0) {\n\
+ version();\n\
+ exit(EXIT_SUCCESS);\n\
+ }\n\
+ }\n\
+\n\
+ return 0;\n\
+}");
+
+ return 0;
+}
diff --git a/proj.h b/proj.h
@@ -0,0 +1,6 @@
+#ifndef PROJ_H_
+#define PROJ_H_
+
+int makeproj(char *src);
+
+#endif /* PROJ_H_ */
diff --git a/shell.c b/shell.c
@@ -0,0 +1,68 @@
+/* shell.c
+ *
+ * The routines in this file generater an
+ * opiionated shell script.
+ *
+ * written by vx-clutch
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "estruct.h"
+#include "file.h"
+#include "input.h"
+#include "shell.h"
+#include "usage.h"
+
+int makeshell(char *src)
+{
+ if (ffexist(src))
+ die("%s already exists", src);
+
+ char *license = LICENSE;
+ if (!QLICENSE)
+ license = getstring("License");
+ char *description = getstring("Description");
+
+ ffwrite(src, "\
+#!/bin/sh\n\
+# SPDX-License-Identifier: %s\n\
+#\n\
+# %s\n\
+\n\
+me=$0\n\
+scriptversion=\"1.0.0\"\n\
+\n\
+version=\"$me $scriptversion\n\
+\n\
+Copyright (C) %d %s.\n\
+This is free software; you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\"\n\
+\n\
+usage=\"\\\n\
+Usage: $me [OPTION]...\n\
+%s\n\
+\n\
+Options:\n\
+ --help print this help and exit\n\
+ --version output version information\n\"\n\
+\n\
+while [ $# -gt 0 ]; do\n\
+ case $1 in\n\
+ --help) echo \"$usage\"; exit 0 ;;\n\
+ --version) echo \"$version\"; exit 0 ;;\n\
+ -*)\n\
+ echo \"$0: Unknown option '$1'.\" >&2\n\
+ echo \"$0: Try '--help' for more information.\" >&2\n\
+ exit 1 ;;\n\
+ esac\n\
+ shift\n\
+done", license, description, 2025, "fSD", description);
+
+ struct stat st;
+ if (stat(src, &st) == 0)
+ chmod(src, st.st_mode | S_IXUSR | S_IXGRP | S_IXOTH);
+
+ return 0;
+}
diff --git a/shell.h b/shell.h
@@ -0,0 +1,6 @@
+#ifndef SHELL_H_
+#define SHELL_H_
+
+int makeshell(char *src);
+
+#endif /* SHELL_H_ */
diff --git a/usage.c b/usage.c
@@ -0,0 +1,22 @@
+#include "usage.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static void report(const char* prefix, const char *err, va_list params)
+{
+ char msg[4096];
+ vsnprintf(msg, sizeof(msg), err, params);
+ fprintf(stderr, "%s%s\n", prefix, msg);
+}
+
+void die(const char* err, ...)
+{
+ va_list params;
+
+ va_start(params, err);
+ report("fatal: ", err, params);
+ va_end(params);
+ exit(128);
+}
diff --git a/usage.h b/usage.h
@@ -0,0 +1,6 @@
+#ifndef USAGE_H_
+#define USAGE_H_
+
+void die(const char* err, ...);
+
+#endif /* USAGE_H_ */
diff --git a/version.c b/version.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include "version.h"
+
+void version(void)
+{
+ printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION);
+}
diff --git a/version.h b/version.h
@@ -0,0 +1,12 @@
+#ifndef VERSION_H_
+#define VERSION_H_
+
+#define PROGRAM_NAME "yait"
+#define PROGRAM_NAME_LONG "yait/fSD"
+
+#define VERSION "1.0.0"
+
+/* Print the version string. */
+void version(void);
+
+#endif /* VERSION_H_ */