Inital branch commit
This commit is contained in:
48
COPYING
48
COPYING
@@ -1,39 +1,15 @@
|
||||
Copyright (c) 2025-2026 fSD version 1
|
||||
ISC License
|
||||
|
||||
This document is intended "as is", without modifications.
|
||||
Copyright (c) 2025-2026 fSD
|
||||
|
||||
The binary and source code that this file is associated with and distributed
|
||||
with is licensed under the following terms and conditions.
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Maintainers Note:
|
||||
This section is reserved for any deviations of the prior notice. Given that
|
||||
you are reading this, that means this document is assumed unmodified. Any
|
||||
modifications in this section most follow this format:
|
||||
|
||||
o the note.
|
||||
|
||||
If a note is provided here the header the at top of the document must be
|
||||
changed to reflect that as such: "This document is intended "as is",
|
||||
without modifications." must become "This is a modified version of the
|
||||
fSD general license. See Maintainers Note.".
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
49
Makefile
49
Makefile
@@ -1,46 +1,5 @@
|
||||
# Makefile for yait
|
||||
all:
|
||||
@echo "nothing to do"
|
||||
|
||||
# Make the build silent by default
|
||||
V =
|
||||
|
||||
ifeq ($(strip $(V)),)
|
||||
E = @echo
|
||||
Q = @
|
||||
else
|
||||
E = @\#
|
||||
Q =
|
||||
endif
|
||||
export E Q
|
||||
|
||||
PROGRAM = yait
|
||||
TARBALL = $(PROGRAM).tar
|
||||
SRC = $(wildcard *.c)
|
||||
OBJ = $(SRC:.c=.o)
|
||||
HDR = $(wildcard *.h)
|
||||
|
||||
CC = gcc
|
||||
WARNINGS = -Wall -Wstrict-prototypes
|
||||
CFLAGS = -O2 $(WARNINGS) -g
|
||||
DEFINES =
|
||||
LIBS =
|
||||
LDFLAGS =
|
||||
BINDIR = /usr/bin
|
||||
LIBDIR = /usr/lib
|
||||
|
||||
$(PROGRAM): $(OBJ) $(HDR)
|
||||
$(E) " LINK " $@
|
||||
$(Q) $(CC) $(LDFLAGS) $(DEFINES) -o $@ $(OBJ) $(LIBS)
|
||||
|
||||
clean:
|
||||
$(E) " CLEAN"
|
||||
$(Q) rm -f $(PROGRAM) $(OBJ)
|
||||
|
||||
install: $(PROGRAM)
|
||||
cp $(PROGRAM) ${BINDIR}
|
||||
|
||||
release: $(PROGRAM)
|
||||
tar cvf $(TARBALL) $(SRC) $(HDR) Makefile README
|
||||
|
||||
.c.o:
|
||||
$(E) " CC " $@
|
||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
|
||||
install:
|
||||
cp bin/yait /usr/local/bin
|
||||
|
||||
18
edef.h
18
edef.h
@@ -1,18 +0,0 @@
|
||||
/* edef.h
|
||||
*
|
||||
* Global variable definition
|
||||
*
|
||||
* written by vx-clutch
|
||||
*/
|
||||
|
||||
#ifndef EDEF_H_
|
||||
#define EDEF_H_
|
||||
|
||||
/* Initialized global external declarations. */
|
||||
|
||||
extern int git;
|
||||
|
||||
/* Other constants declarations */
|
||||
enum { SINGLE, FULL };
|
||||
|
||||
#endif /* EDEF_H_ */
|
||||
18
estruct.h
18
estruct.h
@@ -1,18 +0,0 @@
|
||||
#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 */
|
||||
|
||||
#define DEFAULT_GIT 0 /* Default git state */
|
||||
|
||||
/* Internal constants */
|
||||
|
||||
#define NPAT 128
|
||||
|
||||
#endif /* ESTRUCT_H_ */
|
||||
77
file.c
77
file.c
@@ -1,77 +0,0 @@
|
||||
/* file.c
|
||||
*
|
||||
* The routines in this file handle the reading, writing
|
||||
* and lookup of disk files.
|
||||
*
|
||||
* 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 "estruct.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;
|
||||
}
|
||||
8
file.h
8
file.h
@@ -1,8 +0,0 @@
|
||||
#ifndef FILE_H_
|
||||
#define FILE_H_
|
||||
|
||||
int ffwrite(char *path, char *fmt, ...);
|
||||
int fmkdir(char *path, ...);
|
||||
int ffexist(char *fmt, ...);
|
||||
|
||||
#endif /* FILE_H_ */
|
||||
79
full.c
79
full.c
@@ -1,79 +0,0 @@
|
||||
/* full.c
|
||||
*
|
||||
* Init to be called before project creation.
|
||||
*
|
||||
* written by vx-clutch
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "file.h"
|
||||
#include "full.h"
|
||||
#include "usage.h"
|
||||
#include "git.h"
|
||||
|
||||
int full_project_init_and_cd(char *src)
|
||||
{
|
||||
if (ffexist(src))
|
||||
die("%s already exists", src);
|
||||
|
||||
fmkdir(src);
|
||||
if (chdir(src))
|
||||
die("could not cd into %s", src);
|
||||
|
||||
// TODO(vx-clutch): Take in interactive arguments all at once
|
||||
ffwrite("README", "\
|
||||
+--------------------+\n\
|
||||
| package/Author 1.0 |\n\
|
||||
+--------------------+\n\
|
||||
\n\
|
||||
A project that does a thing 'well'.\n\
|
||||
\n\
|
||||
%s was written by ME!!!\n\
|
||||
\n\
|
||||
Copyright Notices:\n\
|
||||
\n\
|
||||
%s 1.0 (c) Copyright 2026 Author. \n\
|
||||
Reference the COPYING file for detailed information\n\
|
||||
\n\
|
||||
\n\
|
||||
WHAT IS package/Author?\n\
|
||||
\n\
|
||||
package/Author 1.0 is an optionated C and SH project generator. For C project\n\
|
||||
generation is produces a similar layout to the source of this project. On\n\
|
||||
SH it generates a shell script with useful useful scaffolding for a\n\
|
||||
script.\n\
|
||||
\n\
|
||||
\n\
|
||||
WHAT IS NEW\n\
|
||||
\n\
|
||||
Features:\n\
|
||||
\n\
|
||||
o This is the inital commit, EVERYTHING is new!\n\
|
||||
\n\
|
||||
Bug fixes - not very interesting:\n\
|
||||
\n\
|
||||
o None\n\
|
||||
\n\
|
||||
Something is gone:\n\
|
||||
\n\
|
||||
o None\n\
|
||||
\n\
|
||||
HOW TO INSTALL package/Author?\n\
|
||||
\n\
|
||||
o UNIX: Look at estruct.h, do a 'make', test the program, 'make install'.\n\
|
||||
\n\
|
||||
\n\
|
||||
ACKNOWLEDGEMENTS AND STATUS\n\
|
||||
\n\
|
||||
This project's file strucutre, file format, and certain contents are\n\
|
||||
derived from uEmacs/PK 4.0 specifically from the Linux Torvalds\n\
|
||||
distribution on GitHub. The README on from uEmacs/PK 4.0 has greater and\n\
|
||||
more accurate attributions, if you desire.\n\
|
||||
\n\
|
||||
LATE MODIFIED DATE", src, src);
|
||||
|
||||
ginit(); /* initialize a git repository */
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
full.h
6
full.h
@@ -1,6 +0,0 @@
|
||||
#ifndef FULL_H_
|
||||
#define FULL_H_
|
||||
|
||||
int full_project_init_and_cd(char *src);
|
||||
|
||||
#endif /* FULL_H_ */
|
||||
17
git.c
17
git.c
@@ -1,17 +0,0 @@
|
||||
/* git.c
|
||||
*
|
||||
* Routines for initilizing a git repository
|
||||
*
|
||||
* written by vx-clutch
|
||||
*/
|
||||
|
||||
#include "git.h"
|
||||
#include "edef.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int ginit()
|
||||
{
|
||||
if (git) return 0;
|
||||
system("git init --quiet");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#include "estruct.h"
|
||||
#include "edef.h"
|
||||
|
||||
/* initialized global definitions */
|
||||
|
||||
int git = DEFAULT_GIT;
|
||||
70
input.c
70
input.c
@@ -1,70 +0,0 @@
|
||||
/* 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 yesno(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;
|
||||
}
|
||||
}
|
||||
9
input.h
9
input.h
@@ -1,9 +0,0 @@
|
||||
#ifndef INPUT_H_
|
||||
#define INPUT_H_
|
||||
|
||||
enum { TRUE, FALSE, GUARANTEE };
|
||||
|
||||
char *getstring(char *fmt, ...);
|
||||
int yesno(char *fmt, ...);
|
||||
|
||||
#endif /* INPUT_H_ */
|
||||
83
main.c
83
main.c
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "edef.h"
|
||||
#include "proj.h"
|
||||
#include "shell.h"
|
||||
#include "usage.h"
|
||||
#include "version.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(" -S enable shell creation mode as a full project\n", stdout);
|
||||
fputs(" --git initialize a git repository\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 shell_mode = 0;
|
||||
char *package = NULL;
|
||||
int carg;
|
||||
|
||||
if (argc < 2)
|
||||
die("not enough arguments");
|
||||
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "--help") == 0)
|
||||
usage(EXIT_SUCCESS);
|
||||
else if (strcmp(argv[1], "--version") == 0) {
|
||||
version();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
for (carg = 1; carg < argc; ++carg) {
|
||||
if (argv[carg][0] == '-') {
|
||||
if (argv[carg][1] == 's')
|
||||
shell_mode = SINGLE;
|
||||
else if (argv[carg][1] == 'S')
|
||||
shell_mode = FULL;
|
||||
else if (strcmp(argv[carg], "--git"))
|
||||
git = 1;
|
||||
else
|
||||
die("unknown option");
|
||||
} else
|
||||
package = argv[carg];
|
||||
}
|
||||
|
||||
if (!package)
|
||||
die("no package name provided");
|
||||
|
||||
if (shell_mode)
|
||||
makeshell(package, shell_mode);
|
||||
else
|
||||
makeproj(package);
|
||||
|
||||
return 0;
|
||||
}
|
||||
264
proj.c
264
proj.c
@@ -1,264 +0,0 @@
|
||||
/* proj.c
|
||||
*
|
||||
* The routines in this file generater an
|
||||
* opinionated C project.
|
||||
*
|
||||
* written by vx-clutch
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "estruct.h"
|
||||
#include "wrapper.h"
|
||||
#include "file.h"
|
||||
#include "input.h"
|
||||
#include "proj.h"
|
||||
#include "usage.h"
|
||||
#include "util.h"
|
||||
#include "version.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);
|
||||
|
||||
int year = getyear();
|
||||
char *author = getstring("Author");
|
||||
char *description = getstring("Description");
|
||||
|
||||
ffwrite("main.c", "\
|
||||
/*\n\
|
||||
* main.c\n\
|
||||
*\n\
|
||||
* %s/%s 1.0\n\
|
||||
*\n\
|
||||
* Copying policy\n\
|
||||
*\n\
|
||||
* %s 1.0 can be copied and distributed freely for any\n\
|
||||
* non-commercial purposes. %s 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\
|
||||
#include \"version.h\"\n\
|
||||
#include \"estruct.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\
|
||||
puts(MESSAGE);\n\
|
||||
\n\
|
||||
return 0;\n\
|
||||
}", src, author, src, src);
|
||||
|
||||
size_t len = strlen(src) + 1 + strlen(author) + 6; /* account for " 1.0 " */
|
||||
char *pad = xmalloc(len + 1);
|
||||
memset(pad, '-', len);
|
||||
pad[len] = '\0';
|
||||
ffwrite("README", "\
|
||||
+%s+\n\
|
||||
| %s/%s 1.0 |\n\
|
||||
+%s+\n\
|
||||
\n\
|
||||
%s\n\
|
||||
\n\
|
||||
%s was written by %s\n\
|
||||
\n\
|
||||
Copyright Notices:\n\
|
||||
\n\
|
||||
%s 1.0 (c) Copyright %d %s\n\
|
||||
\n\
|
||||
Reference the COPYING file for detailed information\n\
|
||||
\n\
|
||||
\n\
|
||||
WHAT IS %s/%s?\n\
|
||||
\n\
|
||||
%s/%s 1.0 %s\n\
|
||||
\n\
|
||||
\n\
|
||||
WHAT IS NEW\n\
|
||||
\n\
|
||||
Features:\n\
|
||||
\n\
|
||||
o This is the first version, EVERYTHING is new!\n\
|
||||
\n\
|
||||
Bug fixes - not very interesting:\n\
|
||||
\n\
|
||||
o None\n\
|
||||
\n\
|
||||
Something is gone:\n\
|
||||
\n\
|
||||
o None\n\
|
||||
\n\
|
||||
HOW TO INSTALL %s/%s?\n\
|
||||
\n\
|
||||
o UNIX: Look at estruct.h, do a 'make', test the program, 'make install'.\n\
|
||||
\n\
|
||||
\n\
|
||||
ACKNOWLEDGEMENTS AND STATUS\n\
|
||||
\n\
|
||||
This project's file strucutre, file format, and certain contents are\n\
|
||||
derived from uEmacs/PK 4.0 specifically from the Linux Torvalds\n\
|
||||
distribution on GitHub. The README on from uEmacs/PK 4.0 has greater and\n\
|
||||
more accurate attributions, if you desire.\n\
|
||||
\n\
|
||||
%s was generated using %s %s\n\
|
||||
\n\
|
||||
LAST MODIFED DATE\
|
||||
",
|
||||
pad,
|
||||
src, author,
|
||||
pad,
|
||||
description,
|
||||
src, author,
|
||||
src, year, author,
|
||||
src, author,
|
||||
src, author, description,
|
||||
src, author,
|
||||
src, PROGRAM_NAME_LONG, VERSION);
|
||||
|
||||
ffwrite("version.h", "\
|
||||
#ifndef VERSION_H_\n\
|
||||
#define VERSION_H_\n\
|
||||
\n\
|
||||
#define PROGRAM_NAME \"%s\"\n\
|
||||
#define PROGRAM_NAME_LONG \"%s/%s\"\n\
|
||||
\n\
|
||||
#define VERSION \"1.0.0\"\n\
|
||||
\n\
|
||||
/* Print the version string. */\n\
|
||||
void version(void);\n\
|
||||
\n\
|
||||
#endif /* VERSION_H_ */", src, src, author);
|
||||
ffwrite("version.c", "\
|
||||
#include <stdio.h>\n\
|
||||
#include \"version.h\"\n\
|
||||
\n\
|
||||
void version(void)\n\
|
||||
{\n\
|
||||
printf(\"%%s version %%s\\n\", PROGRAM_NAME_LONG, VERSION);\n\
|
||||
}");
|
||||
|
||||
ffwrite("Makefile", "\
|
||||
# Makefile for %s\n\
|
||||
\n\
|
||||
# Make the build silent by default\n\
|
||||
V =\n\
|
||||
\n\
|
||||
ifeq ($(strip $(V)),)\n\
|
||||
E = @echo\n\
|
||||
Q = @\n\
|
||||
else\n\
|
||||
E = @\\#\n\
|
||||
Q =\n\
|
||||
endif\n\
|
||||
export E Q\n\
|
||||
\n\
|
||||
PROGRAM = %s\n\
|
||||
TARBALL = $(PROGRAM).tar\n\
|
||||
SRC = $(wildcard *.c)\n\
|
||||
OBJ = $(SRC:.c=.o)\n\
|
||||
HDR = $(wildcard *.h)\n\
|
||||
\n\
|
||||
CC = gcc\n\
|
||||
WARNINGS = -Wall -Wstrict-prototypes\n\
|
||||
CFLAGS = -O2 $(WARNINGS) -g\n\
|
||||
DEFINES =\n\
|
||||
LIBS =\n\
|
||||
LDFLAGS =\n\
|
||||
BINDIR = /usr/bin\n\
|
||||
LIBDIR = /usr/lib\n\
|
||||
\n\
|
||||
$(PROGRAM): $(OBJ) $(HDR)\n\
|
||||
$(E) \" LINK \" $@\n\
|
||||
$(Q) $(CC) $(LDFLAGS) $(DEFINES) -o $@ $(OBJ) $(LIBS)\n\
|
||||
\n\
|
||||
clean:\n\
|
||||
$(E) \" CLEAN\"\n\
|
||||
$(Q) rm -f $(PROGRAM) $(OBJ)\n\
|
||||
\n\
|
||||
install: $(PROGRAM)\n\
|
||||
cp $(PROGRAM) ${BINDIR}\n\
|
||||
\n\
|
||||
release: $(PROGRAM)\n\
|
||||
tar cvf $(TARBALL) $(SRC) $(HDR) Makefile README\n\
|
||||
\n\
|
||||
.c.o:\n\
|
||||
$(E) \" CC \" $@\n\
|
||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@", src, src);
|
||||
|
||||
ffwrite("usage.h", "\
|
||||
#ifndef USAGE_H_\n\
|
||||
#define USAGE_H_\n\
|
||||
\n\
|
||||
void die(const char* err, ...);\n\
|
||||
\n\
|
||||
#endif /* USAGE_H_ */");
|
||||
ffwrite("usage.c", "\
|
||||
#include \"usage.h\"\n\
|
||||
\n\
|
||||
#include <stdarg.h>\n\
|
||||
#include <stdio.h>\n\
|
||||
#include <stdlib.h>\n\
|
||||
\n\
|
||||
static void report(const char* prefix, const char *err, va_list params)\n\
|
||||
{\n\
|
||||
char msg[4096];\n\
|
||||
vsnprintf(msg, sizeof(msg), err, params);\n\
|
||||
fprintf(stderr, \"%%s%%s\\n\", prefix, msg);\n\
|
||||
}\n\
|
||||
\n\
|
||||
void die(const char* err, ...)\n\
|
||||
{\n\
|
||||
va_list params;\n\
|
||||
\n\
|
||||
va_start(params, err);\n\
|
||||
report(\"fatal: \", err, params);\n\
|
||||
va_end(params);\n\
|
||||
exit(128);\n\
|
||||
}");
|
||||
|
||||
ffwrite("estruct.h", "\
|
||||
#ifndef ESTRUCT_H_\n\
|
||||
#define ESTRUCT_H_\n\
|
||||
\n\
|
||||
/* Configuration options */\n\
|
||||
\n\
|
||||
#define MESSAGE \"Hello, World!\" /* Default greeting */\n\
|
||||
\n\
|
||||
#endif /* ESTRUCT_H_ */");
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
proj.h
6
proj.h
@@ -1,6 +0,0 @@
|
||||
#ifndef PROJ_H_
|
||||
#define PROJ_H_
|
||||
|
||||
int makeproj(char *src);
|
||||
|
||||
#endif /* PROJ_H_ */
|
||||
16
scripts/git-hooks/pre-commit
Normal file
16
scripts/git-hooks/pre-commit
Normal file
@@ -0,0 +1,16 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# Run pre commit checks on bin/yait. Requires `shellcheck` as well as a POSIX
|
||||
# shell (duh)
|
||||
|
||||
script_path="./bin/yait"
|
||||
|
||||
if git diff --cached --name-only | grep -q "$script_path"; then
|
||||
if ! shellcheck "$script_path"; then
|
||||
echo "[$0]: Syntax errors found in $script_path. Commit aborted."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[$0] All Tests Pass"
|
||||
exit 0
|
||||
77
shell.c
77
shell.c
@@ -1,77 +0,0 @@
|
||||
/* 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 "full.h"
|
||||
#include "edef.h"
|
||||
#include "input.h"
|
||||
#include "shell.h"
|
||||
#include "single.h"
|
||||
#include "usage.h"
|
||||
|
||||
int makeshell(char *src, int complexity) {
|
||||
char *license = LICENSE;
|
||||
|
||||
if (complexity == SINGLE)
|
||||
single_init(src);
|
||||
else if (complexity == FULL) {
|
||||
full_project_init_and_cd(src);
|
||||
}
|
||||
else
|
||||
die("invalid state! shell.c:%d", __LINE__);
|
||||
|
||||
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, 2026, "fSD", description);
|
||||
|
||||
struct stat st;
|
||||
if (stat(src, &st) == 0)
|
||||
chmod(src, st.st_mode | S_IXUSR | S_IXGRP | S_IXOTH);
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
shell.h
6
shell.h
@@ -1,6 +0,0 @@
|
||||
#ifndef SHELL_H_
|
||||
#define SHELL_H_
|
||||
|
||||
int makeshell(char *src, int complexity);
|
||||
|
||||
#endif /* SHELL_H_ */
|
||||
20
single.c
20
single.c
@@ -1,20 +0,0 @@
|
||||
/* single.c
|
||||
*
|
||||
* Init to be called before single file
|
||||
* creation as a final product.
|
||||
*
|
||||
* written by vx-clutch
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "file.h"
|
||||
#include "single.h"
|
||||
#include "usage.h"
|
||||
|
||||
int single_init(char *src)
|
||||
{
|
||||
if (ffexist(src))
|
||||
die("%s already exists", src);
|
||||
return 0;
|
||||
}
|
||||
6
single.h
6
single.h
@@ -1,6 +0,0 @@
|
||||
#ifndef SINGLE_H_
|
||||
#define SINGLE_H_
|
||||
|
||||
int single_init(char *src);
|
||||
|
||||
#endif /* SINGLE_H_ */
|
||||
22
usage.c
22
usage.c
@@ -1,22 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
6
usage.h
6
usage.h
@@ -1,6 +0,0 @@
|
||||
#ifndef USAGE_H_
|
||||
#define USAGE_H_
|
||||
|
||||
void die(const char* err, ...);
|
||||
|
||||
#endif /* USAGE_H_ */
|
||||
10
util.c
10
util.c
@@ -1,10 +0,0 @@
|
||||
#include "util.h"
|
||||
#include <time.h>
|
||||
|
||||
int getyear()
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
return t->tm_year + 1900;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "version.h"
|
||||
|
||||
void version(void)
|
||||
{
|
||||
printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION);
|
||||
}
|
||||
12
version.h
12
version.h
@@ -1,12 +0,0 @@
|
||||
#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_ */
|
||||
13
wrapper.c
13
wrapper.c
@@ -1,13 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wrapper.h"
|
||||
#include "usage.h"
|
||||
|
||||
void *xmalloc(size_t size)
|
||||
{
|
||||
void *ret = malloc(size);
|
||||
if (!ret)
|
||||
die("memory exhausted");
|
||||
return ret;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef WRAPPER_H_
|
||||
#define WRAPPER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void *xmalloc(size_t size);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user