Compare commits
19 Commits
600996c832
...
refactor
| Author | SHA1 | Date | |
|---|---|---|---|
| fc2e477665 | |||
| 82635759a7 | |||
| 52c0d05889 | |||
| e42881c4d1 | |||
|
|
cd6cf9ff4f | ||
| 6a50590393 | |||
| 27c248c9bb | |||
| f764bc6759 | |||
|
|
22242dc532 | ||
|
|
abe6fb68c1 | ||
|
|
7c63847667 | ||
|
|
2e82682318 | ||
|
|
51f30fdd51 | ||
|
|
fc6a5f9412 | ||
|
|
1db2803e95 | ||
|
|
2214b85e16 | ||
| 1c9d62dabf | |||
| bfefb223f1 | |||
| 561753df41 |
108
.clang-format
108
.clang-format
@@ -1,108 +0,0 @@
|
|||||||
---
|
|
||||||
AccessModifierOffset: -4
|
|
||||||
AlignAfterOpenBracket: Align
|
|
||||||
AlignConsecutiveAssignments: false
|
|
||||||
AlignConsecutiveDeclarations: false
|
|
||||||
AlignEscapedNewlines: Left
|
|
||||||
AlignOperands: true
|
|
||||||
AlignTrailingComments: false
|
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
|
||||||
AllowShortBlocksOnASingleLine: false
|
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
|
||||||
AllowShortFunctionsOnASingleLine: None
|
|
||||||
AllowShortIfStatementsOnASingleLine: false
|
|
||||||
AllowShortLoopsOnASingleLine: false
|
|
||||||
AlwaysBreakAfterDefinitionReturnType: None
|
|
||||||
AlwaysBreakAfterReturnType: None
|
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
|
||||||
AlwaysBreakTemplateDeclarations: false
|
|
||||||
BinPackArguments: true
|
|
||||||
BinPackParameters: true
|
|
||||||
BraceWrapping:
|
|
||||||
AfterClass: false
|
|
||||||
AfterControlStatement: false
|
|
||||||
AfterEnum: false
|
|
||||||
AfterFunction: true
|
|
||||||
AfterNamespace: true
|
|
||||||
AfterObjCDeclaration: false
|
|
||||||
AfterStruct: false
|
|
||||||
AfterUnion: false
|
|
||||||
AfterExternBlock: false
|
|
||||||
BeforeCatch: false
|
|
||||||
BeforeElse: false
|
|
||||||
IndentBraces: false
|
|
||||||
SplitEmptyFunction: true
|
|
||||||
SplitEmptyRecord: true
|
|
||||||
SplitEmptyNamespace: true
|
|
||||||
BreakBeforeBinaryOperators: None
|
|
||||||
BreakBeforeBraces: Custom
|
|
||||||
BreakBeforeInheritanceComma: false
|
|
||||||
BreakBeforeTernaryOperators: false
|
|
||||||
BreakConstructorInitializersBeforeComma: false
|
|
||||||
BreakConstructorInitializers: BeforeComma
|
|
||||||
BreakAfterJavaFieldAnnotations: false
|
|
||||||
BreakStringLiterals: false
|
|
||||||
ColumnLimit: 80
|
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
|
||||||
CompactNamespaces: false
|
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
|
||||||
ConstructorInitializerIndentWidth: 8
|
|
||||||
ContinuationIndentWidth: 8
|
|
||||||
Cpp11BracedListStyle: false
|
|
||||||
DerivePointerAlignment: false
|
|
||||||
DisableFormat: false
|
|
||||||
ExperimentalAutoDetectBinPacking: false
|
|
||||||
FixNamespaceComments: false
|
|
||||||
|
|
||||||
IncludeBlocks: Preserve
|
|
||||||
IncludeCategories:
|
|
||||||
- Regex: '.*'
|
|
||||||
Priority: 1
|
|
||||||
IncludeIsMainRegex: '(Test)?$'
|
|
||||||
IndentCaseLabels: false
|
|
||||||
IndentGotoLabels: false
|
|
||||||
IndentPPDirectives: None
|
|
||||||
IndentWidth: 8
|
|
||||||
IndentWrappedFunctionNames: false
|
|
||||||
JavaScriptQuotes: Leave
|
|
||||||
JavaScriptWrapImports: true
|
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
|
||||||
MacroBlockBegin: ''
|
|
||||||
MacroBlockEnd: ''
|
|
||||||
MaxEmptyLinesToKeep: 1
|
|
||||||
NamespaceIndentation: None
|
|
||||||
ObjCBinPackProtocolList: Auto
|
|
||||||
ObjCBlockIndentWidth: 8
|
|
||||||
ObjCSpaceAfterProperty: true
|
|
||||||
ObjCSpaceBeforeProtocolList: true
|
|
||||||
|
|
||||||
PenaltyBreakAssignment: 10
|
|
||||||
PenaltyBreakBeforeFirstCallParameter: 30
|
|
||||||
PenaltyBreakComment: 10
|
|
||||||
PenaltyBreakFirstLessLess: 0
|
|
||||||
PenaltyBreakString: 10
|
|
||||||
PenaltyExcessCharacter: 100
|
|
||||||
PenaltyReturnTypeOnItsOwnLine: 60
|
|
||||||
|
|
||||||
PointerAlignment: Right
|
|
||||||
ReflowComments: false
|
|
||||||
SortIncludes: false
|
|
||||||
SortUsingDeclarations: false
|
|
||||||
SpaceAfterCStyleCast: false
|
|
||||||
SpaceAfterTemplateKeyword: true
|
|
||||||
SpaceBeforeAssignmentOperators: true
|
|
||||||
SpaceBeforeCtorInitializerColon: true
|
|
||||||
SpaceBeforeInheritanceColon: true
|
|
||||||
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
|
||||||
SpaceBeforeRangeBasedForLoopColon: true
|
|
||||||
SpaceInEmptyParentheses: false
|
|
||||||
SpacesBeforeTrailingComments: 1
|
|
||||||
SpacesInAngles: false
|
|
||||||
SpacesInContainerLiterals: false
|
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
SpacesInParentheses: false
|
|
||||||
SpacesInSquareBrackets: false
|
|
||||||
Standard: Cpp03
|
|
||||||
TabWidth: 8
|
|
||||||
UseTab: Always
|
|
||||||
...
|
|
||||||
7
.clangd
7
.clangd
@@ -1,7 +0,0 @@
|
|||||||
CompileFlags:
|
|
||||||
Add: [-x, c, -std=c2x]
|
|
||||||
|
|
||||||
Diagnostics:
|
|
||||||
ClangTidy:
|
|
||||||
Add: [clang-diagnostic-*]
|
|
||||||
Remove: []
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,6 +1,2 @@
|
|||||||
bin/
|
yait
|
||||||
build/
|
|
||||||
*.o
|
*.o
|
||||||
config.mak
|
|
||||||
config.status
|
|
||||||
*cache*
|
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "gcklib"]
|
|
||||||
path = gcklib
|
|
||||||
url = https://github.com/gck-org/gcklib
|
|
||||||
11
AUTHORS
11
AUTHORS
@@ -1,11 +0,0 @@
|
|||||||
Authors of GCK yait.
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
Also see the THANKS files.
|
|
||||||
|
|
||||||
vx-clutch
|
|
||||||
23
COPYING
23
COPYING
@@ -1,6 +1,9 @@
|
|||||||
BSD 3-Clause License
|
Copyright (c) 2025 fSD version 1
|
||||||
|
|
||||||
Copyright (c) 2025, GCK
|
This document is intended "as is", without modifications.
|
||||||
|
|
||||||
|
The binary and source code that this file is associated with and distributed
|
||||||
|
with is licensed under the following terms and conditions.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
@@ -12,10 +15,6 @@ modification, are permitted provided that the following conditions are met:
|
|||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
@@ -26,3 +25,15 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
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
|
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.
|
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.".
|
||||||
|
|||||||
54
INSTALL
54
INSTALL
@@ -1,54 +0,0 @@
|
|||||||
Installation Instructions
|
|
||||||
*************************
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved. This file is offered as-is,
|
|
||||||
without warranty of any kind.
|
|
||||||
|
|
||||||
Basic Installation
|
|
||||||
==================
|
|
||||||
|
|
||||||
Briefly, the shell command `./configure && make && make install` should
|
|
||||||
configure, build, and install this package. The following more-detailed
|
|
||||||
instruction are generic; see the `README` file for instructions specific to
|
|
||||||
this package.
|
|
||||||
|
|
||||||
The `configure` shell script attempts to guess correct values for
|
|
||||||
various system-dependent variables used during compilation. It uses
|
|
||||||
those values within a `Makefile` to build for that POSIX system as
|
|
||||||
defined by `config.mak` which was generated by `configure`.
|
|
||||||
|
|
||||||
Compilers and Options
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Some systems require unusal options for compilation or linking that
|
|
||||||
the `configure` script does not know about. If you run into an issue
|
|
||||||
run `./configure --help` to figure out what you can do to fix the
|
|
||||||
behavoir.
|
|
||||||
|
|
||||||
Installation Names
|
|
||||||
==================
|
|
||||||
|
|
||||||
By default, `make install` installs the package's command under
|
|
||||||
`/usr/local/bin`. You can specify an installation prefix other than `/usr/local/`
|
|
||||||
by giving `configure` the option `--prefix=PREFIX` to `configure`, the package uses
|
|
||||||
PREFIX as the prefix for installation programs and libraries.
|
|
||||||
Documentation and other data files still use the regular prefix.
|
|
||||||
|
|
||||||
`configure` Invokation
|
|
||||||
======================
|
|
||||||
|
|
||||||
`configure` recongizes the following options to control its operations.
|
|
||||||
|
|
||||||
`--help`
|
|
||||||
Prints a summary of all the options to `configure`, and exits.
|
|
||||||
`--prefix=PREFIX`
|
|
||||||
Sets the installation prefix.
|
|
||||||
`CFLAGS`
|
|
||||||
Sets the flags used during compilation.
|
|
||||||
|
|
||||||
`configure` also accepts some other options. Run `configure --help` for more
|
|
||||||
details
|
|
||||||
93
Makefile
93
Makefile
@@ -1,69 +1,46 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# Makefile for yait
|
||||||
PACKAGE := yait
|
|
||||||
|
|
||||||
SRCS := $(wildcard src/*.c) $(wildcard lib/*.c)
|
# Make the build silent by default
|
||||||
OBJS := $(patsubst %.c,build/obj/%.o,$(SRCS))
|
V =
|
||||||
|
|
||||||
BIN := bin/$(PACKAGE)
|
ifeq ($(strip $(V)),)
|
||||||
|
E = @echo
|
||||||
COMMIT := $(shell git rev-list --count --all)
|
Q = @
|
||||||
FLAGS := -I. --std=c2x -pedantic -Ibuild/include
|
|
||||||
|
|
||||||
VERSION := $(shell git describe --tags --always --dirty)
|
|
||||||
TARBALL := $(PACKAGE)-$(VERSION).tar.gz
|
|
||||||
RELEASE_FILES := doc src lib COPYING AUTHORS README $(PACKAGE).1 INSTALL Makefile configure config.h
|
|
||||||
|
|
||||||
-include config.mak
|
|
||||||
|
|
||||||
ifeq ($(wildcard config.mak),)
|
|
||||||
all:
|
|
||||||
@echo "File config.mak not found, run configure"
|
|
||||||
@exit 1
|
|
||||||
else
|
else
|
||||||
|
E = @\#
|
||||||
all: $(BIN)
|
Q =
|
||||||
|
|
||||||
bin:
|
|
||||||
@mkdir -p bin
|
|
||||||
|
|
||||||
build/obj:
|
|
||||||
@mkdir -p build/obj/src
|
|
||||||
@mkdir -p build/obj/lib
|
|
||||||
|
|
||||||
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 $@
|
|
||||||
|
|
||||||
|
|
||||||
install: $(BIN)
|
|
||||||
cp $(BIN) $(PREFIX)
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
export E Q
|
||||||
|
|
||||||
doc:
|
PROGRAM = yait
|
||||||
@$(MAKE) -C doc all
|
TARBALL = $(PROGRAM).tar
|
||||||
|
SRC = $(wildcard *.c)
|
||||||
|
OBJ = $(SRC:.c=.o)
|
||||||
|
HDR = $(wildcard *.h)
|
||||||
|
|
||||||
uninstall:
|
CC = gcc
|
||||||
@$(RM) $(PREFIX)$(PACKAGE)
|
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:
|
clean:
|
||||||
@echo " CLEAN"
|
$(E) " CLEAN"
|
||||||
@$(RM) -r bin
|
$(Q) rm -f $(PROGRAM) $(OBJ)
|
||||||
@$(RM) -r build
|
|
||||||
@$(MAKE) -C doc clean --no-print-directory
|
|
||||||
|
|
||||||
distclean: clean
|
install: $(PROGRAM)
|
||||||
@$(RM) config.mak config.status
|
cp $(PROGRAM) ${BINDIR}
|
||||||
@$(RM) $(TARBALL)
|
|
||||||
|
|
||||||
release: distclean all
|
release: $(PROGRAM)
|
||||||
tar -czf $(TARBALL) $(RELEASE_FILES)
|
tar cvf $(TARBALL) $(SRC) $(HDR) Makefile README
|
||||||
|
|
||||||
test:
|
.c.o:
|
||||||
@$(BIN) --version > /dev/null 2>&1 && echo "intact" || echo "defective"
|
$(E) " CC " $@
|
||||||
|
$(Q) $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
|
||||||
.PHONY: all clean distclean install uninstall doc
|
|
||||||
|
|||||||
68
README
68
README
@@ -1,29 +1,51 @@
|
|||||||
This is the README file for the GCK yait distribution.
|
+--------------+
|
||||||
yait is an optionated C project generator
|
| yait/fSD 1.0 |
|
||||||
|
+--------------+
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
Highly opinionated C and SH project generator
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
yait was written by vx-clutch
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
See the files ./INSTALL* for building and installation instructions.
|
Copyright Notices:
|
||||||
|
|
||||||
Bug reports:
|
yait 1.0 (c) Copyright 2025 fSD.
|
||||||
Please include enough information for the maintainers to reproduce the
|
|
||||||
problem. Generally speaking, that means:
|
|
||||||
- the contents of any input files necessary to reproduce the bug
|
|
||||||
and command line invocations of the program(s) involved (crucial!).
|
|
||||||
- a description of the problem and any samples of the erroneous output.
|
|
||||||
- the version number of the program(s) involved (use --version).
|
|
||||||
- hardware, operating system, and compiler versions (uname -a).
|
|
||||||
- unusual options you gave to configure, if any (see config.mak).
|
|
||||||
- anything else that you think would be helpful.
|
|
||||||
|
|
||||||
See README-dev for information on the development environment -- any
|
Reference the COPYING file for detailed information
|
||||||
interested parties are welcome. If you're a programmer and wish to
|
|
||||||
contribute, this should get you started. If you're not a programmer,
|
|
||||||
your help in writing test cases, checking documentation against the
|
|
||||||
implementation, etc., would still be very much appreciated.
|
|
||||||
|
|
||||||
GCK yait is free software. See the file COPYING for copying conditions.
|
|
||||||
|
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 scaffolding for a script. For
|
||||||
|
more detailed useage compile the program for your system and run with the
|
||||||
|
`--help` option.
|
||||||
|
|
||||||
|
|
||||||
|
WHAT IS NEW
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
o This is the first version, EVERYTHING is new!
|
||||||
|
|
||||||
|
Bug fixes - not very interesting:
|
||||||
|
|
||||||
|
o None
|
||||||
|
|
||||||
|
Something is gone:
|
||||||
|
|
||||||
|
o None
|
||||||
|
|
||||||
|
HOW TO INSTALL yait/fSD?
|
||||||
|
|
||||||
|
o UNIX: Look at estruct.h, do a 'make', test the program, 'make install'.
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
November 12, 2025
|
||||||
|
|||||||
112
README-dev
112
README-dev
@@ -1,112 +0,0 @@
|
|||||||
This README.dev file describes the development environment.
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
Notice
|
|
||||||
------
|
|
||||||
|
|
||||||
This documentation is standard across all GCK package and is not specified per
|
|
||||||
package; however, this is the defacto standard for most packages. The only
|
|
||||||
place where this commonly differs is in non-binary or library packages.
|
|
||||||
|
|
||||||
|
|
||||||
Build system
|
|
||||||
------------
|
|
||||||
|
|
||||||
This distribution uses a GNU autotools-like build system. This is made up of a
|
|
||||||
configure script, and a Makefile. The configure script detects a C23 compiler
|
|
||||||
on the system and sets any program flags: debug, release, custom. The Makefile
|
|
||||||
builds the binary based on the output [config.mak] of the configure script.
|
|
||||||
|
|
||||||
|
|
||||||
Building
|
|
||||||
--------
|
|
||||||
|
|
||||||
To build this distribution you first must run the configure script. This
|
|
||||||
outputs a config.mak file that will be used in the Make step. Then run make;
|
|
||||||
this builds the objects into build/ and the binary into bin/.
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The configuration script is used to generate a build intermediate step called
|
|
||||||
the config.mak. This file is used by the Makefile to figure out C compiler to
|
|
||||||
use, what CFLAGS and LDFLAGS to use, and where to install the binary if
|
|
||||||
requested. By default these values are gcc, the release flag set, and
|
|
||||||
/usr/local/. The configuration script supports the following flags that control
|
|
||||||
CFLAGS: --enable-debug and CFLAGS="". By default, the script uses flags for a release
|
|
||||||
build. Debug is for in-development programming and is the strictest when it
|
|
||||||
comes to warnings and other compiler output. CFLAGS="" is for custom flag
|
|
||||||
definition. For the development environment is it recommended to use the
|
|
||||||
--debug flag. Some examples of how you can run the configure script:
|
|
||||||
|
|
||||||
For default behavior:
|
|
||||||
|
|
||||||
./configure
|
|
||||||
|
|
||||||
For debug use:
|
|
||||||
|
|
||||||
./configure --enable-debug
|
|
||||||
|
|
||||||
For help text:
|
|
||||||
|
|
||||||
./configure --help
|
|
||||||
|
|
||||||
The help text is a more useage specific and up-to-date reference for
|
|
||||||
the configure script.
|
|
||||||
|
|
||||||
|
|
||||||
Makefile
|
|
||||||
--------
|
|
||||||
|
|
||||||
The GNU Makefile is used to build the final executable, clean up build
|
|
||||||
artifacts, and install the program. It checks for the config.mak which is
|
|
||||||
generated by the configure script. For a regular build, once you have the
|
|
||||||
configure script with desired flags, run:
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
||||||
This builds the executable to bin/ and build objects to build/
|
|
||||||
|
|
||||||
|
|
||||||
Suggested enviroment setup
|
|
||||||
--------------------------
|
|
||||||
It is suggested that you run do the following things to prepare you environment
|
|
||||||
for development. This is not a strict enforcement, but due to the project
|
|
||||||
structure it is a good starting point.
|
|
||||||
|
|
||||||
git pull
|
|
||||||
./tools/Cleanup
|
|
||||||
./configure --debug
|
|
||||||
./build-aux/generate-artifacts
|
|
||||||
make test
|
|
||||||
|
|
||||||
This is to ensure that you have the most up-to-date source code, and that there
|
|
||||||
are no major problems with the source control version.
|
|
||||||
|
|
||||||
The git pull is used to sync with the repository and prevent conflicts. The
|
|
||||||
cleanup is to ensure their are no lingering build artifacts. The configure with
|
|
||||||
debug enabled is for strict build flags and -ggdb. Bear is used to generated
|
|
||||||
compile_commands.json for the clang suite of tooling. Finally, run the program
|
|
||||||
to ensure the chain works.
|
|
||||||
|
|
||||||
|
|
||||||
Pre-commit checks
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Before you commit to source control ensure that done the following:
|
|
||||||
|
|
||||||
* Run the cleanup scripts
|
|
||||||
|
|
||||||
./tools/Cleanup
|
|
||||||
|
|
||||||
* Ensure that all changes were atomic
|
|
||||||
|
|
||||||
* If you compted a TODO list item check it off.
|
|
||||||
|
|
||||||
* Based on complexity, test the feature accordingly.
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
Here are most of the steps before you make a release.
|
|
||||||
|
|
||||||
* Start from a clean, up-to-date git driectory on "master":
|
|
||||||
|
|
||||||
make -k distclean || { ./configure && make distclean; }
|
|
||||||
git checkout master
|
|
||||||
git pull origin master
|
|
||||||
|
|
||||||
* Ensure that the latest stable versions of make, sh, etc.
|
|
||||||
are in your path. See the prerequisites list in README-dev
|
|
||||||
for a compile list of tools.
|
|
||||||
|
|
||||||
* Ensure that you have no uncommitted diffs. This should produce
|
|
||||||
no output:
|
|
||||||
|
|
||||||
git diff
|
|
||||||
|
|
||||||
* Ensure that you've pushed all changes that belong in the release:
|
|
||||||
|
|
||||||
git push origin master
|
|
||||||
|
|
||||||
* Pre-release testing: ensure that the following command succeeds:
|
|
||||||
|
|
||||||
make check syntax-check distcheck
|
|
||||||
|
|
||||||
Once all the builds and tests have passed,
|
|
||||||
|
|
||||||
* Run the following to create release tarballs.
|
|
||||||
|
|
||||||
make release
|
|
||||||
|
|
||||||
* Upload the tarball to the relavent distribtuion platform.
|
|
||||||
15
THANKS
15
THANKS
@@ -1,15 +0,0 @@
|
|||||||
Additional contributors to GCK yait.
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
Thanks to:
|
|
||||||
|
|
||||||
GNU hello for layout ideas.
|
|
||||||
|
|
||||||
The Linux Kernel for the code formatting guidelines.
|
|
||||||
|
|
||||||
See also the AUTHORS file.
|
|
||||||
8
TODO
8
TODO
@@ -1,8 +0,0 @@
|
|||||||
GCK yait --- TODO
|
|
||||||
|
|
||||||
Todo:
|
|
||||||
|
|
||||||
* fix 't' so that it handles names correctly and special in-file characters
|
|
||||||
* write all templates sources
|
|
||||||
|
|
||||||
end of file TODO
|
|
||||||
44
bootstrap
44
bootstrap
@@ -1,44 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Prepares the build enviroment
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0 ;;
|
|
||||||
--version) echo "$version"; exit 0 ;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
echo "$0: Bootstrapping from checked-out $(basename "$(git rev-parse --show-toplevel)") sources"
|
|
||||||
|
|
||||||
if [ ! -f .gitmodules ]; then
|
|
||||||
echo "$0: No .gitmodules file found. Skipping submodule initialization."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
git config -f .gitmodules --get-regexp path | while read -r key path; do
|
|
||||||
echo "$0: initializing submodule '$path'..."
|
|
||||||
git submodule update --init --recursive "$path"
|
|
||||||
done
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Compile wrapper for GCK distributions
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-R force re-compile everything
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information
|
|
||||||
|
|
||||||
Automatically passes arugments to 'configure'"
|
|
||||||
|
|
||||||
rebuild=
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
-R) rebuild=true ;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -f ./config.mak ] && [ -z "$rebuild" ]; then
|
|
||||||
echo "$0: reusing old 'config.mak'"
|
|
||||||
else
|
|
||||||
if [ ! -x ./configure ]; then
|
|
||||||
echo "$0: 'configure' not found or not executable" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$0: configuring $(basename "$(git rev-parse --show-toplevel)")"
|
|
||||||
./configure "$@"
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "error: configure failed" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$0: starting build"
|
|
||||||
make -j"$(nproc)"
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "error: build failed" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$0: finish"
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Generates artifacts
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ! -e "config.mak" ]; then
|
|
||||||
./configure
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p build
|
|
||||||
bear --output build/compile_commands.json -- make -B -j"$(nproc)"
|
|
||||||
10
config.h
10
config.h
@@ -1,10 +0,0 @@
|
|||||||
#ifndef CONFIG_H
|
|
||||||
#define CONFIG_H
|
|
||||||
|
|
||||||
/* Program information */
|
|
||||||
#define PROGRAM "yait"
|
|
||||||
#define AUTHORS "GCK"
|
|
||||||
#define VERSION "beta"
|
|
||||||
#define YEAR 2025
|
|
||||||
|
|
||||||
#endif
|
|
||||||
159
configure
vendored
159
configure
vendored
@@ -1,159 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Prepares the build system for GCK distributions
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--release enable release flags
|
|
||||||
--enable-debug enable debugging options
|
|
||||||
--prefix PREFIX set installation prefix
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information
|
|
||||||
|
|
||||||
Environment variables:
|
|
||||||
|
|
||||||
CC C compiler command
|
|
||||||
CFLAGS C compiler flags
|
|
||||||
|
|
||||||
Use these variables to override the choices made by 'configure'."
|
|
||||||
|
|
||||||
release=false
|
|
||||||
debug=false
|
|
||||||
prefix=/usr/local
|
|
||||||
CFLAGS=-pedantic
|
|
||||||
CC=
|
|
||||||
args_old=$@
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0 ;;
|
|
||||||
--version) echo "$version"; exit 0 ;;
|
|
||||||
--release) release=true ;;
|
|
||||||
--enable-debug) debug=true ;;
|
|
||||||
--prefix) shift; prefix=${1:?missing prefix argument} ;;
|
|
||||||
--strict) CFLAGS+="-Werror" ;;
|
|
||||||
CC=*) CC=${1#*=} ;;
|
|
||||||
CFLAGS=*) CFLAGS=${1#*=} ;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$release" = true ] && [ "$debug" = true ]; then
|
|
||||||
echo "$0: Can't set both '--release' and '--debug'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cmdexists() { command -v "$1" >/dev/null 2>&1 ; }
|
|
||||||
trycc() { [ -z "$CC" ] && cmdexists "$1" && CC=$1 ; }
|
|
||||||
|
|
||||||
if [ -z "$CC" ]; then
|
|
||||||
printf "checking for C compiler... "
|
|
||||||
trycc gcc
|
|
||||||
trycc clang
|
|
||||||
trycc cc
|
|
||||||
if [ -z "$CC" ]; then
|
|
||||||
echo "none found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
printf "%s\n" "$CC"
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "checking for git... "
|
|
||||||
if cmdexists git; then
|
|
||||||
echo "yes"
|
|
||||||
else
|
|
||||||
echo "no"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "checking whether C compiler works... "
|
|
||||||
tmpcdir="$(mktemp -d)"
|
|
||||||
tmpc="$tmpcdir/test.c"
|
|
||||||
echo "typedef int x;" > "$tmpc"
|
|
||||||
if output=$($CC $CFLAGS -c -o /dev/null "$tmpc" 2>&1); then
|
|
||||||
printf "yes\n"
|
|
||||||
else
|
|
||||||
printf "no; %s\n" "$output"
|
|
||||||
rm -rf "$tmpcdir"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
rm -rf "$tmpcdir"
|
|
||||||
|
|
||||||
if [ "$release" = true ]; then
|
|
||||||
CFLAGS="$CFLAGS -O3 -pipe -DNDEBUG -march=native -flto -s -fdata-sections -ffunction-sections -Wl,--gc-sections"
|
|
||||||
elif [ "$debug" = true ]; then
|
|
||||||
CFLAGS="$CFLAGS -O0 -ggdb -Wall -Wextra -Wpedantic -fno-omit-frame-pointer -DDEBUG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "creating config.status"
|
|
||||||
cat <<EOF > config.status
|
|
||||||
#!/bin/sh
|
|
||||||
# DO NOT MODIFY. THIS IS A AUTOGENERATED SCRIPT FROM 'configure'
|
|
||||||
#
|
|
||||||
# COMPILATION (Linux - POSIX):
|
|
||||||
# ./config.status
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# LICENSE: BSD-3-Clause
|
|
||||||
#
|
|
||||||
# Copyright (c) 2025 GCK
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
# 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
# contributors may be used to endorse or promote products derived from
|
|
||||||
# this software without specific prior written permission.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
printf "config.status: recreating config.mak... "
|
|
||||||
{
|
|
||||||
printf "PREFIX=%s\\n" "$prefix"
|
|
||||||
printf "CFLAGS=%s\\n" "$CFLAGS"
|
|
||||||
printf "CC=%s\\n" "$CC"
|
|
||||||
} > config.status
|
|
||||||
printf "done\n"
|
|
||||||
EOF
|
|
||||||
chmod u+x config.status
|
|
||||||
|
|
||||||
printf "configure: creating config.mak... "
|
|
||||||
{
|
|
||||||
printf "PREFIX=%s\n" "$prefix"
|
|
||||||
printf "CFLAGS=%s\n" "$CFLAGS"
|
|
||||||
printf "CC=%s\n" "$CC"
|
|
||||||
} > config.mak
|
|
||||||
printf "done\n"
|
|
||||||
22
doc/Makefile
22
doc/Makefile
@@ -1,22 +0,0 @@
|
|||||||
hello.info: hello.texi version.texi
|
|
||||||
@makeinfo --no-split hello.texi -o hello.info
|
|
||||||
|
|
||||||
hello.html: hello.texi version.texi
|
|
||||||
@makeinfo --no-split --html hello.texi
|
|
||||||
|
|
||||||
hello.pdf: hello.texi version.texi
|
|
||||||
@makeinfo --pdf hello.texi
|
|
||||||
|
|
||||||
hello.txt: hello.texi version.texi
|
|
||||||
@makeinfo --plaintext hello.texi -o hello.txt
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -f *.aux *.cp *.cps *.fn *.fns *.ky *.kys *.log *.pg *.pgs *.toc *.tp *.tps *.vr *.vrs
|
|
||||||
@rm -f hello.info hello.dvi hello.pdf hello.html hello.txt
|
|
||||||
|
|
||||||
install: hello.info
|
|
||||||
@install -d $(DESTDIR)$(infodir)
|
|
||||||
@install -m 644 hello.info $(DESTDIR)$(infodir)/
|
|
||||||
@install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/hello.info
|
|
||||||
|
|
||||||
.PHONY: all clean install
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
@set UPDATED 2025-01-01
|
|
||||||
@set VERSION 1.0
|
|
||||||
240
doc/yait.texi
240
doc/yait.texi
@@ -1,240 +0,0 @@
|
|||||||
\input texinfo @c -*-texinfo-*-
|
|
||||||
@c %**start of header
|
|
||||||
@setfilename hello.info
|
|
||||||
@include version.texi
|
|
||||||
@settitle GCK Hello @value{VERSION}
|
|
||||||
|
|
||||||
@c Define a new index for options.
|
|
||||||
@defcodeindex op
|
|
||||||
@c Combine everything into one index (arbitrarily chosen to be the
|
|
||||||
@c concept index).
|
|
||||||
@syncodeindex op cp
|
|
||||||
@c %**end of header
|
|
||||||
|
|
||||||
@copying
|
|
||||||
This manual is for GCK Hello (version @value{VERSION}, @value{UPDATED}),
|
|
||||||
which greets you nicely.
|
|
||||||
|
|
||||||
Copyright @copyright{} 2025 GCK.
|
|
||||||
|
|
||||||
@quotation
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
@end quotation
|
|
||||||
@end copying
|
|
||||||
|
|
||||||
@titlepage
|
|
||||||
@title GCK Hello
|
|
||||||
@subtitle for version @value{VERSION}, @value{UPDATED}
|
|
||||||
@page
|
|
||||||
@vskip 0pt plus 1filll
|
|
||||||
@insertcopying
|
|
||||||
@end titlepage
|
|
||||||
|
|
||||||
@contents
|
|
||||||
|
|
||||||
|
|
||||||
@ifnottex
|
|
||||||
@node Top
|
|
||||||
@top GCK Hello
|
|
||||||
|
|
||||||
This manual is for GCK Hello (version @value{VERSION}, @value{UPDATED}),
|
|
||||||
which greets you nicely.
|
|
||||||
@end ifnottex
|
|
||||||
|
|
||||||
@menu
|
|
||||||
* Overview:: General purpose and information.
|
|
||||||
* Sample output:: Sample output from @command{hello}.
|
|
||||||
* Invoking hello:: How to run @command{hello}.
|
|
||||||
* Reporting bugs:: Sending bug reports and feature suggestions.
|
|
||||||
* Concept index:: Index of concepts.
|
|
||||||
@end menu
|
|
||||||
|
|
||||||
|
|
||||||
@node Overview
|
|
||||||
@chapter Overview
|
|
||||||
|
|
||||||
@cindex greetings
|
|
||||||
@cindex overview
|
|
||||||
|
|
||||||
The GCK @command{hello} program produces a simple, friendly greeting.
|
|
||||||
It serves as a minimal example of a C program with proper GNU-style
|
|
||||||
structure and build system.
|
|
||||||
|
|
||||||
@cindex example program
|
|
||||||
@cindex template
|
|
||||||
This program is designed as a template and example for other projects.
|
|
||||||
It demonstrates basic C programming practices, proper project structure,
|
|
||||||
and standard GNU conventions.
|
|
||||||
|
|
||||||
@cindex features
|
|
||||||
GCK Hello has the following features:
|
|
||||||
|
|
||||||
@itemize @bullet
|
|
||||||
@item Simple and friendly greeting
|
|
||||||
@item Support for command-line arguments
|
|
||||||
@item Standard GNU-style help and version options
|
|
||||||
@item Clean, readable C source code
|
|
||||||
@item Proper project structure with build system
|
|
||||||
@end itemize
|
|
||||||
|
|
||||||
@cindex implementation
|
|
||||||
GCK Hello is implemented in C and follows standard POSIX conventions.
|
|
||||||
The program accepts command-line arguments and greets each one individually,
|
|
||||||
or prints a default greeting if no arguments are provided.
|
|
||||||
|
|
||||||
@cindex license
|
|
||||||
This program is distributed under the BSD 3-Clause License, allowing
|
|
||||||
free use, modification, and distribution with minimal restrictions.
|
|
||||||
|
|
||||||
|
|
||||||
@node Sample output
|
|
||||||
@chapter Sample output
|
|
||||||
|
|
||||||
@cindex sample output
|
|
||||||
@cindex examples
|
|
||||||
|
|
||||||
Here are some examples of running GCK Hello.
|
|
||||||
|
|
||||||
This is the output of the command @samp{hello}:
|
|
||||||
|
|
||||||
@example
|
|
||||||
Hello, World!
|
|
||||||
@end example
|
|
||||||
|
|
||||||
This is the output of the command @samp{hello Alice}:
|
|
||||||
|
|
||||||
@example
|
|
||||||
Hello, Alice!
|
|
||||||
@end example
|
|
||||||
|
|
||||||
This is the output of the command @samp{hello Alice Bob}:
|
|
||||||
|
|
||||||
@example
|
|
||||||
Hello, Alice!
|
|
||||||
Hello, Bob!
|
|
||||||
@end example
|
|
||||||
|
|
||||||
This is the output of the command @samp{hello --help}:
|
|
||||||
|
|
||||||
@example
|
|
||||||
Usage: hello [OPTION]...
|
|
||||||
Greets you nicely.
|
|
||||||
|
|
||||||
--help display this help and exit
|
|
||||||
--version display version information and exit
|
|
||||||
@end example
|
|
||||||
|
|
||||||
|
|
||||||
@node Invoking hello
|
|
||||||
@chapter Invoking @command{hello}
|
|
||||||
|
|
||||||
@cindex invoking
|
|
||||||
@cindex options
|
|
||||||
@cindex usage
|
|
||||||
@cindex help
|
|
||||||
|
|
||||||
The format for running the @command{hello} program is:
|
|
||||||
|
|
||||||
@example
|
|
||||||
hello [@var{option}]... [@var{name}]...
|
|
||||||
@end example
|
|
||||||
|
|
||||||
With no arguments, @command{hello} prints the greeting @samp{Hello, World!}.
|
|
||||||
|
|
||||||
If one or more @var{name} arguments are provided, @command{hello} greets
|
|
||||||
each name individually with @samp{Hello, @var{name}!}.
|
|
||||||
|
|
||||||
@command{hello} supports the following options:
|
|
||||||
|
|
||||||
@table @option
|
|
||||||
@item --help
|
|
||||||
@opindex --help
|
|
||||||
Print an informative help message on standard output and exit
|
|
||||||
successfully.
|
|
||||||
|
|
||||||
@item --version
|
|
||||||
@opindex --version
|
|
||||||
Print the version number and licensing information of Hello on
|
|
||||||
standard output and then exit successfully.
|
|
||||||
@end table
|
|
||||||
|
|
||||||
|
|
||||||
@node Reporting bugs
|
|
||||||
@chapter Reporting bugs
|
|
||||||
|
|
||||||
@cindex bug reporting
|
|
||||||
@cindex problems
|
|
||||||
@cindex reporting bugs
|
|
||||||
|
|
||||||
To report bugs, suggest enhancements or otherwise discuss GCK Hello,
|
|
||||||
please send electronic mail to the project maintainers.
|
|
||||||
|
|
||||||
@cindex checklist for bug reports
|
|
||||||
For bug reports, please include enough information for the maintainers
|
|
||||||
to reproduce the problem. Generally speaking, that means:
|
|
||||||
|
|
||||||
@itemize @bullet
|
|
||||||
@item The version numbers of Hello (which you can find by running
|
|
||||||
@w{@samp{hello --version}}) and any other program(s) or
|
|
||||||
manual(s) involved.
|
|
||||||
@item Hardware and operating system names and versions.
|
|
||||||
@item The contents of any input files necessary to reproduce the bug.
|
|
||||||
@item The expected behavior and/or output.
|
|
||||||
@item A description of the problem and samples of any erroneous output.
|
|
||||||
@item Options you gave to @command{configure} other than specifying
|
|
||||||
installation directories.
|
|
||||||
@item Anything else that you think would be helpful.
|
|
||||||
@end itemize
|
|
||||||
|
|
||||||
When in doubt whether something is needed or not, include it. It's
|
|
||||||
better to include too much than to leave out something important.
|
|
||||||
|
|
||||||
@cindex patches, contributing
|
|
||||||
Patches are welcome; if possible, please make them with @samp{@w{diff
|
|
||||||
-c}} and include @file{ChangeLog} entries. Please follow the existing
|
|
||||||
coding style.
|
|
||||||
|
|
||||||
|
|
||||||
@node BSD License
|
|
||||||
@appendix BSD License
|
|
||||||
|
|
||||||
This program is distributed under the BSD 3-Clause License:
|
|
||||||
|
|
||||||
@quotation
|
|
||||||
Copyright (c) 2025, GCK
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
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.
|
|
||||||
@end quotation
|
|
||||||
|
|
||||||
|
|
||||||
@node Concept index
|
|
||||||
@unnumbered Concept index
|
|
||||||
|
|
||||||
@printindex cp
|
|
||||||
|
|
||||||
@bye
|
|
||||||
14
edef.h
Normal file
14
edef.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/* edef.h
|
||||||
|
*
|
||||||
|
* Program definitions
|
||||||
|
*
|
||||||
|
* written by vx-clutch
|
||||||
|
*/
|
||||||
|
#ifndef EDEF_H_
|
||||||
|
#define EDEF_H_
|
||||||
|
|
||||||
|
enum { SINGLE = 1, FULL = 2 };
|
||||||
|
|
||||||
|
#define NPAT 4096 /* number of bytes for path buffer */
|
||||||
|
|
||||||
|
#endif /* EDEF_H_ */
|
||||||
12
estruct.h
Normal file
12
estruct.h
Normal file
@@ -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_ */
|
||||||
78
file.c
Normal file
78
file.c
Normal file
@@ -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 "edef.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
Normal file
8
file.h
Normal file
@@ -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_ */
|
||||||
76
full.c
Normal file
76
full.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
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 2025 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);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
full.h
Normal file
6
full.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef FULL_H_
|
||||||
|
#define FULL_H_
|
||||||
|
|
||||||
|
int full_project_init_and_cd(char *src);
|
||||||
|
|
||||||
|
#endif /* FULL_H_ */
|
||||||
1
gcklib
1
gcklib
Submodule gcklib deleted from b325e8005a
70
input.c
Normal file
70
input.c
Normal file
@@ -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 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
Normal file
9
input.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef INPUT_H_
|
||||||
|
#define INPUT_H_
|
||||||
|
|
||||||
|
enum { TRUE, FALSE, GUARANTEE };
|
||||||
|
|
||||||
|
char *getstring(char *fmt, ...);
|
||||||
|
int yesno(char *fmt, ...);
|
||||||
|
|
||||||
|
#endif /* INPUT_H_ */
|
||||||
214
lib/err.c
214
lib/err.c
@@ -1,214 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.err - Contains color printing functions
|
|
||||||
*
|
|
||||||
* CONFIGURATION
|
|
||||||
* #define NOCOLOR
|
|
||||||
* Force no color when printing
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "err.h"
|
|
||||||
|
|
||||||
#define RESET "\x1B[0m"
|
|
||||||
#define ERROR "\x1B[1;91m"
|
|
||||||
#define WARN "\x1B[1;95m"
|
|
||||||
#define NOTE "\x1B[1;94m"
|
|
||||||
#define HINT "\x1B[38;5;166m"
|
|
||||||
|
|
||||||
static bool err_support_color(void)
|
|
||||||
{
|
|
||||||
#ifdef NOCOLOR
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
static int cached = -1;
|
|
||||||
if (cached != -1)
|
|
||||||
return cached;
|
|
||||||
const char *term, *colorterm, *force, *nocolor;
|
|
||||||
term = getenv("TERM");
|
|
||||||
colorterm = getenv("COLORTERM");
|
|
||||||
force = getenv("FORCE_COLOR");
|
|
||||||
nocolor = getenv("NO_COLOR");
|
|
||||||
if (nocolor && *nocolor && (!force || !*force)) {
|
|
||||||
cached = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (force && *force && strcmp(force, "0") != 0) {
|
|
||||||
cached = 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// if (!isatty(fileno(stdout))) {
|
|
||||||
// cached = 0;
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
if (colorterm && *colorterm) {
|
|
||||||
cached = 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!term || !*term) {
|
|
||||||
cached = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strstr(term, "color") || strstr(term, "xterm") ||
|
|
||||||
strstr(term, "screen") || strstr(term, "vt100") ||
|
|
||||||
strstr(term, "rxvt") || strstr(term, "ansi") ||
|
|
||||||
strstr(term, "linux") || strstr(term, "konsole") ||
|
|
||||||
strstr(term, "vte") || strstr(term, "kitty") ||
|
|
||||||
strstr(term, "wezterm") || strstr(term, "gnome")) {
|
|
||||||
cached = 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cached = 0;
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void errorf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%serror%s: ", ERROR, RESET);
|
|
||||||
} else {
|
|
||||||
fputs("error: ", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void fatalf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%sfatal error%s: ", ERROR, RESET);
|
|
||||||
} else {
|
|
||||||
fputs("fatal error: ", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fputs("program terminated.\n", stderr);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
void warnf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%swarning%s: ", WARN, RESET);
|
|
||||||
} else {
|
|
||||||
fputs("warning: ", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void notef(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%snote%s: ", NOTE, RESET);
|
|
||||||
} else {
|
|
||||||
fputs("note: ", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void hintf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%shint: ", HINT);
|
|
||||||
} else {
|
|
||||||
fputs("hint: ", stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfprintf(stderr, format, args);
|
|
||||||
|
|
||||||
if (err_support_color()) {
|
|
||||||
fprintf(stderr, "%s\n", RESET);
|
|
||||||
} else {
|
|
||||||
fputc('\n', stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void errorfa(int code)
|
|
||||||
{
|
|
||||||
errorf(strerror(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
void fatalfa(int code)
|
|
||||||
{
|
|
||||||
fatalf(strerror(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
void notefa(int code)
|
|
||||||
{
|
|
||||||
notef(strerror(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
void warnfa(int code)
|
|
||||||
{
|
|
||||||
warnf(strerror(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
void hintfa(int code)
|
|
||||||
{
|
|
||||||
hintf(strerror(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file err.c */
|
|
||||||
71
lib/err.h
71
lib/err.h
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.err - Contains color printing functions
|
|
||||||
*
|
|
||||||
* CONFIGURATION
|
|
||||||
* #define NOCOLOR
|
|
||||||
* Force no color when printing
|
|
||||||
* #define SHOW_TRACE
|
|
||||||
* Add debug traces to error printing
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ERR_H
|
|
||||||
#define ERR_H
|
|
||||||
|
|
||||||
void errorf(const char *format, ...);
|
|
||||||
_Noreturn void fatalf(const char *format, ...);
|
|
||||||
void notef(const char *format, ...);
|
|
||||||
void warnf(const char *format, ...);
|
|
||||||
void hintf(const char *format, ...);
|
|
||||||
|
|
||||||
void errorfa(int code);
|
|
||||||
_Noreturn void fatalfa(int code);
|
|
||||||
void notefa(int code);
|
|
||||||
void warnfa(int code);
|
|
||||||
void hintfa(int code);
|
|
||||||
|
|
||||||
#if defined(SHOW_TRACE)
|
|
||||||
#define errorf(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
errorf("%s:%s:%d: " fmt, __FILE__, __func__, \
|
|
||||||
__LINE__ __VA_OPT__(, ) __VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#define fatalf(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
fatalf("%s:%s:%d: " fmt, __FILE__, __func__, \
|
|
||||||
__LINE__ __VA_OPT__(, ) __VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file err.h */
|
|
||||||
125
lib/flag.c
125
lib/flag.c
@@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.flag - Contains command-line flag parsing functions
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "flag.h"
|
|
||||||
|
|
||||||
static char *nextchar;
|
|
||||||
|
|
||||||
int getopt_long(int argc, char *const argv[], const char *optstring,
|
|
||||||
const struct option *longopts, int *longindex)
|
|
||||||
{
|
|
||||||
if (nextchar == NULL || *nextchar == '\0') {
|
|
||||||
if (optind >= argc)
|
|
||||||
return -1;
|
|
||||||
if (argv[optind][0] != '-' || argv[optind][1] == '\0')
|
|
||||||
return -1;
|
|
||||||
if (argv[optind][1] == '-' && argv[optind][2] == '\0') {
|
|
||||||
optind++;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (argv[optind][1] == '-') {
|
|
||||||
const char *arg = argv[optind] + 2;
|
|
||||||
char *eq = strchr(arg, '=');
|
|
||||||
size_t len = eq ? (size_t)(eq - arg) : strlen(arg);
|
|
||||||
for (int i = 0; longopts[i].name; i++) {
|
|
||||||
if (strncmp(arg, longopts[i].name, len) == 0 &&
|
|
||||||
strlen(longopts[i].name) == len) {
|
|
||||||
if (longindex)
|
|
||||||
*longindex = i;
|
|
||||||
if (longopts[i].has_arg ==
|
|
||||||
required_argument) {
|
|
||||||
if (eq)
|
|
||||||
optarg = (char *)eq + 1;
|
|
||||||
else if (optind + 1 < argc)
|
|
||||||
optarg = argv[++optind];
|
|
||||||
else
|
|
||||||
return '?';
|
|
||||||
} else if (longopts[i].has_arg ==
|
|
||||||
optional_argument)
|
|
||||||
optarg = eq ? (char *)eq + 1 :
|
|
||||||
NULL;
|
|
||||||
else
|
|
||||||
optarg = NULL;
|
|
||||||
optind++;
|
|
||||||
if (longopts[i].flag) {
|
|
||||||
*longopts[i].flag =
|
|
||||||
longopts[i].val;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return longopts[i].val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
optind++;
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
nextchar = argv[optind] + 1;
|
|
||||||
}
|
|
||||||
char c = *nextchar++;
|
|
||||||
const char *pos = strchr(optstring, c);
|
|
||||||
if (!pos) {
|
|
||||||
optopt = c;
|
|
||||||
if (*nextchar == '\0')
|
|
||||||
optind++;
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
if (pos[1] == ':') {
|
|
||||||
if (*nextchar != '\0') {
|
|
||||||
optarg = nextchar;
|
|
||||||
optind++;
|
|
||||||
nextchar = NULL;
|
|
||||||
} else if (optind + 1 < argc) {
|
|
||||||
optarg = argv[++optind];
|
|
||||||
optind++;
|
|
||||||
nextchar = NULL;
|
|
||||||
} else {
|
|
||||||
optopt = c;
|
|
||||||
return '?';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
optarg = NULL;
|
|
||||||
if (*nextchar == '\0') {
|
|
||||||
optind++;
|
|
||||||
nextchar = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file flag.c */
|
|
||||||
44
lib/flag.h
44
lib/flag.h
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.flag - Contains command-line flag parsing functions
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FLAG_H
|
|
||||||
#define FLAG_H
|
|
||||||
|
|
||||||
int getopt_long(int argc, char *const argv[], const char *optstring,
|
|
||||||
const struct option *longopts, int *longindex);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file flag.h */
|
|
||||||
211
lib/fs.c
211
lib/fs.c
@@ -1,211 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.fs - Contains file system related iterations
|
|
||||||
*
|
|
||||||
* CONFIGURATION
|
|
||||||
* #define FS_ERROR_ON
|
|
||||||
* Error instead of fatal on failure
|
|
||||||
* #define FS_FATAL_OFF
|
|
||||||
* Disable auto fatal on failure
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "fs.h"
|
|
||||||
|
|
||||||
#include "err.h"
|
|
||||||
#include "xmem.h"
|
|
||||||
|
|
||||||
#if defined(FS_ERROR_ON)
|
|
||||||
#define RETURN(code) \
|
|
||||||
errorfa(code); \
|
|
||||||
return code
|
|
||||||
#elif defined(FS_FATAL_OFF)
|
|
||||||
#define RETURN(code) return code
|
|
||||||
#else
|
|
||||||
#define RETURN(code) fatalfa(code)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *fs_read(const char *path)
|
|
||||||
{
|
|
||||||
FILE *fptr = fopen(path, "r");
|
|
||||||
if (!fptr) {
|
|
||||||
#if defined(FS_ERROR_ON)
|
|
||||||
errorfa(errno);
|
|
||||||
#elif defined(FS_FATAL_ON)
|
|
||||||
fatalfa(errno);
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t cap = 1024;
|
|
||||||
size_t len = 0;
|
|
||||||
char *buf = xmalloc(cap);
|
|
||||||
|
|
||||||
int c;
|
|
||||||
while ((c = fgetc(fptr)) != EOF) {
|
|
||||||
if (len + 1 >= cap) {
|
|
||||||
cap *= 2;
|
|
||||||
char *tmp = realloc(buf, cap);
|
|
||||||
if (!tmp) {
|
|
||||||
free(buf);
|
|
||||||
fclose(fptr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
buf = tmp;
|
|
||||||
}
|
|
||||||
buf[len++] = (char)c;
|
|
||||||
}
|
|
||||||
buf[len] = '\0';
|
|
||||||
|
|
||||||
fclose(fptr);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fs_exists(const char *path)
|
|
||||||
{
|
|
||||||
FILE *fptr;
|
|
||||||
bool exists;
|
|
||||||
|
|
||||||
fptr = fopen(path, "r");
|
|
||||||
if (fptr) {
|
|
||||||
exists = true;
|
|
||||||
} else {
|
|
||||||
exists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fptr);
|
|
||||||
return exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fs_append(const char *path, const char *format, ...)
|
|
||||||
{
|
|
||||||
FILE *fp = fopen(path, "a");
|
|
||||||
if (!fp)
|
|
||||||
RETURN(errno);
|
|
||||||
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
int ret = vfprintf(fp, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
fclose(fp);
|
|
||||||
RETURN(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fclose(fp) != 0)
|
|
||||||
RETURN(errno);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fs_del(const char *path)
|
|
||||||
{
|
|
||||||
RETURN(remove(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
int fs_new(const char *path)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (path == NULL) {
|
|
||||||
errno = EINVAL;
|
|
||||||
RETURN(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(path);
|
|
||||||
if (len == 0) {
|
|
||||||
errno = EINVAL;
|
|
||||||
RETURN(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path[len - 1] == '/') {
|
|
||||||
if (mkdir(path, 0777) == -1)
|
|
||||||
RETURN(-1);
|
|
||||||
} else {
|
|
||||||
fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
|
||||||
if (fd == -1)
|
|
||||||
RETURN(-1);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fs_write(const char *path, const char *format, ...)
|
|
||||||
{
|
|
||||||
FILE *fptr = fopen(path, "w");
|
|
||||||
if (!fptr)
|
|
||||||
RETURN(-1);
|
|
||||||
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
int ret = vfprintf(fptr, format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
fclose(fptr);
|
|
||||||
RETURN(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fclose(fptr) != 0)
|
|
||||||
RETURN(-1);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *fs_temp()
|
|
||||||
{
|
|
||||||
FILE *fptr = tmpfile();
|
|
||||||
|
|
||||||
if (!fptr) {
|
|
||||||
#if defined(FS_ERROR_ON)
|
|
||||||
errorf("tmp failed");
|
|
||||||
#elif defined(FS_FATAL_ON)
|
|
||||||
fatalf("tmp failed");
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file fs.c */
|
|
||||||
55
lib/fs.h
55
lib/fs.h
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.fs - Contains file system related iterations
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef fs_H
|
|
||||||
#define fs_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
char *fs_read(const char *path);
|
|
||||||
|
|
||||||
bool fs_exists(const char *path);
|
|
||||||
|
|
||||||
int fs_append(const char *path, const char *format, ...);
|
|
||||||
int fs_del(const char *path);
|
|
||||||
int fs_new(const char *path);
|
|
||||||
int fs_write(const char *path, const char *format, ...);
|
|
||||||
|
|
||||||
FILE *fs_temp();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file fs.h */
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.proginfo - Program information functions, macros, and variables
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "proginfo.h"
|
|
||||||
|
|
||||||
/* TODO(vx-clutch): default this to argv[0] */
|
|
||||||
const char *prog_name = "";
|
|
||||||
|
|
||||||
void set_prog_name(char *name)
|
|
||||||
{
|
|
||||||
prog_name = prog_name ? basename(name) : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void emit_try_help()
|
|
||||||
{
|
|
||||||
printf("Try '%s --help' for more information\n", prog_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// void emit_version()
|
|
||||||
// {
|
|
||||||
// printf("\
|
|
||||||
// %s %s %d\n\
|
|
||||||
// Copyright (C) %d GCK.\n\
|
|
||||||
// This is free software: you are free to change and redistribute it.\n\
|
|
||||||
// There is NO WARRNTY, to the extent permitted by law.\n\
|
|
||||||
// ",
|
|
||||||
// prog_name, VERSION, COMMIT, YEAR);
|
|
||||||
// }
|
|
||||||
|
|
||||||
int parse_standard_options(int argc, char **argv, void (*print_help)(),
|
|
||||||
void (*print_version)())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
|
||||||
if (!strcmp(argv[i], "--help")) {
|
|
||||||
print_help();
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
} else if (!strcmp(argv[i], "--version")) {
|
|
||||||
print_version();
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file proginfo.c */
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.proginfo - Program information functions, macros, and variables
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef proginfo_H
|
|
||||||
#define proginfo_H
|
|
||||||
|
|
||||||
extern const char *prog_name;
|
|
||||||
|
|
||||||
void set_prog_name(char *name);
|
|
||||||
|
|
||||||
void emit_try_help();
|
|
||||||
void emit_version();
|
|
||||||
|
|
||||||
int parse_standard_options(int argc, char **argv, void (*print_help)(),
|
|
||||||
void (*print_version)());
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file proginfo.h */
|
|
||||||
105
lib/say.c
105
lib/say.c
@@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.say - Provides printing and some string utilies
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "say.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "xmem.h"
|
|
||||||
|
|
||||||
void alert()
|
|
||||||
{
|
|
||||||
fputs("\a", stderr);
|
|
||||||
fflush(stderr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int vasprintf(char **result, const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
int total_width = strlen(fmt) + 1;
|
|
||||||
*result = (char *)xmalloc(total_width);
|
|
||||||
return vsprintf(*result, fmt, ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
int asprintf(char **buf, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
status = vasprintf(buf, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
int say(const char *restrict format, ...)
|
|
||||||
{
|
|
||||||
struct winsize w;
|
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
int ret = vprintf(format, args);
|
|
||||||
va_end(args);
|
|
||||||
putchar('\n');
|
|
||||||
fflush(stdout);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\0337"); // save cursor (ESC 7)
|
|
||||||
printf("\033[%d;1H", w.ws_row); // move to last row
|
|
||||||
printf("\033[2K"); // clear entire line
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
int ret = vprintf(format, args); // print formatted message
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fflush(stdout); // ensure it's visible immediately
|
|
||||||
printf("\0338"); // restore cursor (ESC 8)
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
_Noreturn void die(const char *msg)
|
|
||||||
{
|
|
||||||
fputs(msg, stderr);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file say.c */
|
|
||||||
50
lib/say.h
50
lib/say.h
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.say - Provides printing and some string utilies
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SAY_H
|
|
||||||
#define SAY_H
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
int asprintf(char **buf, const char *fmt, ...);
|
|
||||||
int vasprintf(char **buf, const char *fmt, va_list ap);
|
|
||||||
int say(const char *restrict format, ...);
|
|
||||||
|
|
||||||
void alert();
|
|
||||||
|
|
||||||
_Noreturn void die(const char *msg);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file say.h */
|
|
||||||
80
lib/textc.c
80
lib/textc.c
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.textc - Text control
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "xmem.h"
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "textc.h"
|
|
||||||
|
|
||||||
char *str_dup(char *s)
|
|
||||||
{
|
|
||||||
char *new = xmalloc(strlen(s) + 1);
|
|
||||||
strcpy(new, s);
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *tostrupr(char *s)
|
|
||||||
{
|
|
||||||
char *new = str_dup(s);
|
|
||||||
for (int i = 0; new[i] != '\0'; ++i)
|
|
||||||
new[i] = toupper((unsigned char)new[i]);
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *tostrlwr(char *s)
|
|
||||||
{
|
|
||||||
char *new = str_dup(s);
|
|
||||||
for (int i = 0; new[i] != '\0'; ++i)
|
|
||||||
new[i] = tolower((unsigned char)new[i]);
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *textc_trim(char *s)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *textc_pad_left(int count, char *s, char pad)
|
|
||||||
{
|
|
||||||
char *buffer = xmalloc(strlen(s) + 1);
|
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
buffer = "NOT IMPLEMENTED";
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file textc.c */
|
|
||||||
49
lib/textc.h
49
lib/textc.h
@@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.textc - Text control
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TEXTC_H
|
|
||||||
#define TEXTC_H
|
|
||||||
|
|
||||||
char *str_dup(char *s);
|
|
||||||
char *tostrupr(char *s);
|
|
||||||
char *tostrlwr(char *s);
|
|
||||||
|
|
||||||
char *textc_trim(char *s);
|
|
||||||
char *textc_pad_left(int count, char *s, char pad);
|
|
||||||
char *textc_pad_right(int count, char *s, char pad);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file textc.h */
|
|
||||||
65
lib/xmem.c
65
lib/xmem.c
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.xmem - Xplosive memory
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "err.h"
|
|
||||||
|
|
||||||
#include "xmem.h"
|
|
||||||
|
|
||||||
void *ensure_nonnull(void *ptr)
|
|
||||||
{
|
|
||||||
if (ptr == NULL)
|
|
||||||
fatalf("memory exhausted");
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xmalloc(size_t size)
|
|
||||||
{
|
|
||||||
return ensure_nonnull(malloc(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xrealloc(void *ptr, size_t size)
|
|
||||||
{
|
|
||||||
return ensure_nonnull(realloc(ptr, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *xcalloc(size_t nmemb, size_t size)
|
|
||||||
{
|
|
||||||
return ensure_nonnull(calloc(nmemb, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* end of file xmem.c */
|
|
||||||
47
lib/xmem.h
47
lib/xmem.h
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* gcklib.xmem - Xplosive memory
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE: BSD-3-Clause
|
|
||||||
*
|
|
||||||
* Copyright (c) 2025 GCK
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef xmem_H
|
|
||||||
#define xmem_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
void *xmalloc(size_t size);
|
|
||||||
void *xrealloc(void *ptr, size_t size);
|
|
||||||
void *xcalloc(size_t nmemb, size_t size);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of file xmem.h */
|
|
||||||
77
main.c
Normal file
77
main.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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 "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(" --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
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
[NAME]
|
|
||||||
yait - An opinionated C project generator
|
|
||||||
[ADDITIONAL INFORMATION]
|
|
||||||
.UR https://github.com/gck-org/yait
|
|
||||||
264
proj.c
Normal file
264
proj.c
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
/* 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
Normal file
6
proj.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef PROJ_H_
|
||||||
|
#define PROJ_H_
|
||||||
|
|
||||||
|
int makeproj(char *src);
|
||||||
|
|
||||||
|
#endif /* PROJ_H_ */
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Builds man page
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
package=yait
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information.'$1'." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
help2man --include=man/$package.x ./bin/$package > $package.1
|
|
||||||
76
shell.c
Normal file
76
shell.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* 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, 2025, "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
Normal file
6
shell.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SHELL_H_
|
||||||
|
#define SHELL_H_
|
||||||
|
|
||||||
|
int makeshell(char *src, int complexity);
|
||||||
|
|
||||||
|
#endif /* SHELL_H_ */
|
||||||
20
single.c
Normal file
20
single.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* 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
Normal file
6
single.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SINGLE_H_
|
||||||
|
#define SINGLE_H_
|
||||||
|
|
||||||
|
int single_init(char *src);
|
||||||
|
|
||||||
|
#endif /* SINGLE_H_ */
|
||||||
42
src/flat.c
42
src/flat.c
@@ -1,42 +0,0 @@
|
|||||||
// SPDX-License-Identifer: BSD-3-Clause
|
|
||||||
/*
|
|
||||||
* A uemacs derided and inspired layout and format for smaller projects;
|
|
||||||
* such as, a small test, or CLI.
|
|
||||||
*/
|
|
||||||
#include <lib/fs.h>
|
|
||||||
#include <lib/say.h>
|
|
||||||
|
|
||||||
#include <template.h>
|
|
||||||
#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, "%s", license);
|
|
||||||
fs_write("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();\n\
|
|
||||||
\n\
|
|
||||||
#endif",
|
|
||||||
package, package, author);
|
|
||||||
fs_write("version.c", "\
|
|
||||||
#include <stdio.h>\n\
|
|
||||||
#include \"version.h\"\n\
|
|
||||||
\n\
|
|
||||||
void version()\n\
|
|
||||||
{\n\
|
|
||||||
printf(\"%%s version %%s\\n\", PROGRAM_NAME_LONG, VERSION);\n\
|
|
||||||
}");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
#ifndef LICENCES_H_
|
|
||||||
#define LICENCES_H_
|
|
||||||
|
|
||||||
const char *fBSD = "\
|
|
||||||
BSD 3-Clause License\n\
|
|
||||||
\n\
|
|
||||||
Copyright (c) %d, %s\n\
|
|
||||||
\n\
|
|
||||||
Redistribution and use in source and binary forms, with or without\n\
|
|
||||||
modification, are permitted provided that the following conditions are met:\n\
|
|
||||||
\n\
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this\n\
|
|
||||||
list of conditions and the following disclaimer.\n\
|
|
||||||
\n\
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,\n\
|
|
||||||
this list of conditions and the following disclaimer in the documentation\n\
|
|
||||||
and/or other materials provided with the distribution.\n\
|
|
||||||
\n\
|
|
||||||
3. Neither the name of the copyright holder nor the names of its\n\
|
|
||||||
contributors may be used to endorse or promote products derived from\n\
|
|
||||||
this software without specific prior written permission.\n\
|
|
||||||
\n\
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \" AS IS \"\n\
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n\
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n\
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n\
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n\
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n\
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\
|
|
||||||
";
|
|
||||||
|
|
||||||
const char *fGPL = "\
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later\n\
|
|
||||||
\n\
|
|
||||||
This program is free software: you can redistribute it and/or modify it\n\
|
|
||||||
under the terms of the GNU General Public License as published by the\n\
|
|
||||||
Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\
|
|
||||||
\n\
|
|
||||||
For details, see <https://www.gnu.org/licenses/>.";
|
|
||||||
|
|
||||||
const char *fMIT = "\
|
|
||||||
Copyright %d %s\n\
|
|
||||||
\n\
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\
|
|
||||||
\n\
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\
|
|
||||||
\n\
|
|
||||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
const char *fUNL = "\
|
|
||||||
This is free and unencumbered software released into the public domain.\n\
|
|
||||||
\n\
|
|
||||||
Anyone is free to copy, modify, publish, use, compile, sell, or\n\
|
|
||||||
distribute this software, either in source code form or as a compiled\n\
|
|
||||||
binary, for any purpose, commercial or non-commercial, and by any\n\
|
|
||||||
means.\n\
|
|
||||||
\n\
|
|
||||||
In jurisdictions that recognize copyright laws, the author or authors\n\
|
|
||||||
of this software dedicate any and all copyright interest in the\n\
|
|
||||||
software to the public domain. We make this dedication for the benefit\n\
|
|
||||||
of the public at large and to the detriment of our heirs and\n\
|
|
||||||
successors. We intend this dedication to be an overt act of\n\
|
|
||||||
relinquishment in perpetuity of all present and future rights to this\n\
|
|
||||||
software under copyright law.\n\
|
|
||||||
\n\
|
|
||||||
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\
|
|
||||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n\
|
|
||||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n\
|
|
||||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n\
|
|
||||||
OTHER DEALINGS IN THE SOFTWARE.\n\
|
|
||||||
\n\
|
|
||||||
For more information, please refer to <https://unlicense.org/>\
|
|
||||||
";
|
|
||||||
|
|
||||||
#endif
|
|
||||||
62
src/shell.c
62
src/shell.c
@@ -1,62 +0,0 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
#include <errno.h>
|
|
||||||
#include <lib/err.h>
|
|
||||||
#include <lib/fs.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
int write_shell(char *package, char *license, int year, char *author, char *m)
|
|
||||||
{
|
|
||||||
fs_write(package, "\
|
|
||||||
#!/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 textent permitted by law.\"\n\
|
|
||||||
\n\
|
|
||||||
usage=\"\\\n\
|
|
||||||
Usage: $me [OPTION]...\n\
|
|
||||||
%s\n\
|
|
||||||
\n\
|
|
||||||
Options:\n\
|
|
||||||
\n\
|
|
||||||
--help print this help and exit\n\
|
|
||||||
--version output version information\"\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: Unknwon option '$1'.\" >&2\n\
|
|
||||||
echo \"$0: Try '--help' for more information.\" >&2\n\
|
|
||||||
exit 1 ;;\n\
|
|
||||||
esac\n\
|
|
||||||
shift\n\
|
|
||||||
done\n\
|
|
||||||
\n\
|
|
||||||
echo \"$0: done.\"\n\
|
|
||||||
\n\
|
|
||||||
# End: %s\
|
|
||||||
",
|
|
||||||
license, m, year, author, m, package);
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (stat(package, &st) != 0) {
|
|
||||||
fatalfa(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
mode_t mode = st.st_mode | S_IXUSR;
|
|
||||||
|
|
||||||
if (chmod(package, mode) != 0) {
|
|
||||||
fatalfa(errno);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
#ifndef SHELL_H_
|
|
||||||
#define SHELL_H_
|
|
||||||
|
|
||||||
int write_shell(char *package, char *license, int year, char *author, char *m);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// SPDX-License-Identifer: BSD-3-Clause
|
|
||||||
#ifndef VERSION_H_
|
|
||||||
#define VERSION_H_
|
|
||||||
|
|
||||||
#define PROGRAM_NAME "yait"
|
|
||||||
#define PROGRAM_NAME_LONG "yait/GCK"
|
|
||||||
|
|
||||||
#define VERSION "beta"
|
|
||||||
|
|
||||||
/* Print the version string. */
|
|
||||||
void version();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
235
src/yait.c
235
src/yait.c
@@ -1,235 +0,0 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2025, GCK.
|
|
||||||
* Written by vx-clutch (vx-clutch)
|
|
||||||
*/
|
|
||||||
#include <config.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <lib/err.h>
|
|
||||||
#include <lib/fs.h>
|
|
||||||
#include <lib/proginfo.h>
|
|
||||||
#include <lib/say.h>
|
|
||||||
#include <lib/textc.h>
|
|
||||||
|
|
||||||
#include "flat.h"
|
|
||||||
#include "license.h"
|
|
||||||
#include "shell.h"
|
|
||||||
#include "version.h"
|
|
||||||
#include <template.h>
|
|
||||||
|
|
||||||
#ifndef GOOD
|
|
||||||
#define GOOD 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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 }
|
|
||||||
};
|
|
||||||
|
|
||||||
static int exit_status;
|
|
||||||
|
|
||||||
static void print_help();
|
|
||||||
|
|
||||||
static char *get_name()
|
|
||||||
{
|
|
||||||
int fds[2];
|
|
||||||
if (pipe(fds) == -1)
|
|
||||||
goto sysuser;
|
|
||||||
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid == -1) {
|
|
||||||
close(fds[0]);
|
|
||||||
close(fds[1]);
|
|
||||||
goto sysuser;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pid == 0) {
|
|
||||||
dup2(fds[1], STDOUT_FILENO);
|
|
||||||
close(fds[0]);
|
|
||||||
close(fds[1]);
|
|
||||||
execlp("git", "git", "config", "--get", "user.name",
|
|
||||||
(char *)NULL);
|
|
||||||
_exit(127);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fds[1]);
|
|
||||||
char buf[256];
|
|
||||||
ssize_t n = read(fds[0], buf, sizeof buf - 1);
|
|
||||||
close(fds[0]);
|
|
||||||
int status;
|
|
||||||
waitpid(pid, &status, 0);
|
|
||||||
if (n > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
|
||||||
buf[n] = 0;
|
|
||||||
buf[strcspn(buf, "\n")] = 0;
|
|
||||||
return str_dup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
sysuser: {
|
|
||||||
char *name = getlogin();
|
|
||||||
if (name)
|
|
||||||
return str_dup(name);
|
|
||||||
struct passwd *pw = getpwuid(getuid());
|
|
||||||
if (pw && pw->pw_name)
|
|
||||||
return str_dup(pw->pw_name);
|
|
||||||
}
|
|
||||||
return str_dup("author");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_year()
|
|
||||||
{
|
|
||||||
time_t now = time(NULL);
|
|
||||||
struct tm *t = localtime(&now);
|
|
||||||
|
|
||||||
return t->tm_year + 1900;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int optc;
|
|
||||||
int lose = 0;
|
|
||||||
char *m = str_dup("[DESCRIPTION]"), /* description flag */
|
|
||||||
*package;
|
|
||||||
bool S = false; /* shell flag */
|
|
||||||
bool f = false; /* flat flag */
|
|
||||||
char *author = get_name();
|
|
||||||
exit_status = GOOD;
|
|
||||||
int year = get_year();
|
|
||||||
license_t license = BSD;
|
|
||||||
char *license_str = "BSD-3-Clause";
|
|
||||||
set_prog_name(argv[0]);
|
|
||||||
|
|
||||||
parse_standard_options(argc, argv, print_help, version);
|
|
||||||
|
|
||||||
while ((optc = getopt_long(argc, argv, "a:l:m:EqfS", longopts, NULL)) !=
|
|
||||||
-1)
|
|
||||||
switch (optc) {
|
|
||||||
case 'a':
|
|
||||||
if (optarg) {
|
|
||||||
if (author)
|
|
||||||
free(author);
|
|
||||||
author = str_dup(optarg);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
if (optarg) {
|
|
||||||
if (m)
|
|
||||||
free(m);
|
|
||||||
m = str_dup(optarg);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
if (!strcmp(optarg, "list")) {
|
|
||||||
puts("BSD\nGPL\nMIT\nUNL");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "GPL")) {
|
|
||||||
license = GPL;
|
|
||||||
license_str = "GPL-3.0-only";
|
|
||||||
} else if (!strcmp(optarg, "MIT")) {
|
|
||||||
license = MIT;
|
|
||||||
license_str = "MIT";
|
|
||||||
} else if (!strcmp(optarg, "BSD")) {
|
|
||||||
license = BSD;
|
|
||||||
license_str = "BSD-3-Clause";
|
|
||||||
} else if (!strcmp(optarg, "UNL")) {
|
|
||||||
license = UNL;
|
|
||||||
license_str = "Unlicense";
|
|
||||||
} else {
|
|
||||||
puts("BSD\nGPL\nMIT\nUNL");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
S = true;
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
f = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
lose = 1;
|
|
||||||
}
|
|
||||||
if (lose) {
|
|
||||||
emit_try_help();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind >= argc) {
|
|
||||||
fatalf("no input name");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind + 1 < argc) {
|
|
||||||
errorf("extra operand: %s", argv[optind + 1]);
|
|
||||||
emit_try_help();
|
|
||||||
}
|
|
||||||
|
|
||||||
package = str_dup(argv[optind]);
|
|
||||||
|
|
||||||
if (S)
|
|
||||||
return write_shell(package, license_str, year, author, m);
|
|
||||||
|
|
||||||
char *project_dir;
|
|
||||||
asprintf(&project_dir, "%s/", package);
|
|
||||||
|
|
||||||
fs_new(project_dir);
|
|
||||||
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,
|
|
||||||
package, author, package);
|
|
||||||
|
|
||||||
if (f)
|
|
||||||
exit_status =
|
|
||||||
generate_flat(package, author, year, license_str, m);
|
|
||||||
// else
|
|
||||||
// exit_status =
|
|
||||||
// generate_regular(package, author, year, license_str, m);
|
|
||||||
|
|
||||||
return exit_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_help()
|
|
||||||
{
|
|
||||||
printf("Usage: %s [OPTION]... [project-name]...\n", PROGRAM);
|
|
||||||
fputs("\
|
|
||||||
Generates an opinionated C project.\n",
|
|
||||||
stdout);
|
|
||||||
puts("");
|
|
||||||
fputs("\
|
|
||||||
--help display this help and exit\n\
|
|
||||||
--version display version information and exit\n",
|
|
||||||
stdout);
|
|
||||||
puts("");
|
|
||||||
fputs("\
|
|
||||||
-m DESC Set the program description (default \"Does a thing\")\n\
|
|
||||||
--author NAME Set the program author (default git username|system username)\n\
|
|
||||||
--license LICENSE Set the program license (default BSD)\n",
|
|
||||||
stdout);
|
|
||||||
exit(exit_status);
|
|
||||||
}
|
|
||||||
55
t/INSTALL.x
55
t/INSTALL.x
@@ -1,55 +0,0 @@
|
|||||||
Format_Index: y, a
|
|
||||||
Installation Instructions
|
|
||||||
*************************
|
|
||||||
|
|
||||||
Copyright (C) %d %s
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved. This file is offered as-is,
|
|
||||||
without warranty of any kind.
|
|
||||||
|
|
||||||
Basic Installation
|
|
||||||
==================
|
|
||||||
|
|
||||||
Briefly, the shell command `./configure && make && make install` should
|
|
||||||
configure, build, and install this package. The following more-detailed
|
|
||||||
instruction are generic; see the `README` file for instructions specific to
|
|
||||||
this package.
|
|
||||||
|
|
||||||
The `configure` shell script attempts to guess correct values for
|
|
||||||
various system-dependent variables used during compilation. It uses
|
|
||||||
those values within a `Makefile` to build for that POSIX system as
|
|
||||||
defined by `config.mak` which was generated by `configure`.
|
|
||||||
|
|
||||||
Compilers and Options
|
|
||||||
=====================
|
|
||||||
|
|
||||||
Some systems require unusal options for compilation or linking that
|
|
||||||
the `configure` script does not know about. If you run into an issue
|
|
||||||
run `./configure --help` to figure out what you can do to fix the
|
|
||||||
behavoir.
|
|
||||||
|
|
||||||
Installation Names
|
|
||||||
==================
|
|
||||||
|
|
||||||
By default, `make install` installs the package's command under
|
|
||||||
`/usr/local/bin`. You can specify an installation prefix other than `/usr/local/`
|
|
||||||
by giving `configure` the option `--prefix=PREFIX` to `configure`, the package uses
|
|
||||||
PREFIX as the prefix for installation programs and libraries.
|
|
||||||
Documentation and other data files still use the regular prefix.
|
|
||||||
|
|
||||||
`configure` Invokation
|
|
||||||
======================
|
|
||||||
|
|
||||||
`configure` recongizes the following options to control its operations.
|
|
||||||
|
|
||||||
`--help`
|
|
||||||
Prints a summary of all the options to `configure`, and exits.
|
|
||||||
`--prefix=PREFIX`
|
|
||||||
Sets the installation prefix.
|
|
||||||
`CFLAGS`
|
|
||||||
Sets the flags used during compilation.
|
|
||||||
|
|
||||||
`configure` also accepts some other options. Run `configure --help` for more
|
|
||||||
details
|
|
||||||
64
t/Makefile.x
64
t/Makefile.x
@@ -1,64 +0,0 @@
|
|||||||
Format_Index: p
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
PACKAGE := %s
|
|
||||||
|
|
||||||
SRCS := $(wildcard src/*.c) $(wildcard lib/*.c)
|
|
||||||
OBJS := $(patsubst src/%.c,build/obj/%.o,$(SRCS))
|
|
||||||
|
|
||||||
BIN := bin/$(PACKAGE)
|
|
||||||
|
|
||||||
COMMIT := $(shell git rev-list --count --all)
|
|
||||||
FLAGS := -I. -DCOMMIT=$(COMMIT) --std=c2x -pedantic -Ibuild/include
|
|
||||||
|
|
||||||
VERSION := $(shell git describe --tags --always --dirty)
|
|
||||||
TARBALL := $(PACKAGE)-$(VERSION).tar.gz
|
|
||||||
RELEASE_FILES := doc src lib COPYING AUTHORS README $(PACKAGE).1 INSTALL Makefile configure config.h
|
|
||||||
|
|
||||||
-include config.mak
|
|
||||||
|
|
||||||
ifeq ($(wildcard config.mak),)
|
|
||||||
all:
|
|
||||||
@echo "File config.mak not found, run configure"
|
|
||||||
@exit 1
|
|
||||||
else
|
|
||||||
|
|
||||||
all: build $(BIN) doc
|
|
||||||
|
|
||||||
build:
|
|
||||||
mkdir -p bin
|
|
||||||
mkdir -p build/obj
|
|
||||||
|
|
||||||
build/obj/%.o: src/%.c config.mak
|
|
||||||
$(CC) $(FLAGS) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
$(BIN): $(OBJS)
|
|
||||||
$(CC) $(FLAGS) $(CFLAGS) $^ -o $@
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
install: $(BIN)
|
|
||||||
cp $(BIN) $(PREFIX)
|
|
||||||
|
|
||||||
doc:
|
|
||||||
$(MAKE) -C doc all
|
|
||||||
|
|
||||||
uninstall:
|
|
||||||
$(RM) $(PREFIX)$(PACKAGE)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) -r bin
|
|
||||||
$(RM) -r build
|
|
||||||
$(MAKE) -C doc clean
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(RM) config.mak config.status
|
|
||||||
$(RM) $(TARBALL)
|
|
||||||
$(MAKE) -C doc clean
|
|
||||||
|
|
||||||
release: clean all
|
|
||||||
tar -czf $(TARBALL) $(RELEASE_FILES)
|
|
||||||
|
|
||||||
test:
|
|
||||||
@$(BIN) --version > /dev/null 2>&1 && echo "intact"|| echo "defective"
|
|
||||||
|
|
||||||
.PHONY: all clean distclean install uninstall build release doc
|
|
||||||
113
t/README-dev.x
113
t/README-dev.x
@@ -1,113 +0,0 @@
|
|||||||
Format_Index: y, a
|
|
||||||
This README.dev file describes the development environment.
|
|
||||||
|
|
||||||
Copyright (C) %d %s.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
Notice
|
|
||||||
------
|
|
||||||
|
|
||||||
This documentation is standard across all GCK package and is not specified per
|
|
||||||
package; however, this is the defacto standard for most packages. The only
|
|
||||||
place where this commonly differs is in non-binary or library packages.
|
|
||||||
|
|
||||||
|
|
||||||
Build system
|
|
||||||
------------
|
|
||||||
|
|
||||||
This distribution uses a GNU autotools-like build system. This is made up of a
|
|
||||||
configure script, and a Makefile. The configure script detects a C23 compiler
|
|
||||||
on the system and sets any program flags: debug, release, custom. The Makefile
|
|
||||||
builds the binary based on the output [config.mak] of the configure script.
|
|
||||||
|
|
||||||
|
|
||||||
Building
|
|
||||||
--------
|
|
||||||
|
|
||||||
To build this distribution you first must run the configure script. This
|
|
||||||
outputs a config.mak file that will be used in the Make step. Then run make;
|
|
||||||
this builds the objects into build/ and the binary into bin/.
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
|
|
||||||
The configuration script is used to generate a build intermediate step called
|
|
||||||
the config.mak. This file is used by the Makefile to figure out C compiler to
|
|
||||||
use, what CFLAGS and LDFLAGS to use, and where to install the binary if
|
|
||||||
requested. By default these values are gcc, the release flag set, and
|
|
||||||
/usr/local/. The configuration script supports the following flags that control
|
|
||||||
CFLAGS: --enable-debug and CFLAGS="". By default, the script uses flags for a release
|
|
||||||
build. Debug is for in-development programming and is the strictest when it
|
|
||||||
comes to warnings and other compiler output. CFLAGS="" is for custom flag
|
|
||||||
definition. For the development environment is it recommended to use the
|
|
||||||
--debug flag. Some examples of how you can run the configure script:
|
|
||||||
|
|
||||||
For default behavior:
|
|
||||||
|
|
||||||
./configure
|
|
||||||
|
|
||||||
For debug use:
|
|
||||||
|
|
||||||
./configure --enable-debug
|
|
||||||
|
|
||||||
For help text:
|
|
||||||
|
|
||||||
./configure --help
|
|
||||||
|
|
||||||
The help text is a more useage specific and up-to-date reference for
|
|
||||||
the configure script.
|
|
||||||
|
|
||||||
|
|
||||||
Makefile
|
|
||||||
--------
|
|
||||||
|
|
||||||
The GNU Makefile is used to build the final executable, clean up build
|
|
||||||
artifacts, and install the program. It checks for the config.mak which is
|
|
||||||
generated by the configure script. For a regular build, once you have the
|
|
||||||
configure script with desired flags, run:
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
||||||
This builds the executable to bin/ and build objects to build/
|
|
||||||
|
|
||||||
|
|
||||||
Suggested enviroment setup
|
|
||||||
--------------------------
|
|
||||||
It is suggested that you run do the following things to prepare you environment
|
|
||||||
for development. This is not a strict enforcement, but due to the project
|
|
||||||
structure it is a good starting point.
|
|
||||||
|
|
||||||
git pull
|
|
||||||
./tools/Cleanup
|
|
||||||
./configure --enable-debug
|
|
||||||
./build-aux/generate-artifacts
|
|
||||||
make test
|
|
||||||
|
|
||||||
This is to ensure that you have the most up-to-date source code, and that there
|
|
||||||
are no major problems with the source control version.
|
|
||||||
|
|
||||||
The git pull is used to sync with the repository and prevent conflicts. The
|
|
||||||
cleanup is to ensure their are no lingering build artifacts. The configure with
|
|
||||||
debug enabled is for strict build flags and -ggdb. Bear is used to generated
|
|
||||||
compile_commands.json for the clang suite of tooling. Finally, run the program
|
|
||||||
to ensure the chain works.
|
|
||||||
|
|
||||||
|
|
||||||
Pre-commit checks
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Before you commit to source control ensure that done the following:
|
|
||||||
|
|
||||||
* Run the cleanup scripts
|
|
||||||
|
|
||||||
./tools/Cleanup
|
|
||||||
|
|
||||||
* Ensure that all changes were atomic
|
|
||||||
|
|
||||||
* If you compted a TODO list item check it off.
|
|
||||||
|
|
||||||
* Based on complexity, test the feature accordingly.
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
Format_Index:
|
|
||||||
Here are most of the steps before you make a release.
|
|
||||||
|
|
||||||
* Start from a clean, up-to-date git driectory on "master":
|
|
||||||
|
|
||||||
make -k distclean || { ./configure && make distclean; }
|
|
||||||
git checkout master
|
|
||||||
git pull origin master
|
|
||||||
|
|
||||||
* Ensure that the latest stable versions of make, sh, etc.
|
|
||||||
are in your path. See the prerequisites list in README-dev
|
|
||||||
for a compile list of tools.
|
|
||||||
|
|
||||||
* Ensure that you have no uncommitted diffs. This should produce
|
|
||||||
no output:
|
|
||||||
|
|
||||||
git diff
|
|
||||||
|
|
||||||
* Ensure that you've pushed all changes that belong in the release:
|
|
||||||
|
|
||||||
git push origin master
|
|
||||||
|
|
||||||
* Pre-release testing: ensure that the following command succeeds:
|
|
||||||
|
|
||||||
make check syntax-check distcheck
|
|
||||||
|
|
||||||
Once all the builds and tests have passed,
|
|
||||||
|
|
||||||
* Run the following to create release tarballs.
|
|
||||||
|
|
||||||
make release
|
|
||||||
|
|
||||||
* Upload the tarball to the relavent distribtuion platform.
|
|
||||||
30
t/README.x
30
t/README.x
@@ -1,30 +0,0 @@
|
|||||||
Format_Index: a, p, p, d, y, p, a, p
|
|
||||||
This is the README file for the %s %s distribution.
|
|
||||||
%s %s
|
|
||||||
|
|
||||||
Copyright (C) %d %s.
|
|
||||||
|
|
||||||
Copying and distribution of this file, with or without modification,
|
|
||||||
are permitted in any medium without royalty provided the copyright
|
|
||||||
notice and this notice are preserved.
|
|
||||||
|
|
||||||
See the files ./INSTALL* for building and installation instructions.
|
|
||||||
|
|
||||||
Bug reports:
|
|
||||||
Please include enough information for the maintainers to reproduce the
|
|
||||||
problem. Generally speaking, that means:
|
|
||||||
- the contents of any input files necessary to reproduce the bug
|
|
||||||
and command line invocations of the program(s) involved (crucial!).
|
|
||||||
- a description of the problem and any samples of the erroneous output.
|
|
||||||
- the version number of the program(s) involved (use --version).
|
|
||||||
- hardware, operating system, and compiler versions (uname -a).
|
|
||||||
- unusual options you gave to configure, if any (see config.mak).
|
|
||||||
- anything else that you think would be helpful.
|
|
||||||
|
|
||||||
See README-dev for information on the development environment -- any
|
|
||||||
interested parties are welcome. If you're a programmer and wish to
|
|
||||||
contribute, this should get you started. If you're not a programmer,
|
|
||||||
your help in writing test cases, checking documentation against the
|
|
||||||
implementation, etc., would still be very much appreciated.
|
|
||||||
|
|
||||||
%s %s is free software. See the file COPYING for copying conditions.
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
Format_Index: p
|
|
||||||
PROGRAM = %s
|
|
||||||
CC = gcc
|
|
||||||
CFLAGS = -O2 -Wall -Wstrict-prototypes -g
|
|
||||||
DEFINES =
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
SRC = $(wildcard *.c)
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
|
|
||||||
V =
|
|
||||||
ifeq ($(strip $(V)),)
|
|
||||||
E = @echo
|
|
||||||
Q = @
|
|
||||||
else
|
|
||||||
E = @\#
|
|
||||||
Q =
|
|
||||||
endif
|
|
||||||
export E Q
|
|
||||||
|
|
||||||
$(PROGRAM): $(OBJ)
|
|
||||||
$(E) " LINK " $@
|
|
||||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ $(LIBS)
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(E) " CC " $@
|
|
||||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -c $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(E) " CLEAN"
|
|
||||||
$(Q) rm -f $(PROGRAM) $(OBJ)
|
|
||||||
50
t/main.x
50
t/main.x
@@ -1,50 +0,0 @@
|
|||||||
Format_Index: l, y, a, d, a
|
|
||||||
// SPDX-License-Identifier: %s
|
|
||||||
/*
|
|
||||||
* Copyright (C) %d, %s.
|
|
||||||
* Written by YOU (you@example.com)
|
|
||||||
*/
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
39
t/shell.x
39
t/shell.x
@@ -1,39 +0,0 @@
|
|||||||
Format_Index: l,d,y,a,d,p
|
|
||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: %s
|
|
||||||
#
|
|
||||||
# %s
|
|
||||||
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) %d %s
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the textent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
%s
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$0: done."
|
|
||||||
|
|
||||||
# End: %s
|
|
||||||
154
t/t
154
t/t
@@ -1,154 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.1"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Generate template headers
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
x_files=$(find . -maxdepth 1 -name "*.x" -type f | sort)
|
|
||||||
|
|
||||||
if test -z "$x_files"; then
|
|
||||||
echo "$0: No .x files found in current directory." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output_file="../template.h"
|
|
||||||
mkdir -p ../build/include/
|
|
||||||
|
|
||||||
first_template=true
|
|
||||||
|
|
||||||
{
|
|
||||||
echo "/* DO NOT MODIFY THIS FILE! It was generated by t $scriptversion. */"
|
|
||||||
echo "#ifndef TEMPLATE_H"
|
|
||||||
echo "#define TEMPLATE_H"
|
|
||||||
|
|
||||||
for input_file in $x_files; do
|
|
||||||
base_name=$(basename "$input_file" .x)
|
|
||||||
template_name=$(echo "$base_name" | tr '[:lower:]' '[:upper:]')
|
|
||||||
|
|
||||||
tmp_format=$(mktemp)
|
|
||||||
tmp_template=$(mktemp)
|
|
||||||
tmp_params=$(mktemp)
|
|
||||||
|
|
||||||
format_index=$(head -n 1 "$input_file")
|
|
||||||
if ! echo "$format_index" | grep -q "^Format_Index:"; then
|
|
||||||
echo "$0: '$input_file': Missing Format_Index line." >&2
|
|
||||||
rm -f "$tmp_format" "$tmp_template" "$tmp_params"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$first_template" = false; then
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
first_template=false
|
|
||||||
|
|
||||||
tmp_specs=$(mktemp)
|
|
||||||
|
|
||||||
echo "$format_index" | sed 's/Format_Index://' | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' > "$tmp_params"
|
|
||||||
|
|
||||||
tail -n +2 "$input_file" | sed '/^$/d' > "$tmp_template"
|
|
||||||
|
|
||||||
param_names=""
|
|
||||||
while IFS= read -r param; do
|
|
||||||
param_names="$param_names $param"
|
|
||||||
done < "$tmp_params"
|
|
||||||
|
|
||||||
while IFS= read -r line; do
|
|
||||||
echo "$line" | grep -o '%[sdifgxXoucpeEaAn]' >> "$tmp_specs"
|
|
||||||
done < "$tmp_template"
|
|
||||||
|
|
||||||
echo "/*"
|
|
||||||
|
|
||||||
param_idx=1
|
|
||||||
for param in $param_names; do
|
|
||||||
format_type=""
|
|
||||||
spec=$(sed -n "${param_idx}p" "$tmp_specs")
|
|
||||||
case "$spec" in
|
|
||||||
%s|%S) format_type="(s)" ;;
|
|
||||||
%d|%i|%u|%x|%X|%o) format_type="(d)" ;;
|
|
||||||
%f|%g|%e|%E|%a|%A) format_type="(f)" ;;
|
|
||||||
%c) format_type="(c)" ;;
|
|
||||||
%p) format_type="(p)" ;;
|
|
||||||
%n) format_type="(n)" ;;
|
|
||||||
*) format_type="(?)" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case "$param" in
|
|
||||||
a) param="author" ;;
|
|
||||||
y) param="year" ;;
|
|
||||||
l) param="license" ;;
|
|
||||||
d) param="description" ;;
|
|
||||||
p) param="package" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
printf " * %-13s%s\n" "$param" "$format_type"
|
|
||||||
param_idx=$((param_idx + 1))
|
|
||||||
done
|
|
||||||
|
|
||||||
echo " */"
|
|
||||||
echo "static const char templ_${template_name}[] = \"\\"
|
|
||||||
|
|
||||||
line_count=0
|
|
||||||
total_lines=$(wc -l < "$tmp_template")
|
|
||||||
while IFS= read -r line; do
|
|
||||||
line_count=$((line_count + 1))
|
|
||||||
escaped_line=$(echo "$line" | sed \
|
|
||||||
-e 's/\\\\/__BSLASH__/g' \
|
|
||||||
-e 's/\\"/__BQUOTE__/g' \
|
|
||||||
-e 's/\\n/__NEWLINE__/g' \
|
|
||||||
-e 's/\\t/__TAB__/g' \
|
|
||||||
-e 's/\\r/__RETURN__/g' \
|
|
||||||
-e 's/\\a/__ALERT__/g' \
|
|
||||||
-e 's/\\b/__BACKSPACE__/g' \
|
|
||||||
-e 's/\\f/__FORMFEED__/g' \
|
|
||||||
-e 's/\\v/__VTAB__/g' \
|
|
||||||
-e 's/\\0/__NULL__/g' \
|
|
||||||
-e 's/\\/\\\\/g' \
|
|
||||||
-e 's/"/\\"/g' \
|
|
||||||
-e 's/__BSLASH__/\\\\/g' \
|
|
||||||
-e 's/__BQUOTE__/\\"/g' \
|
|
||||||
-e 's/__NEWLINE__/\\n/g' \
|
|
||||||
-e 's/__TAB__/\\t/g' \
|
|
||||||
-e 's/__RETURN__/\\r/g' \
|
|
||||||
-e 's/__ALERT__/\\a/g' \
|
|
||||||
-e 's/__BACKSPACE__/\\b/g' \
|
|
||||||
-e 's/__FORMFEED__/\\f/g' \
|
|
||||||
-e 's/__VTAB__/\\v/g' \
|
|
||||||
-e 's/__NULL__/\\0/g')
|
|
||||||
if test $line_count -lt $total_lines; then
|
|
||||||
printf '%s\\n\\\n' "$escaped_line"
|
|
||||||
else
|
|
||||||
printf '%s";\n' "$escaped_line"
|
|
||||||
fi
|
|
||||||
done < "$tmp_template"
|
|
||||||
|
|
||||||
rm -f "$tmp_format" "$tmp_template" "$tmp_params" "$tmp_specs"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "#endif"
|
|
||||||
} > "$output_file"
|
|
||||||
68
template.h
68
template.h
@@ -1,68 +0,0 @@
|
|||||||
/* DO NOT MODIFY THIS FILE! It was generated by t 1.0.1. */
|
|
||||||
#ifndef TEMPLATE_H
|
|
||||||
#define TEMPLATE_H
|
|
||||||
/*
|
|
||||||
* package (s)
|
|
||||||
*/
|
|
||||||
static const char templ_FLAT_MAKEFILE[] = "\
|
|
||||||
PROGRAM = %s\n\
|
|
||||||
CC = gcc\n\
|
|
||||||
CFLAGS = -O2 -Wall -Wstrict-prototypes -g\n\
|
|
||||||
DEFINES =\n\
|
|
||||||
LIBS =\n\
|
|
||||||
SRC = $(wildcard *.c)\n\
|
|
||||||
OBJ = $(SRC:.c=.o)\n\
|
|
||||||
V =\n\
|
|
||||||
ifeq ($(strip $(V)),)\n\
|
|
||||||
E = @echo\n\
|
|
||||||
Q = @\n\
|
|
||||||
else\n\
|
|
||||||
E = @\\#\n\
|
|
||||||
Q =\n\
|
|
||||||
endif\n\
|
|
||||||
export E Q\n\
|
|
||||||
$(PROGRAM): $(OBJ)\n\
|
|
||||||
$(E) \" LINK \" $@\n\
|
|
||||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -o $@ $^ $(LIBS)\n\
|
|
||||||
%.o: %.c\n\
|
|
||||||
$(E) \" CC \" $@\n\
|
|
||||||
$(Q) $(CC) $(CFLAGS) $(DEFINES) -c $<\n\
|
|
||||||
clean:\n\
|
|
||||||
$(E) \" CLEAN\"\n\
|
|
||||||
$(Q) rm -f $(PROGRAM) $(OBJ)";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* author (s)
|
|
||||||
* package (s)
|
|
||||||
* package (s)
|
|
||||||
* description (s)
|
|
||||||
* year (d)
|
|
||||||
* package (s)
|
|
||||||
* author (s)
|
|
||||||
* package (s)
|
|
||||||
*/
|
|
||||||
static const char templ_README[] = "\
|
|
||||||
This is the README file for the %s %s distribution.\n\
|
|
||||||
%s %s\n\
|
|
||||||
Copyright (C) %d %s.\n\
|
|
||||||
Copying and distribution of this file, with or without modification,\n\
|
|
||||||
are permitted in any medium without royalty provided the copyright\n\
|
|
||||||
notice and this notice are preserved.\n\
|
|
||||||
See the files ./INSTALL* for building and installation instructions.\n\
|
|
||||||
Bug reports:\n\
|
|
||||||
Please include enough information for the maintainers to reproduce the\n\
|
|
||||||
problem. Generally speaking, that means:\n\
|
|
||||||
- the contents of any input files necessary to reproduce the bug\n\
|
|
||||||
and command line invocations of the program(s) involved (crucial!).\n\
|
|
||||||
- a description of the problem and any samples of the erroneous output.\n\
|
|
||||||
- the version number of the program(s) involved (use --version).\n\
|
|
||||||
- hardware, operating system, and compiler versions (uname -a).\n\
|
|
||||||
- unusual options you gave to configure, if any (see config.mak).\n\
|
|
||||||
- anything else that you think would be helpful.\n\
|
|
||||||
See README-dev for information on the development environment -- any\n\
|
|
||||||
interested parties are welcome. If you're a programmer and wish to\n\
|
|
||||||
contribute, this should get you started. If you're not a programmer,\n\
|
|
||||||
your help in writing test cases, checking documentation against the\n\
|
|
||||||
implementation, etc., would still be very much appreciated.\n\
|
|
||||||
%s %s is free software. See the file COPYING for copying conditions.";
|
|
||||||
#endif
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Standard GCK cleanup
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-q, --quiet silence output
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
QUIET=
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
--quiet|-q) QUIET="--quiet";;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information.'$1'." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
fatal() {
|
|
||||||
echo "fatal: $*" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
run() {
|
|
||||||
"$@" || fatal "could not run: $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
[ -d "./git" ] && fatal "must be run from parent directory"
|
|
||||||
|
|
||||||
run sh ./tools/format $QUIET
|
|
||||||
run rm -rf .cache
|
|
||||||
run rm -f compile_commands.json
|
|
||||||
run make distclean
|
|
||||||
|
|
||||||
if [ -z "$QUIET" ]; then
|
|
||||||
echo "done."
|
|
||||||
fi
|
|
||||||
43
tools/format
43
tools/format
@@ -1,43 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Format C source code
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-q, -quiet silence output
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
QUIET=
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
--quiet|-q) QUIET=true;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information.'$1'." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$QUIET" ]; then
|
|
||||||
find . -type f -name '*.c' ! -path './lib/*' ! -path './gcklib/*' -exec clang-format -i --verbose {} +
|
|
||||||
find . -type f -name '*.h' ! -path './lib/*' ! -path './gcklib/*' -exec clang-format -i --verbose {} +
|
|
||||||
else
|
|
||||||
find . -type f -name '*.c' ! -path './lib/*' ! -path './gcklib/*' -exec clang-format -i {} +
|
|
||||||
find . -type f -name '*.h' ! -path './lib/*' ! -path './gcklib/*' -exec clang-format -i {} +
|
|
||||||
fi
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
me=$0
|
|
||||||
scriptversion="1.0.0"
|
|
||||||
|
|
||||||
version="$me $scriptversion
|
|
||||||
|
|
||||||
Copyright (C) 2025 GCK.
|
|
||||||
This is free software; you are free to change and redistribute it.
|
|
||||||
There is NO WARRANTY, to the extent permitted by law."
|
|
||||||
|
|
||||||
usage="\
|
|
||||||
Usage: $me [OPTION]...
|
|
||||||
Update gcklib
|
|
||||||
|
|
||||||
Options:
|
|
||||||
|
|
||||||
--current get current gcklib commit
|
|
||||||
|
|
||||||
--help print this help and exit
|
|
||||||
--version output version information"
|
|
||||||
|
|
||||||
while test $# -gt 0; do
|
|
||||||
case $1 in
|
|
||||||
--help) echo "$usage"; exit 0;;
|
|
||||||
--version) echo "$version"; exit 0;;
|
|
||||||
--current) git submodule status gcklib;;
|
|
||||||
-*)
|
|
||||||
echo "$0: Unknown option '$1'." >&2
|
|
||||||
echo "$0: Try '--help' for more information.'$1'." >&2
|
|
||||||
exit 1;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
git submodule update --remote --rebase -- gcklib
|
|
||||||
22
usage.c
Normal file
22
usage.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
6
usage.h
Normal file
6
usage.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef USAGE_H_
|
||||||
|
#define USAGE_H_
|
||||||
|
|
||||||
|
void die(const char* err, ...);
|
||||||
|
|
||||||
|
#endif /* USAGE_H_ */
|
||||||
10
util.c
Normal file
10
util.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "util.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int getyear()
|
||||||
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
|
struct tm *t = localtime(&now);
|
||||||
|
|
||||||
|
return t->tm_year + 1900;
|
||||||
|
}
|
||||||
6
util.h
Normal file
6
util.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef UTIL_H_
|
||||||
|
#define UTIL_H_
|
||||||
|
|
||||||
|
int getyear();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
void version()
|
void version(void)
|
||||||
{
|
{
|
||||||
printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION);
|
printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION);
|
||||||
}
|
}
|
||||||
12
version.h
Normal file
12
version.h
Normal file
@@ -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_ */
|
||||||
13
wrapper.c
Normal file
13
wrapper.c
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
8
wrapper.h
Normal file
8
wrapper.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef WRAPPER_H_
|
||||||
|
#define WRAPPER_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void *xmalloc(size_t size);
|
||||||
|
|
||||||
|
#endif
|
||||||
43
yait.1
43
yait.1
@@ -1,43 +0,0 @@
|
|||||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
|
||||||
.TH YAIT "1" "November 2025" "yait beta 212" "User Commands"
|
|
||||||
.SH NAME
|
|
||||||
yait - An opinionated C project generator
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B yait
|
|
||||||
[\fI\,OPTION\/\fR]... [\fI\,project-name\/\fR]...
|
|
||||||
.SH DESCRIPTION
|
|
||||||
Generates an opinionated C project.
|
|
||||||
.TP
|
|
||||||
\fB\-\-help\fR
|
|
||||||
display this help and exit
|
|
||||||
.TP
|
|
||||||
\fB\-\-version\fR
|
|
||||||
display version information and exit
|
|
||||||
.TP
|
|
||||||
\fB\-m\fR DESC
|
|
||||||
Set the program description (default "Does a thing")
|
|
||||||
.TP
|
|
||||||
\fB\-\-author\fR NAME
|
|
||||||
Set the program author (default git username|system username)
|
|
||||||
.TP
|
|
||||||
\fB\-\-license\fR LICENSE
|
|
||||||
Set the program license (default BSD)
|
|
||||||
.SH "ADDITIONAL INFORMATION"
|
|
||||||
.UR https://github.com/gck-org/yait
|
|
||||||
.SH COPYRIGHT
|
|
||||||
Copyright \(co 2025 GCK.
|
|
||||||
.br
|
|
||||||
This is free software: you are free to change and redistribute it.
|
|
||||||
There is NO WARRNTY, to the extent permitted by law.
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
The full documentation for
|
|
||||||
.B yait
|
|
||||||
is maintained as a Texinfo manual. If the
|
|
||||||
.B info
|
|
||||||
and
|
|
||||||
.B yait
|
|
||||||
programs are properly installed at your site, the command
|
|
||||||
.IP
|
|
||||||
.B info yait
|
|
||||||
.PP
|
|
||||||
should give you access to the complete manual.
|
|
||||||
Reference in New Issue
Block a user