all: update to match GCK standard
This commit is contained in:
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=c23, -Ilib, -I.]
|
||||
|
||||
Diagnostics:
|
||||
ClangTidy:
|
||||
Add: [clang-diagnostic-*]
|
||||
Remove: []
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "gcklib"]
|
||||
path = gcklib
|
||||
url = https://github.com/gck-org/gcklib
|
||||
51
Makefile
51
Makefile
@@ -1,3 +1,37 @@
|
||||
#
|
||||
# Makefile for yait (requires GNU make)
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
PACKAGE := yait
|
||||
|
||||
SRCS := $(wildcard src/*.c) $(wildcard lib/*.c)
|
||||
@@ -6,11 +40,11 @@ OBJS := $(patsubst src/%.c,build/obj/%.o,$(SRCS))
|
||||
BIN := bin/$(PACKAGE)
|
||||
|
||||
COMMIT := $(shell git rev-list --count --all)
|
||||
FLAGS := -I. -DCOMMIT=$(COMMIT) -DSHOW_TRACE --std=c23
|
||||
FLAGS := -I. -DCOMMIT=$(COMMIT) --std=c2x -pedantic
|
||||
|
||||
VERSION := $(shell git describe --tags --always --dirty)
|
||||
TARBALL := $(PACKAGE)-$(VERSION).tar.gz
|
||||
RELEASE_FILES := doc src lib COPYING AUTHORS README yait.1 INSTALL Makefile configure config.h
|
||||
RELEASE_FILES := doc src lib COPYING AUTHORS README hello.1 INSTALL Makefile configure config.h
|
||||
|
||||
-include config.mak
|
||||
|
||||
@@ -20,7 +54,7 @@ all:
|
||||
@exit 1
|
||||
else
|
||||
|
||||
all: build $(BIN)
|
||||
all: build $(BIN) doc
|
||||
|
||||
build:
|
||||
mkdir -p bin
|
||||
@@ -37,18 +71,23 @@ endif
|
||||
install: $(BIN)
|
||||
cp $(BIN) $(PREFIX)
|
||||
|
||||
doc:
|
||||
$(MAKE) -C doc all
|
||||
|
||||
uninstall:
|
||||
$(RM) $(PREFIX)$(PACKAGE)
|
||||
|
||||
clean:
|
||||
$(RM) $(BIN)
|
||||
$(RM) -r bin
|
||||
$(RM) -r build
|
||||
$(MAKE) -C doc clean
|
||||
|
||||
distclean: clean
|
||||
$(RM) config.mak
|
||||
$(RM) config.mak config.status
|
||||
$(RM) $(TARBALL)
|
||||
$(MAKE) -C doc clean
|
||||
|
||||
release: clean all
|
||||
tar -czf $(TARBALL) $(RELEASE_FILES)
|
||||
|
||||
.PHONY: all clean distclean install uninstall build release
|
||||
.PHONY: all clean distclean install uninstall build release doc
|
||||
|
||||
2
README
2
README
@@ -1,5 +1,5 @@
|
||||
This is the README file for the GCK yait distribution.
|
||||
yait generates a optioned C project.
|
||||
yait is an optionated C project generator
|
||||
|
||||
Copyright (C) 2025 GCK.
|
||||
|
||||
|
||||
@@ -6,6 +6,14 @@ This README.dev file describes the development environment.
|
||||
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 package. The only place
|
||||
where this commonly differs is in non-binary or library packages.
|
||||
|
||||
|
||||
Build system
|
||||
------------
|
||||
|
||||
|
||||
2
THANKS
2
THANKS
@@ -8,8 +8,6 @@ Additional contributors to GCK yait.
|
||||
|
||||
Thanks to:
|
||||
|
||||
GNU & UNIX for command design ideas.
|
||||
|
||||
GNU hello for layout ideas.
|
||||
|
||||
The Linux Kernel for the code formatting guidelines.
|
||||
|
||||
8
TODO
8
TODO
@@ -1,10 +1,8 @@
|
||||
GCK yait - TODO
|
||||
GCK yait --- TODO
|
||||
|
||||
Todo:
|
||||
|
||||
* Fix package.c generation
|
||||
* Add git integration: git init, add the gcklib submodule, ./gcklib-tool --import proginfo
|
||||
* -p: specify path
|
||||
* sanitize input (gcklib feature)
|
||||
* update copyright every January 1st
|
||||
* pre-commit scripts
|
||||
|
||||
end of file TODO
|
||||
|
||||
84
bootstrap
Executable file
84
bootstrap
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh
|
||||
# gck.bootstrap - Prepares the build enviroment
|
||||
# FEATURES:
|
||||
# - Initializes submodules
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./bootstrap
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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
|
||||
|
||||
# End: bootstrap
|
||||
101
build-aux/compile
Executable file
101
build-aux/compile
Executable file
@@ -0,0 +1,101 @@
|
||||
#!/bin/sh
|
||||
# gck.compile - Compile wrapper for GCK distributions
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./compile
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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"
|
||||
|
||||
# End: compile
|
||||
75
build-aux/generate-artifacts
Executable file
75
build-aux/generate-artifacts
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# gck.generate-artifacts - Generate compile_commands.json
|
||||
#
|
||||
# FEATURES:
|
||||
# - Generate compile_commands.json
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./generate-artifacts
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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
|
||||
|
||||
mkdir -p build
|
||||
bear --output build/compile_commands.json -- make -B -j"$(nproc)"
|
||||
|
||||
# End: generate-artifacts
|
||||
2
config.h
2
config.h
@@ -3,8 +3,6 @@
|
||||
|
||||
/* Program information */
|
||||
#define PROGRAM "yait"
|
||||
#define LICENSE_LINE \
|
||||
"License BSD-3-Clause: BSD-3-Clause <https://opensource.org/license/bsd-3-clause>"
|
||||
#define AUTHORS "GCK"
|
||||
#define VERSION "beta"
|
||||
#define YEAR 2025
|
||||
|
||||
244
configure
vendored
244
configure
vendored
@@ -1,90 +1,200 @@
|
||||
#!/bin/sh
|
||||
# gck.configure - Prepares the build system for GCK distributions
|
||||
# FEATURES:
|
||||
# - Generate config.mak
|
||||
# - Sets C Flags
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./configure
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
me=$0
|
||||
scriptversion="1.0.1"
|
||||
|
||||
To assign environment variables (e.g., CC, CFLAGS...), specify them as
|
||||
VAR=VALUE.
|
||||
version="make $scriptversion
|
||||
|
||||
CC C compiler command [detected]
|
||||
CFLAGS C compiler flags [-g, ...]
|
||||
LDFLAGS C linker flags
|
||||
Copyright (C) 2025 GCK.
|
||||
|
||||
--prefix=<path> Set the install path
|
||||
--debug Flags for debug build, overrides CFLAGS
|
||||
This is free software; you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law."
|
||||
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
usage="\
|
||||
Usage: $me [OPTION]...
|
||||
Prepares the build system for GCK distributions
|
||||
|
||||
cmdexists() { type "$1" >/dev/null 2>&1 ; }
|
||||
trycc() { [ -z "$CC" ] && cmdexists "$1" && CC=$1 ; }
|
||||
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="-std=c23"
|
||||
LDFLAGS=
|
||||
CFLAGS=-pedantic
|
||||
CC=
|
||||
args_old=$@
|
||||
|
||||
printf "checking for C compiler... "
|
||||
trycc gcc
|
||||
trycc clang
|
||||
trycc cc
|
||||
trycc icx
|
||||
printf "%s\n" "$CC"
|
||||
|
||||
DEBUG=false
|
||||
for arg; do
|
||||
case "$arg" in
|
||||
--help|-h) usage ;;
|
||||
--prefix=*) prefix=${arg#*=} ;;
|
||||
--debug) DEBUG=true ;;
|
||||
CFLAGS=*) CFLAGS=${arg#*=} ;;
|
||||
LDFLAGS=*) LDFLAGS=${arg#*=} ;;
|
||||
CC=*) CC=${arg#*=} ;;
|
||||
*) printf "Unrecognized option %s\n" "$arg" ;;
|
||||
esac
|
||||
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... "
|
||||
tmpc="$(mktemp -d)/test.c"
|
||||
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"
|
||||
printf "yes\n"
|
||||
else
|
||||
printf "no; %s\n" "$output"
|
||||
exit 1
|
||||
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
|
||||
|
||||
GDEBUGCFLAGS="-std=c23 -O0 -g3 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wconversion -Wsign-conversion -Wcast-qual -Wcast-align=strict -Wpointer-arith -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wunreachable-code -Wswitch-enum -fanalyzer -fsanitize=undefined,address -fstack-protector-strong -D_FORTIFY_SOURCE=3"
|
||||
CDEBUGCFLAGS="-std=gnu2x -O0 -g3 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wdouble-promotion -Wformat=2 -Wnull-dereference -Wconversion -Wsign-conversion -Wcast-qual -Wcast-align=strict -Wpointer-arith -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wunreachable-code -Wswitch-enum -fanalyzer -fsanitize=undefined,address -fstack-protector-strong -D_FORTIFY_SOURCE=3"
|
||||
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.
|
||||
#
|
||||
|
||||
if [ -z "$DEBUG" ]; then
|
||||
case "$CC" in
|
||||
gcc) CFLAGS="$GDEBUGFLAGS";;
|
||||
clang) CFLAGS="$CDEBUGFLAGS";;
|
||||
*) ;;
|
||||
esac
|
||||
else
|
||||
case "$CC" in
|
||||
gcc) ;;
|
||||
clang) ;;
|
||||
*) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case "$OSTYPE" in
|
||||
cygwin|msys)
|
||||
echo "enabling windows specific flags"
|
||||
CFLAGS="-v $CFLAGS"
|
||||
;;
|
||||
esac
|
||||
|
||||
printf "creating config.mak... "
|
||||
printf "config.status: recreating config.mak... "
|
||||
{
|
||||
printf "PREFIX=%s\n" "$prefix"
|
||||
printf "CFLAGS=%s\n" "$CFLAGS"
|
||||
printf "LDFLAGS=%s\n" "$LDFLAGS"
|
||||
printf "CC=%s\n" "$CC"
|
||||
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"
|
||||
|
||||
# End: configure
|
||||
|
||||
22
doc/Makefile
Normal file
22
doc/Makefile
Normal file
@@ -0,0 +1,22 @@
|
||||
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,4 +1,2 @@
|
||||
@set UPDATED 12 September 2025
|
||||
@set UPDATED-MONTH September 2025
|
||||
@set EDITION beta
|
||||
@set VERSION beta
|
||||
@set UPDATED 2025-01-01
|
||||
@set VERSION 1.0
|
||||
248
doc/yait.texi
248
doc/yait.texi
@@ -1,8 +1,8 @@
|
||||
\input texinfo @c -*-texinfo-*-
|
||||
@c %**start of header
|
||||
@setfilename yait.info
|
||||
@setfilename hello.info
|
||||
@include version.texi
|
||||
@settitle GCK yait @value{VERSION}
|
||||
@settitle GCK Hello @value{VERSION}
|
||||
|
||||
@c Define a new index for options.
|
||||
@defcodeindex op
|
||||
@@ -12,8 +12,8 @@
|
||||
@c %**end of header
|
||||
|
||||
@copying
|
||||
This manual is for GCK yait (version @value{VERSION}, @value{UPDATED}),
|
||||
which generates an optionated C project.
|
||||
This manual is for GCK Hello (version @value{VERSION}, @value{UPDATED}),
|
||||
which greets you nicely.
|
||||
|
||||
Copyright @copyright{} 2025 GCK.
|
||||
|
||||
@@ -25,7 +25,7 @@ notice and this notice are preserved.
|
||||
@end copying
|
||||
|
||||
@titlepage
|
||||
@title GCK yait
|
||||
@title GCK Hello
|
||||
@subtitle for version @value{VERSION}, @value{UPDATED}
|
||||
@page
|
||||
@vskip 0pt plus 1filll
|
||||
@@ -37,16 +37,16 @@ notice and this notice are preserved.
|
||||
|
||||
@ifnottex
|
||||
@node Top
|
||||
@top GNU Hello
|
||||
@top GCK Hello
|
||||
|
||||
This manual is for GCK yait (version @value{VERSION}, @value{UPDATED}),
|
||||
which generates an optionated C project.
|
||||
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{yait}.
|
||||
* Invoking hello:: How to run @command{yait}.
|
||||
* 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
|
||||
@@ -58,113 +58,35 @@ which generates an optionated C project.
|
||||
@cindex greetings
|
||||
@cindex overview
|
||||
|
||||
The GNU @command{hello} program
|
||||
(@url{http://www.gnu.org/software/hello/}) produces a familiar,
|
||||
friendly greeting. It allows nonprogrammers to use a classic computer
|
||||
science tool which would otherwise be unavailable to them. Because it
|
||||
is protected by the GNU General Public License, users are free (in
|
||||
perpetuity) to share and change it.
|
||||
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 joke, not
|
||||
Not to spoil the joke, but of course the practical purpose of GNU
|
||||
Hello is to serve as a minimal example of a GNU package. So, although
|
||||
most manuals don't need to discuss the implementation of the programs
|
||||
they document, that is part of the goal here.
|
||||
@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 GNU coding standards
|
||||
@cindex GNU maintainer standards
|
||||
@cindex standards, GNU coding
|
||||
@cindex standards, GNU maintainer
|
||||
First, GNU Hello follows the GNU coding standards
|
||||
(@pxref{Top,,Preface,standards,GNU Coding Standards}) and GNU
|
||||
maintainer standards (@pxref{Top,,Preface,maintain, Information for
|
||||
GNU Maintainers}). These are the basic documents which all GNU
|
||||
packages should adhere to.
|
||||
|
||||
The Hello package also implements recommended development practices
|
||||
not embodied in the standards, using other GNU packages and features:
|
||||
@cindex features
|
||||
GCK Hello has the following features:
|
||||
|
||||
@itemize @bullet
|
||||
@item
|
||||
@cindex Automake
|
||||
@cindex Autoconf
|
||||
It uses Automake (@pxref{Top,,Introduction,automake,GNU Automake}) and
|
||||
hence also Autoconf (@pxref{Top,,Introduction,autoconf,GNU Autoconf})
|
||||
for configuration.
|
||||
|
||||
@item
|
||||
@cindex Gnulib
|
||||
@cindex @command{srclist-update} script
|
||||
@cindex @file{README-dev} source file
|
||||
It uses Gnulib (@pxref{Top,,Introduction,gnulib,GNU Gnulib}) to enhance
|
||||
portability and avoid duplication of common sources. Both
|
||||
@code{gnulib-tool} and @code{srclist-update} are used, for purposes of
|
||||
example. See the @file{README-dev} file in the distribution.
|
||||
|
||||
@item
|
||||
@cindex Gettext
|
||||
GNU Gettext (@pxref{Top,,Introduction,gettext,GNU Gettext}) is used
|
||||
for internationalization support. Hello's greeting has been translated
|
||||
into many languages.
|
||||
|
||||
@item
|
||||
@opindex --help
|
||||
Internally, Hello uses the GNU @code{getopt_long} function
|
||||
(@pxref{Getopt Long Options,,,libc,GNU C Library}) to parse options,
|
||||
thus supporting GNU-style long options such as @option{--help}.
|
||||
|
||||
@item
|
||||
@cindex Help2man
|
||||
The Hello Man page is generated with GNU @code{help2man}
|
||||
(@pxref{Top,,Overview,help2man,GNU @code{help2man}}) from the
|
||||
@option{--help} output. This relieves the maintainers from the burden
|
||||
of updating separate man documentation, yet provides a reasonable
|
||||
overview for man devotees.
|
||||
|
||||
@item
|
||||
@cindex Texinfo
|
||||
Finally, Texinfo (@pxref{Top,,Introduction,texinfo,Texinfo}) is the
|
||||
documentation format for this manual. It supports output in Info,
|
||||
HTML, PDF, DVI, plain text, XML, and other formats.
|
||||
|
||||
@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
|
||||
|
||||
GNU Hello is implemented in C@. The GNU Gettext distribution contains
|
||||
``hello world'' examples in many other programming languages; see the
|
||||
Gettext home page at @url{http://www.gnu.org/software/gettext/}.
|
||||
@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 @file{Makefile.am} targets
|
||||
The top-level @file{Makefile.am} in Hello also contains a few special
|
||||
targets for other projects to adapt as desired:
|
||||
|
||||
@table @code
|
||||
@item diff
|
||||
Make a diff from the previous release, assuming the current tarball is
|
||||
in the current tarball.
|
||||
|
||||
@item po-check
|
||||
Verify that all source files using @code{_()} are included for
|
||||
translation in @file{po/POTFILES.in}, so translators will have all the
|
||||
messages.
|
||||
|
||||
@item wwwdoc
|
||||
Sample procedure for updating the manual on the GNU web site, in this
|
||||
case @url{http://www.gnu.org/software/hello/manual/}.
|
||||
@end table
|
||||
|
||||
@cindex authors
|
||||
@cindex Haertel, Mike
|
||||
@cindex MacKenzie, David
|
||||
@cindex Brittenson, Jan
|
||||
@cindex Hannum, Charles
|
||||
@cindex McGrath, Roland
|
||||
@cindex Friedman, Noah
|
||||
@cindex Eichwalder, Karl
|
||||
@cindex King, The
|
||||
@cindex Berry, Karl
|
||||
GNU Hello was written by Mike Haertel, David MacKenzie, Jan
|
||||
Brittenson, Charles Hannum, Roland McGrath, Noah Friedman, Karl
|
||||
Eichwalder, Karl Berry, and @w{The King}.
|
||||
@cindex license
|
||||
This program is distributed under the BSD 3-Clause License, allowing
|
||||
free use, modification, and distribution with minimal restrictions.
|
||||
|
||||
|
||||
@node Sample output
|
||||
@@ -173,24 +95,35 @@ Eichwalder, Karl Berry, and @w{The King}.
|
||||
@cindex sample output
|
||||
@cindex examples
|
||||
|
||||
Here are some examples of running GNU Hello.
|
||||
Here are some examples of running GCK Hello.
|
||||
|
||||
This is the output of the command @samp{hello}:
|
||||
|
||||
@example
|
||||
Hello, world!
|
||||
Hello, World!
|
||||
@end example
|
||||
|
||||
This is the output of the command @samp{hello --traditional}:
|
||||
This is the output of the command @samp{hello Alice}:
|
||||
|
||||
@example
|
||||
hello, world
|
||||
Hello, Alice!
|
||||
@end example
|
||||
|
||||
This is the output of the command @samp{hello --greeting=hi}:
|
||||
This is the output of the command @samp{hello Alice Bob}:
|
||||
|
||||
@example
|
||||
hi
|
||||
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
|
||||
|
||||
|
||||
@@ -205,57 +138,28 @@ hi
|
||||
The format for running the @command{hello} program is:
|
||||
|
||||
@example
|
||||
hello @var{option} @dots{}
|
||||
hello [@var{option}]... [@var{name}]...
|
||||
@end example
|
||||
|
||||
With no options, @command{hello} prints the greeting @samp{Hello,
|
||||
world!}.
|
||||
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 --greeting=@var{text}
|
||||
@itemx -g @var{text}
|
||||
@opindex --greeting
|
||||
@opindex -g
|
||||
Output @var{text} instead of the default greeting.
|
||||
|
||||
@item --help
|
||||
@itemx -h
|
||||
@opindex --help
|
||||
@opindex -h
|
||||
Print an informative help message on standard output and exit
|
||||
successfully.
|
||||
|
||||
@cindex environment variables, help for
|
||||
@c This comment prevents `make syntax-check' from diagnosing a doubled word "for\nFor"
|
||||
For the @option{--help} output of GNU programs, it's strongly
|
||||
encouraged to include a brief (one or two sentences) description of
|
||||
what the program does, as well as the synopsis of how to run the
|
||||
program. Any environment variables which affect execution should also
|
||||
be mentioned (Hello doesn't have any).
|
||||
|
||||
@item --traditional
|
||||
@itemx -t
|
||||
@opindex --traditional
|
||||
@opindex -t
|
||||
@cindex traditional
|
||||
@cindex modern
|
||||
Output the traditional greeting message @samp{hello, world}.
|
||||
|
||||
@item --version
|
||||
@itemx -v
|
||||
@opindex --version
|
||||
@opindex -v
|
||||
Print the version number and licensing information of Hello on
|
||||
standard output and then exit successfully.
|
||||
|
||||
@end table
|
||||
|
||||
If more than one of the greeting options (@option{-g},
|
||||
@option{-t}, and their long-named equivalents) is specified, whichever
|
||||
comes last takes precedence.
|
||||
|
||||
|
||||
@node Reporting bugs
|
||||
@chapter Reporting bugs
|
||||
@@ -264,8 +168,8 @@ comes last takes precedence.
|
||||
@cindex problems
|
||||
@cindex reporting bugs
|
||||
|
||||
To report bugs, suggest enhancements or otherwise discuss GNU Hello,
|
||||
please send electronic mail to @email{bug-hello@@gnu.org}.
|
||||
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
|
||||
@@ -289,15 +193,43 @@ 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}} (@pxref{Top,, Overview, diff, Comparing and Merging Files}) and
|
||||
include @file{ChangeLog} entries (@pxref{Change Log,,, emacs, The GNU
|
||||
Emacs Manual}). Please follow the existing coding style.
|
||||
-c}} and include @file{ChangeLog} entries. Please follow the existing
|
||||
coding style.
|
||||
|
||||
|
||||
@node GNU Free Documentation License
|
||||
@appendix GNU Free Documentation License
|
||||
@node BSD License
|
||||
@appendix BSD License
|
||||
|
||||
@include fdl.texi
|
||||
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
|
||||
|
||||
255
lib/err.c
255
lib/err.c
@@ -13,8 +13,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -26,14 +26,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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>
|
||||
@@ -50,165 +51,143 @@
|
||||
#define NOTE "\x1B[1;94m"
|
||||
#define HINT "\x1B[38;5;166m"
|
||||
|
||||
static bool err_support_color(void)
|
||||
{
|
||||
static bool err_support_color(void) {
|
||||
#ifdef NOCOLOR
|
||||
return false;
|
||||
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;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%serror%s: ", ERROR, RESET);
|
||||
} else {
|
||||
fputs("error: ", stderr);
|
||||
}
|
||||
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
void fatalf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
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);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%sfatal error%s: ", ERROR, RESET);
|
||||
} else {
|
||||
fputs("fatal error: ", stderr);
|
||||
}
|
||||
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
|
||||
fputs("program terminated.\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
fputs("program terminated.\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
void warnf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
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);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%swarning%s: ", WARN, RESET);
|
||||
} else {
|
||||
fputs("warning: ", stderr);
|
||||
}
|
||||
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
void notef(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
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);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%snote%s: ", NOTE, RESET);
|
||||
} else {
|
||||
fputs("note: ", stderr);
|
||||
}
|
||||
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
vfprintf(stderr, format, args);
|
||||
fputc('\n', stderr);
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
void hintf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
void hintf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%shint: ", HINT);
|
||||
} else {
|
||||
fputs("hint: ", stderr);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%shint: ", HINT);
|
||||
} else {
|
||||
fputs("hint: ", stderr);
|
||||
}
|
||||
|
||||
vfprintf(stderr, format, args);
|
||||
vfprintf(stderr, format, args);
|
||||
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%s\n", RESET);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
if (err_support_color()) {
|
||||
fprintf(stderr, "%s\n", RESET);
|
||||
} else {
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void errorfa(int code)
|
||||
{
|
||||
errorf(strerror(code));
|
||||
}
|
||||
void errorfa(int code) { errorf(strerror(code)); }
|
||||
|
||||
void fatalfa(int code)
|
||||
{
|
||||
fatalf(strerror(code));
|
||||
}
|
||||
void fatalfa(int code) { fatalf(strerror(code)); }
|
||||
|
||||
void notefa(int code)
|
||||
{
|
||||
notef(strerror(code));
|
||||
}
|
||||
void notefa(int code) { notef(strerror(code)); }
|
||||
|
||||
void warnfa(int code)
|
||||
{
|
||||
warnf(strerror(code));
|
||||
}
|
||||
void warnfa(int code) { warnf(strerror(code)); }
|
||||
|
||||
void hintfa(int code)
|
||||
{
|
||||
hintf(strerror(code));
|
||||
}
|
||||
void hintfa(int code) { hintf(strerror(code)); }
|
||||
|
||||
/* end of file err.c */
|
||||
|
||||
41
lib/err.h
41
lib/err.h
@@ -15,8 +15,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -28,14 +28,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
@@ -54,16 +55,16 @@ 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)
|
||||
#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
|
||||
|
||||
170
lib/flag.c
170
lib/flag.c
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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>
|
||||
@@ -42,83 +43,78 @@
|
||||
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;
|
||||
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 */
|
||||
|
||||
23
lib/flag.h
23
lib/flag.h
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,21 +22,22 @@
|
||||
*
|
||||
* 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.
|
||||
* 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);
|
||||
const struct option *longopts, int *longindex);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
244
lib/fs.c
244
lib/fs.c
@@ -15,8 +15,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -28,14 +28,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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>
|
||||
@@ -52,159 +53,150 @@
|
||||
#include "xmem.h"
|
||||
|
||||
#if defined(FS_ERROR_ON)
|
||||
#define RETURN(code) \
|
||||
errorfa(code); \
|
||||
return code
|
||||
#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) {
|
||||
char *fs_read(const char *path) {
|
||||
FILE *fptr = fopen(path, "r");
|
||||
if (!fptr) {
|
||||
#if defined(FS_ERROR_ON)
|
||||
errorfa(errno);
|
||||
errorfa(errno);
|
||||
#elif defined(FS_FATAL_ON)
|
||||
fatalfa(errno);
|
||||
fatalfa(errno);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t cap = 1024;
|
||||
size_t len = 0;
|
||||
char *buf = xmalloc(cap);
|
||||
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';
|
||||
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;
|
||||
fclose(fptr);
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool fs_exists(const char *path)
|
||||
{
|
||||
FILE *fptr;
|
||||
bool exists;
|
||||
bool fs_exists(const char *path) {
|
||||
FILE *fptr;
|
||||
bool exists;
|
||||
|
||||
fptr = fopen(path, "r");
|
||||
if (fptr) {
|
||||
exists = true;
|
||||
} else {
|
||||
exists = false;
|
||||
}
|
||||
fptr = fopen(path, "r");
|
||||
if (fptr) {
|
||||
exists = true;
|
||||
} else {
|
||||
exists = false;
|
||||
}
|
||||
|
||||
fclose(fptr);
|
||||
return exists;
|
||||
fclose(fptr);
|
||||
return exists;
|
||||
}
|
||||
|
||||
int fs_append(const char *path, const char *format, ...)
|
||||
{
|
||||
FILE *fp = fopen(path, "a");
|
||||
if (!fp)
|
||||
RETURN(errno);
|
||||
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);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int ret = vfprintf(fp, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (ret < 0) {
|
||||
fclose(fp);
|
||||
RETURN(errno);
|
||||
}
|
||||
if (ret < 0) {
|
||||
fclose(fp);
|
||||
RETURN(errno);
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0)
|
||||
RETURN(errno);
|
||||
if (fclose(fp) != 0)
|
||||
RETURN(errno);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fs_del(const char *path)
|
||||
{
|
||||
RETURN(remove(path));
|
||||
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_new(const char *path)
|
||||
{
|
||||
size_t len;
|
||||
int fd;
|
||||
int fs_write(const char *path, const char *format, ...) {
|
||||
FILE *fptr = fopen(path, "w");
|
||||
if (!fptr)
|
||||
RETURN(-1);
|
||||
|
||||
if (path == NULL) {
|
||||
errno = EINVAL;
|
||||
RETURN(-1);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
int ret = vfprintf(fptr, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
len = strlen(path);
|
||||
if (len == 0) {
|
||||
errno = EINVAL;
|
||||
RETURN(-1);
|
||||
}
|
||||
if (ret < 0) {
|
||||
fclose(fptr);
|
||||
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);
|
||||
}
|
||||
if (fclose(fptr) != 0)
|
||||
RETURN(-1);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fs_write(const char *path, const char *format, ...)
|
||||
{
|
||||
FILE *fptr = fopen(path, "w");
|
||||
if (!fptr)
|
||||
RETURN(-1);
|
||||
FILE *fs_temp() {
|
||||
FILE *fptr = tmpfile();
|
||||
|
||||
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 (!fptr) {
|
||||
#if defined(FS_ERROR_ON)
|
||||
errorf("tmp failed");
|
||||
errorf("tmp failed");
|
||||
#elif defined(FS_FATAL_ON)
|
||||
fatalf("tmp failed");
|
||||
fatalf("tmp failed");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fptr;
|
||||
return fptr;
|
||||
}
|
||||
|
||||
/* end of file fs.c */
|
||||
|
||||
21
lib/fs.h
21
lib/fs.h
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,61 +22,56 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 <config.h>
|
||||
#include <libgen.h>
|
||||
#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 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_try_help()
|
||||
{
|
||||
printf("Try '%s --help' for more information\n", prog_name);
|
||||
}
|
||||
|
||||
void emit_version()
|
||||
{
|
||||
printf("\
|
||||
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);
|
||||
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")) {
|
||||
emit_version();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
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")) {
|
||||
emit_version();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* end of file proginfo.c */
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
@@ -43,7 +44,7 @@ void emit_try_help();
|
||||
void emit_version();
|
||||
|
||||
int parse_standard_options(int argc, char **argv, void (*print_help)(),
|
||||
void (*print_version)());
|
||||
void (*print_version)());
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
114
lib/say.c
114
lib/say.c
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,84 +22,80 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "xmem.h"
|
||||
|
||||
void alert()
|
||||
{
|
||||
fputs("\a", stderr);
|
||||
fflush(stderr);
|
||||
return;
|
||||
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 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 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;
|
||||
}
|
||||
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
|
||||
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);
|
||||
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);
|
||||
fflush(stdout); // ensure it's visible immediately
|
||||
printf("\0338"); // restore cursor (ESC 8)
|
||||
fflush(stdout);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
_Noreturn void die(const char *msg)
|
||||
{
|
||||
fputs(msg, stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
_Noreturn void die(const char *msg) {
|
||||
fputs(msg, stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* end of file say.c */
|
||||
|
||||
21
lib/say.h
21
lib/say.h
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
72
lib/textc.c
72
lib/textc.c
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,58 +22,52 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 <string.h>
|
||||
#include <ctype.h>
|
||||
#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 *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 *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 *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_trim(char *s) { return NULL; }
|
||||
|
||||
char *textc_pad_left(int count, char *s, char pad)
|
||||
{
|
||||
char *buffer = xmalloc(strlen(s) + 1);
|
||||
char *textc_pad_left(int count, char *s, char pad) {
|
||||
char *buffer = xmalloc(strlen(s) + 1);
|
||||
|
||||
free(buffer);
|
||||
buffer = "NOT IMPLEMENTED";
|
||||
free(buffer);
|
||||
buffer = "NOT IMPLEMENTED";
|
||||
|
||||
return buffer;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* end of file textc.c */
|
||||
|
||||
21
lib/textc.h
21
lib/textc.h
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
47
lib/xmem.c
47
lib/xmem.c
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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>
|
||||
@@ -39,26 +40,20 @@
|
||||
|
||||
#include "xmem.h"
|
||||
|
||||
void *ensure_nonnull(void *ptr)
|
||||
{
|
||||
if (ptr == NULL)
|
||||
fatalf("memory exhausted");
|
||||
return ptr;
|
||||
void *ensure_nonnull(void *ptr) {
|
||||
if (ptr == NULL)
|
||||
fatalf("memory exhausted");
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *xmalloc(size_t size)
|
||||
{
|
||||
return ensure_nonnull(malloc(size));
|
||||
void *xmalloc(size_t size) { return ensure_nonnull(malloc(size)); }
|
||||
|
||||
void *xrealloc(void *ptr, size_t size) {
|
||||
return ensure_nonnull(realloc(ptr, 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));
|
||||
void *xcalloc(size_t nmemb, size_t size) {
|
||||
return ensure_nonnull(calloc(nmemb, size));
|
||||
}
|
||||
|
||||
/* end of file xmem.c */
|
||||
|
||||
21
lib/xmem.h
21
lib/xmem.h
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
[NAME]
|
||||
yait - an optionated C project generator
|
||||
yait - An opinionated C project generator
|
||||
[ADDITIONAL INFORMATION]
|
||||
.UR https://github.com/gck-org/yait
|
||||
|
||||
76
scripts/manual/make
Executable file
76
scripts/manual/make
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
# gck.make - Generate manual page
|
||||
#
|
||||
# FEATURES:
|
||||
# - Generate manual page
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./make
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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
|
||||
|
||||
# End: make
|
||||
@@ -9,8 +9,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -22,14 +22,15 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 LICENCES_H
|
||||
|
||||
477
src/yait.c
477
src/yait.c
@@ -20,8 +20,8 @@
|
||||
* 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.
|
||||
* 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
|
||||
@@ -33,182 +33,177 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 <config.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "licence.h"
|
||||
#include "../lib/err.h"
|
||||
#include "../lib/fs.h"
|
||||
#include "../lib/proginfo.h"
|
||||
#include "../lib/textc.h"
|
||||
#include "../lib/say.h"
|
||||
#include "../lib/textc.h"
|
||||
#include "licence.h"
|
||||
|
||||
typedef enum { MIT, GPL, BSD, UNL } licence_t;
|
||||
|
||||
static const struct option longopts[] = {
|
||||
{ "author", required_argument, 0, 'a' },
|
||||
{ "licence", required_argument, 0, 'l' },
|
||||
{ "quiet", no_argument, 0, 'q' },
|
||||
{ "force", no_argument, 0, 'f' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
static const struct option longopts[] = {{"author", required_argument, 0, 'a'},
|
||||
{"licence", required_argument, 0, 'l'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
static int exit_status;
|
||||
|
||||
static void print_help();
|
||||
static void print_version();
|
||||
|
||||
static char *get_name()
|
||||
{
|
||||
int fds[2];
|
||||
if (pipe(fds) == -1)
|
||||
goto sysuser;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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");
|
||||
return str_dup("author");
|
||||
}
|
||||
|
||||
static int get_year()
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *t = localtime(&now);
|
||||
static int get_year() {
|
||||
time_t now = time(NULL);
|
||||
struct tm *t = localtime(&now);
|
||||
|
||||
// The tm_year member stores years since 1900, so add 1900 to get the actual year
|
||||
return t->tm_year + 1900;
|
||||
// The tm_year member stores years since 1900, so add 1900 to get the actual
|
||||
// year
|
||||
return t->tm_year + 1900;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int optc;
|
||||
int lose = 0;
|
||||
char *package;
|
||||
bool quiet = false;
|
||||
bool force = false;
|
||||
bool editor = false;
|
||||
bool shell = false;
|
||||
char *author = get_name();
|
||||
exit_status = EXIT_SUCCESS;
|
||||
int year = get_year();
|
||||
licence_t licence = BSD;
|
||||
set_prog_name(argv[0]);
|
||||
int main(int argc, char **argv) {
|
||||
int optc;
|
||||
int lose = 0;
|
||||
char *package;
|
||||
bool quiet = false;
|
||||
bool force = false;
|
||||
bool editor = false;
|
||||
bool shell = false;
|
||||
char *author = get_name();
|
||||
exit_status = EXIT_SUCCESS;
|
||||
int year = get_year();
|
||||
licence_t licence = BSD;
|
||||
set_prog_name(argv[0]);
|
||||
|
||||
parse_standard_options(argc, argv, print_help, print_version);
|
||||
parse_standard_options(argc, argv, print_help, print_version);
|
||||
|
||||
while ((optc = getopt_long(argc, argv, "a:l:EqfS", longopts, NULL)) !=
|
||||
-1)
|
||||
switch (optc) {
|
||||
case 'a':
|
||||
if (optarg) {
|
||||
if (author)
|
||||
free(author);
|
||||
author = str_dup(optarg);
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (!strcmp(optarg, "list")) {
|
||||
puts("BSD\nGPL\nMIT\nUNL");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
if (!strcmp(optarg, "GPL"))
|
||||
licence = GPL;
|
||||
else if (!strcmp(optarg, "MIT"))
|
||||
licence = MIT;
|
||||
else if (!strcmp(optarg, "BSD"))
|
||||
licence = BSD;
|
||||
else if (!strcmp(optarg, "UNL"))
|
||||
licence = UNL;
|
||||
else {
|
||||
puts("BSD\nGPL\nMIT\nUNL");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
editor = true;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'f':
|
||||
force = true;
|
||||
break;
|
||||
case 'S':
|
||||
shell = true;
|
||||
break;
|
||||
default:
|
||||
lose = 1;
|
||||
}
|
||||
if (lose) {
|
||||
emit_try_help();
|
||||
}
|
||||
while ((optc = getopt_long(argc, argv, "a:l:EqfS", longopts, NULL)) != -1)
|
||||
switch (optc) {
|
||||
case 'a':
|
||||
if (optarg) {
|
||||
if (author)
|
||||
free(author);
|
||||
author = str_dup(optarg);
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
if (!strcmp(optarg, "list")) {
|
||||
puts("BSD\nGPL\nMIT\nUNL");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
if (!strcmp(optarg, "GPL"))
|
||||
licence = GPL;
|
||||
else if (!strcmp(optarg, "MIT"))
|
||||
licence = MIT;
|
||||
else if (!strcmp(optarg, "BSD"))
|
||||
licence = BSD;
|
||||
else if (!strcmp(optarg, "UNL"))
|
||||
licence = UNL;
|
||||
else {
|
||||
puts("BSD\nGPL\nMIT\nUNL");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
editor = true;
|
||||
break;
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'f':
|
||||
force = true;
|
||||
break;
|
||||
case 'S':
|
||||
shell = true;
|
||||
break;
|
||||
default:
|
||||
lose = 1;
|
||||
}
|
||||
if (lose) {
|
||||
emit_try_help();
|
||||
}
|
||||
|
||||
if (optind >= argc) {
|
||||
fatalf("no input name");
|
||||
}
|
||||
if (optind >= argc) {
|
||||
fatalf("no input name");
|
||||
}
|
||||
|
||||
if (optind + 1 < argc) {
|
||||
errorf("extra operand: %s", argv[optind + 1]);
|
||||
emit_try_help();
|
||||
}
|
||||
if (optind + 1 < argc) {
|
||||
errorf("extra operand: %s", argv[optind + 1]);
|
||||
emit_try_help();
|
||||
}
|
||||
|
||||
package = str_dup(argv[optind]);
|
||||
package = str_dup(argv[optind]);
|
||||
|
||||
if (shell) {
|
||||
fs_write(package, "\
|
||||
if (shell) {
|
||||
fs_write(package, "\
|
||||
#!/bin/sh\n\
|
||||
\n\
|
||||
# Usage: $0 [options]...\n\
|
||||
@@ -253,45 +248,45 @@ while [ $# -gt 0 ]; do\n\
|
||||
shift\n\
|
||||
done\n\
|
||||
",
|
||||
year, author);
|
||||
struct stat st;
|
||||
year, author);
|
||||
struct stat st;
|
||||
|
||||
if (stat(package, &st) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (stat(package, &st) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
|
||||
mode_t mode = st.st_mode | S_IXUSR;
|
||||
mode_t mode = st.st_mode | S_IXUSR;
|
||||
|
||||
if (chmod(package, mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
return exit_status;
|
||||
}
|
||||
if (chmod(package, mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
// size_t len = strlen(package);
|
||||
// char *pdir = xmalloc(len + 2);
|
||||
// memcpy(pdir, package, len);
|
||||
// pdir[len] = '/';
|
||||
// pdir[len + 1] = '\0';
|
||||
char *pdir;
|
||||
asprintf(&pdir, "%s/", package);
|
||||
// size_t len = strlen(package);
|
||||
// char *pdir = xmalloc(len + 2);
|
||||
// memcpy(pdir, package, len);
|
||||
// pdir[len] = '/';
|
||||
// pdir[len + 1] = '\0';
|
||||
char *pdir;
|
||||
asprintf(&pdir, "%s/", package);
|
||||
|
||||
fs_new(pdir);
|
||||
if (chdir(pdir))
|
||||
fatalfa(errno);
|
||||
fs_new(pdir);
|
||||
if (chdir(pdir))
|
||||
fatalfa(errno);
|
||||
|
||||
fs_write("doc/version.texi", "\
|
||||
fs_write("doc/version.texi", "\
|
||||
@set UPDATED %s\
|
||||
@set UPDATED-MONTH %s\
|
||||
@set EDITION 1\
|
||||
@set VERSION alpha\
|
||||
",
|
||||
"1 January 1970", "January 2025");
|
||||
"1 January 1970", "January 2025");
|
||||
|
||||
char *texi_buffer;
|
||||
// snprintf(path_buffer, sizeof(path_buffer), "doc/%s.texi", package);
|
||||
asprintf(&texi_buffer, "doc/%s.texi", package);
|
||||
fs_write(texi_buffer, "\
|
||||
char *texi_buffer;
|
||||
// snprintf(path_buffer, sizeof(path_buffer), "doc/%s.texi", package);
|
||||
asprintf(&texi_buffer, "doc/%s.texi", package);
|
||||
fs_write(texi_buffer, "\
|
||||
\\input texinfo @c -*-texinfo-*-\n\
|
||||
@c %**start of header\n\
|
||||
@setfilename foo.info\n\
|
||||
@@ -460,15 +455,15 @@ a @file{ChangeLog} entry.\n\
|
||||
\n\
|
||||
@bye\
|
||||
",
|
||||
author, author, author, author, author, author, author, author,
|
||||
author, author, author, author, author, author);
|
||||
free(texi_buffer);
|
||||
author, author, author, author, author, author, author, author,
|
||||
author, author, author, author, author, author);
|
||||
free(texi_buffer);
|
||||
|
||||
// TODO(vx-clutch): Why dosn't this write the source?
|
||||
// snprintf(path_buffer, sizeof(path_buffer), "src/%s.c", package);
|
||||
char *src_path;
|
||||
asprintf(&src_path, "src/%s.c", package);
|
||||
fs_write(src_path, "\
|
||||
// TODO(vx-clutch): Why dosn't this write the source?
|
||||
// snprintf(path_buffer, sizeof(path_buffer), "src/%s.c", package);
|
||||
char *src_path;
|
||||
asprintf(&src_path, "src/%s.c", package);
|
||||
fs_write(src_path, "\
|
||||
/* Copyright (C) %s\n\
|
||||
*\n\
|
||||
* This file is part of %s\n\
|
||||
@@ -529,10 +524,10 @@ void print_version()\n\
|
||||
exit(exit_status);\n\
|
||||
}\
|
||||
",
|
||||
author, package, package, package, author);
|
||||
free(src_path);
|
||||
author, package, package, package, author);
|
||||
free(src_path);
|
||||
|
||||
fs_write("tools/Cleanup", "\
|
||||
fs_write("tools/Cleanup", "\
|
||||
#!/bin/sh\n\
|
||||
# Usage: ./Cleanup\n\
|
||||
\n\
|
||||
@@ -554,7 +549,7 @@ run make distclean\n\
|
||||
\n\
|
||||
echo \"done.\"\
|
||||
");
|
||||
fs_write("tools/format", "\
|
||||
fs_write("tools/format", "\
|
||||
#!/bin/sh\n\
|
||||
\n\
|
||||
# Usage ./format\n\
|
||||
@@ -563,7 +558,7 @@ find . -name \"*.c\" -exec clang-format -i --verbose {} \\;\n\
|
||||
find . -name \"*.h\" -exec clang-format -i --verbose {} \\;\
|
||||
");
|
||||
|
||||
fs_write(".clang-format", "\
|
||||
fs_write(".clang-format", "\
|
||||
---\n\
|
||||
AccessModifierOffset: -4\n\
|
||||
AlignAfterOpenBracket: Align\n\
|
||||
@@ -674,7 +669,7 @@ UseTab: Always\n\
|
||||
...\
|
||||
");
|
||||
|
||||
fs_write(".clangd", "\
|
||||
fs_write(".clangd", "\
|
||||
CompileFlags:\n\
|
||||
Add: [-x, c, -std=c23, -Ilib, -I.]\n\
|
||||
\n\
|
||||
@@ -684,7 +679,7 @@ Diagnostics:\n\
|
||||
Remove: []\
|
||||
");
|
||||
|
||||
fs_write("README", "\
|
||||
fs_write("README", "\
|
||||
This is the README for the GCK %s distribution.\n\
|
||||
%s does a thing.\n\
|
||||
\n\
|
||||
@@ -715,9 +710,9 @@ implementation, etc., would still be very much appreciated.\n\
|
||||
\n\
|
||||
GCK %s is free software. See the file COPYING for copying conditions.\n\
|
||||
\n",
|
||||
package, package, year, package);
|
||||
package, package, year, package);
|
||||
|
||||
fs_write("INSTALL", "\
|
||||
fs_write("INSTALL", "\
|
||||
Installation Instructions\n\
|
||||
*************************\n\
|
||||
\n\
|
||||
@@ -773,9 +768,9 @@ Documentation and other data files still use the regular prefix.\n\
|
||||
`configure` also accepts some other options. Run `configure --help` for more\n\
|
||||
details\n\
|
||||
",
|
||||
year);
|
||||
year);
|
||||
|
||||
fs_write("AUTHORS", "\
|
||||
fs_write("AUTHORS", "\
|
||||
Authors of %s %s.\n\
|
||||
\n\
|
||||
Copyright (C) %d %s.\n\
|
||||
@@ -788,9 +783,9 @@ Also see the THANKS files.\n\
|
||||
\n\
|
||||
%s\n\
|
||||
",
|
||||
author, package, year, package, author);
|
||||
author, package, year, package, author);
|
||||
|
||||
fs_write("THANKS", "\
|
||||
fs_write("THANKS", "\
|
||||
Additional contributors to %s %s.\n\
|
||||
\n\
|
||||
Copyright (C) %d %s.\n\
|
||||
@@ -805,9 +800,9 @@ Thanks to:\n\
|
||||
\n\
|
||||
See also the AUTHORS file.\n\
|
||||
",
|
||||
author, package, year, author);
|
||||
author, package, year, author);
|
||||
|
||||
fs_write("config.h", "\
|
||||
fs_write("config.h", "\
|
||||
#ifndef CONFIG_H\n\
|
||||
#define CONFIG_H\n\
|
||||
\n\
|
||||
@@ -819,9 +814,9 @@ See also the AUTHORS file.\n\
|
||||
\n\
|
||||
#endif\
|
||||
",
|
||||
package, author, year);
|
||||
package, author, year);
|
||||
|
||||
fs_write("configure", "\
|
||||
fs_write("configure", "\
|
||||
#!/bin/sh\n\
|
||||
\n\
|
||||
usage() {\n\
|
||||
@@ -914,7 +909,7 @@ printf \"CC=%%s\n\" \"$CC\"\n\
|
||||
printf \"done\n\"\
|
||||
");
|
||||
|
||||
fs_write("Makefile", "\
|
||||
fs_write("Makefile", "\
|
||||
PACKAGE := %s\n\
|
||||
\n\
|
||||
SRCS := $(wildcard src/*.c) $(wildcard lib/*.c)\n\
|
||||
@@ -970,9 +965,9 @@ release: clean all\n\
|
||||
\n\
|
||||
.PHONY: all clean distclean install uninstall build release\
|
||||
",
|
||||
package);
|
||||
package);
|
||||
|
||||
fs_write("TODO", "\
|
||||
fs_write("TODO", "\
|
||||
%s %s- TODO\n\
|
||||
\n\
|
||||
Todo:\n\
|
||||
@@ -981,77 +976,75 @@ Todo:\n\
|
||||
\n\
|
||||
end of file TODO\
|
||||
",
|
||||
author, package, package);
|
||||
author, package, package);
|
||||
|
||||
switch (licence) {
|
||||
case BSD:
|
||||
fs_write("COPYING", fBSD, year, author);
|
||||
break;
|
||||
case MIT:
|
||||
fs_write("COPYING", fMIT, year, author);
|
||||
break;
|
||||
case GPL:
|
||||
fs_write("COPYING", fGPL);
|
||||
break;
|
||||
case UNL:
|
||||
fs_write("COPYING", fUNL);
|
||||
break;
|
||||
default:
|
||||
fatalf("illegal state");
|
||||
}
|
||||
switch (licence) {
|
||||
case BSD:
|
||||
fs_write("COPYING", fBSD, year, author);
|
||||
break;
|
||||
case MIT:
|
||||
fs_write("COPYING", fMIT, year, author);
|
||||
break;
|
||||
case GPL:
|
||||
fs_write("COPYING", fGPL);
|
||||
break;
|
||||
case UNL:
|
||||
fs_write("COPYING", fUNL);
|
||||
break;
|
||||
default:
|
||||
fatalf("illegal state");
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
struct stat st;
|
||||
|
||||
if (stat("configure", &st) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (stat("configure", &st) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
|
||||
mode_t mode = st.st_mode | S_IXUSR;
|
||||
mode_t mode = st.st_mode | S_IXUSR;
|
||||
|
||||
if (chmod("configure", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (chmod("tools/format", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (chmod("tools/Cleanup", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (chmod("configure", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (chmod("tools/format", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
if (chmod("tools/Cleanup", mode) != 0) {
|
||||
fatalfa(errno);
|
||||
}
|
||||
|
||||
return exit_status;
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
printf("Usage: %s [OPTION]... [project-name]...\n", PROGRAM);
|
||||
fputs("\
|
||||
static void print_help() {
|
||||
printf("Usage: %s [OPTION]... [project-name]...\n", PROGRAM);
|
||||
fputs("\
|
||||
Generates an opinionated C project.\n",
|
||||
stdout);
|
||||
puts("");
|
||||
fputs("\
|
||||
stdout);
|
||||
puts("");
|
||||
fputs("\
|
||||
--help display this help and exit\n\
|
||||
--version display version information and exit\n",
|
||||
stdout);
|
||||
puts("");
|
||||
fputs("\
|
||||
stdout);
|
||||
puts("");
|
||||
fputs("\
|
||||
-E Open $EDITOR after project creation\n\
|
||||
-q, --quiet Only print required messages\n\
|
||||
-f, --force Overwrite existing files\n\
|
||||
--author=NAME Set the program author (default git username|system username)\n\
|
||||
--licence=LICENCE Set the program licence (default BSD)\n",
|
||||
stdout);
|
||||
exit(exit_status);
|
||||
stdout);
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
static void print_version()
|
||||
{
|
||||
printf("%s %s %d\n", prog_name, VERSION, COMMIT);
|
||||
static void print_version() {
|
||||
printf("%s %s %d\n", prog_name, VERSION, COMMIT);
|
||||
|
||||
printf("Copyright (C) %d GCK.\n", YEAR);
|
||||
printf("Copyright (C) %d GCK.\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);
|
||||
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);
|
||||
}
|
||||
|
||||
/* end of file yait.c */
|
||||
|
||||
@@ -1,5 +1,75 @@
|
||||
#!/bin/sh
|
||||
# Usage: ./Cleanup
|
||||
# gck.Cleanup - Cleanup the distribution
|
||||
#
|
||||
# FEATURES:
|
||||
# - Run makefile cleans
|
||||
# - Run formats
|
||||
# - Cleanup artifacts
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./Cleanup
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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:
|
||||
|
||||
--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.'$1'." >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
fatal() {
|
||||
echo "fatal: $*" >&2
|
||||
@@ -18,3 +88,5 @@ run rm -f compile_commands.json
|
||||
run make distclean
|
||||
|
||||
echo "done."
|
||||
|
||||
# End: Cleanup
|
||||
|
||||
71
tools/format
71
tools/format
@@ -1,6 +1,75 @@
|
||||
#!/bin/sh
|
||||
# gck.format - Format C source code
|
||||
#
|
||||
# FEATURES:
|
||||
# - Uses clang-format to force C code
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./format
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# Usage ./format
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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:
|
||||
|
||||
--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.'$1'." >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
find . -name "*.c" -exec clang-format -i --verbose {} \;
|
||||
find . -name "*.h" -exec clang-format -i --verbose {} \;
|
||||
|
||||
# End: format
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p build
|
||||
bear --output build/compile_commands.json -- make
|
||||
@@ -1,3 +1,77 @@
|
||||
#!/bin/sh
|
||||
# gck.update-gcklib - Update gcklib submodule
|
||||
#
|
||||
# FEATURES:
|
||||
# - Updates gcklib
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./update-gcklib
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
git submodule update --remote --rebase
|
||||
me=$0
|
||||
scriptversion="1.0.0"
|
||||
|
||||
version="make $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
|
||||
|
||||
# End: update-gcklib
|
||||
|
||||
66
yait.1
66
yait.1
@@ -1,66 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.2.
|
||||
.TH YAIT "1" "September 2025" "yait beta 156" "User Commands"
|
||||
.SH NAME
|
||||
yait \- manual page for yait beta 156
|
||||
.SH SYNOPSIS
|
||||
.B yait
|
||||
[\fI\,OPTION\/\fR]... [\fI\,project-name\/\fR]
|
||||
.SH DESCRIPTION
|
||||
Generates an optionated C project.
|
||||
.TP
|
||||
\fB\-\-help\fR
|
||||
display this help and exit
|
||||
.TP
|
||||
\fB\-\-version\fR
|
||||
display version information and eixt
|
||||
.TP
|
||||
\fB\-\-git\fR
|
||||
Initialize git repository (default)
|
||||
.TP
|
||||
\fB\-\-no\-git\fR
|
||||
Do not initialize git repository
|
||||
.TP
|
||||
\fB\-\-lib\fR
|
||||
Make this a library
|
||||
.TP
|
||||
\fB\-l\fR <licence>
|
||||
Set licence. This list can be found by passing 'list'
|
||||
.TP
|
||||
\fB\-E\fR
|
||||
Open $EDITOR after project creation
|
||||
.TP
|
||||
\fB\-\-autotools\fR
|
||||
Use the autotools build system
|
||||
.TP
|
||||
\fB\-\-cmake\fR
|
||||
Use the cmake build system
|
||||
.TP
|
||||
\fB\-\-make\fR
|
||||
Use the GNU make build system (default)
|
||||
.TP
|
||||
\fB\-\-bare\fR
|
||||
Minimal C project structure
|
||||
.TP
|
||||
\fB\-\-flat\fR
|
||||
All files in project root.
|
||||
.TP
|
||||
\fB\-\-extras=\fR<arg1>,<arg2>
|
||||
Extra build options, Pass list to list out options.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2025 GCK.
|
||||
License BSD\-3\-Clause: BSD\-3\-Clause <https://opensource.org/license/bsd\-3\-clause>
|
||||
.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