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
|
||||
|
||||
222
configure
vendored
222
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 ; }
|
||||
Options:
|
||||
--release enable release flags
|
||||
--enable-debug enable debugging options
|
||||
--prefix PREFIX set installation prefix
|
||||
|
||||
--help print this help and exit
|
||||
--version output version information
|
||||
|
||||
Environment variables:
|
||||
|
||||
CC C compiler command
|
||||
CFLAGS C compiler flags
|
||||
|
||||
Use these variables to override the choices made by 'configure'."
|
||||
|
||||
release=false
|
||||
debug=false
|
||||
prefix=/usr/local
|
||||
CFLAGS=-pedantic
|
||||
CC=
|
||||
args_old=$@
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--help) echo "$usage"; exit 0 ;;
|
||||
--version) echo "$version"; exit 0 ;;
|
||||
--release) release=true ;;
|
||||
--enable-debug) debug=true ;;
|
||||
--prefix) shift; prefix=${1:?missing prefix argument} ;;
|
||||
--strict) CFLAGS+="-Werror" ;;
|
||||
CC=*) CC=${1#*=} ;;
|
||||
CFLAGS=*) CFLAGS=${1#*=} ;;
|
||||
-*)
|
||||
echo "$0: Unknown option '$1'." >&2
|
||||
echo "$0: Try '--help' for more information." >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "$release" = true ] && [ "$debug" = true ]; then
|
||||
echo "$0: Can't set both '--release' and '--debug'." >&2
|
||||
echo "$0: Try '--help' for more information." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmdexists() { command -v "$1" >/dev/null 2>&1 ; }
|
||||
trycc() { [ -z "$CC" ] && cmdexists "$1" && CC=$1 ; }
|
||||
|
||||
prefix=/usr/local
|
||||
CFLAGS="-std=c23"
|
||||
LDFLAGS=
|
||||
CC=
|
||||
|
||||
if [ -z "$CC" ]; then
|
||||
printf "checking for C compiler... "
|
||||
trycc gcc
|
||||
trycc clang
|
||||
trycc cc
|
||||
trycc icx
|
||||
if [ -z "$CC" ]; then
|
||||
echo "none found"
|
||||
exit 1
|
||||
fi
|
||||
printf "%s\n" "$CC"
|
||||
fi
|
||||
|
||||
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
|
||||
done
|
||||
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"
|
||||
else
|
||||
printf "no; %s\n" "$output"
|
||||
rm -rf "$tmpcdir"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "$tmpcdir"
|
||||
|
||||
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"
|
||||
|
||||
if [ -z "$DEBUG" ]; then
|
||||
case "$CC" in
|
||||
gcc) CFLAGS="$GDEBUGFLAGS";;
|
||||
clang) CFLAGS="$CDEBUGFLAGS";;
|
||||
*) ;;
|
||||
esac
|
||||
else
|
||||
case "$CC" in
|
||||
gcc) ;;
|
||||
clang) ;;
|
||||
*) ;;
|
||||
esac
|
||||
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
|
||||
|
||||
case "$OSTYPE" in
|
||||
cygwin|msys)
|
||||
echo "enabling windows specific flags"
|
||||
CFLAGS="-v $CFLAGS"
|
||||
;;
|
||||
esac
|
||||
echo "creating config.status"
|
||||
cat <<EOF > config.status
|
||||
#!/bin/sh
|
||||
# DO NOT MODIFY. THIS IS A AUTOGENERATED SCRIPT FROM 'configure'
|
||||
#
|
||||
# COMPILATION (Linux - POSIX):
|
||||
# ./config.status
|
||||
#
|
||||
#
|
||||
# LICENSE: BSD-3-Clause
|
||||
#
|
||||
# Copyright (c) 2025 GCK
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
printf "creating config.mak... "
|
||||
printf "config.status: recreating config.mak... "
|
||||
{
|
||||
printf "PREFIX=%s\\n" "$prefix"
|
||||
printf "CFLAGS=%s\\n" "$CFLAGS"
|
||||
printf "CC=%s\\n" "$CC"
|
||||
} > config.status
|
||||
printf "done\n"
|
||||
EOF
|
||||
chmod u+x config.status
|
||||
|
||||
printf "configure: creating config.mak... "
|
||||
{
|
||||
printf "PREFIX=%s\n" "$prefix"
|
||||
printf "CFLAGS=%s\n" "$CFLAGS"
|
||||
printf "LDFLAGS=%s\n" "$LDFLAGS"
|
||||
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
|
||||
|
||||
71
lib/err.c
71
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,8 +51,7 @@
|
||||
#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;
|
||||
#else
|
||||
@@ -84,10 +84,9 @@ static bool err_support_color(void)
|
||||
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, "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;
|
||||
@@ -97,8 +96,7 @@ static bool err_support_color(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void errorf(const char *format, ...)
|
||||
{
|
||||
void errorf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -113,8 +111,7 @@ void errorf(const char *format, ...)
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
void fatalf(const char *format, ...)
|
||||
{
|
||||
void fatalf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -132,8 +129,7 @@ void fatalf(const char *format, ...)
|
||||
fputs("program terminated.\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
void warnf(const char *format, ...)
|
||||
{
|
||||
void warnf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -148,8 +144,7 @@ void warnf(const char *format, ...)
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
void notef(const char *format, ...)
|
||||
{
|
||||
void notef(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -164,8 +159,7 @@ void notef(const char *format, ...)
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
void hintf(const char *format, ...)
|
||||
{
|
||||
void hintf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -186,29 +180,14 @@ void hintf(const char *format, ...)
|
||||
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 */
|
||||
|
||||
21
lib/err.h
21
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
|
||||
|
||||
36
lib/flag.c
36
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,8 +43,7 @@
|
||||
static char *nextchar;
|
||||
|
||||
int getopt_long(int argc, char *const argv[], const char *optstring,
|
||||
const struct option *longopts, int *longindex)
|
||||
{
|
||||
const struct option *longopts, int *longindex) {
|
||||
if (nextchar == NULL || *nextchar == '\0') {
|
||||
if (optind >= argc)
|
||||
return -1;
|
||||
@@ -62,24 +62,20 @@ int getopt_long(int argc, char *const argv[], const char *optstring,
|
||||
strlen(longopts[i].name) == len) {
|
||||
if (longindex)
|
||||
*longindex = i;
|
||||
if (longopts[i].has_arg ==
|
||||
required_argument) {
|
||||
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 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;
|
||||
*longopts[i].flag = longopts[i].val;
|
||||
return 0;
|
||||
}
|
||||
return longopts[i].val;
|
||||
|
||||
21
lib/flag.h
21
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,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 FLAG_H
|
||||
|
||||
44
lib/fs.c
44
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>
|
||||
@@ -61,8 +62,7 @@
|
||||
#define RETURN(code) fatalfa(code)
|
||||
#endif
|
||||
|
||||
char *fs_read(const char *path)
|
||||
{
|
||||
char *fs_read(const char *path) {
|
||||
FILE *fptr = fopen(path, "r");
|
||||
if (!fptr) {
|
||||
#if defined(FS_ERROR_ON)
|
||||
@@ -97,8 +97,7 @@ char *fs_read(const char *path)
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool fs_exists(const char *path)
|
||||
{
|
||||
bool fs_exists(const char *path) {
|
||||
FILE *fptr;
|
||||
bool exists;
|
||||
|
||||
@@ -113,8 +112,7 @@ bool fs_exists(const char *path)
|
||||
return exists;
|
||||
}
|
||||
|
||||
int fs_append(const char *path, const char *format, ...)
|
||||
{
|
||||
int fs_append(const char *path, const char *format, ...) {
|
||||
FILE *fp = fopen(path, "a");
|
||||
if (!fp)
|
||||
RETURN(errno);
|
||||
@@ -135,13 +133,9 @@ int fs_append(const char *path, const char *format, ...)
|
||||
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)
|
||||
{
|
||||
int fs_new(const char *path) {
|
||||
size_t len;
|
||||
int fd;
|
||||
|
||||
@@ -169,8 +163,7 @@ int fs_new(const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fs_write(const char *path, const char *format, ...)
|
||||
{
|
||||
int fs_write(const char *path, const char *format, ...) {
|
||||
FILE *fptr = fopen(path, "w");
|
||||
if (!fptr)
|
||||
RETURN(-1);
|
||||
@@ -191,8 +184,7 @@ int fs_write(const char *path, const char *format, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
FILE *fs_temp()
|
||||
{
|
||||
FILE *fs_temp() {
|
||||
FILE *fptr = tmpfile();
|
||||
|
||||
if (!fptr) {
|
||||
|
||||
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,39 +22,35 @@
|
||||
*
|
||||
* 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()
|
||||
{
|
||||
void emit_try_help() {
|
||||
printf("Try '%s --help' for more information\n", prog_name);
|
||||
}
|
||||
|
||||
void emit_version()
|
||||
{
|
||||
void emit_version() {
|
||||
printf("\
|
||||
%s %s %d\n\
|
||||
Copyright (C) %d GCK.\n\
|
||||
@@ -65,8 +61,7 @@ There is NO WARRNTY, to the extent permitted by law.\n\
|
||||
}
|
||||
|
||||
int parse_standard_options(int argc, char **argv, void (*print_help)(),
|
||||
void (*print_version)())
|
||||
{
|
||||
void (*print_version)()) {
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
if (!strcmp(argv[i], "--help")) {
|
||||
print_help();
|
||||
|
||||
@@ -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
|
||||
|
||||
44
lib/say.c
44
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,43 +22,41 @@
|
||||
*
|
||||
* 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()
|
||||
{
|
||||
void alert() {
|
||||
fputs("\a", stderr);
|
||||
fflush(stderr);
|
||||
return;
|
||||
}
|
||||
|
||||
int vasprintf(char **result, const char *fmt, va_list 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 asprintf(char **buf, const char *fmt, ...) {
|
||||
int status;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
@@ -67,8 +65,7 @@ int asprintf(char **buf, const char *fmt, ...)
|
||||
return status;
|
||||
}
|
||||
|
||||
int say(const char *restrict format, ...)
|
||||
{
|
||||
int say(const char *restrict format, ...) {
|
||||
struct winsize w;
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
|
||||
va_list args;
|
||||
@@ -96,8 +93,7 @@ int say(const char *restrict format, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
_Noreturn void die(const char *msg)
|
||||
{
|
||||
_Noreturn void die(const char *msg) {
|
||||
fputs(msg, stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
42
lib/textc.c
42
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,52 +22,46 @@
|
||||
*
|
||||
* 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 *str_dup(char *s) {
|
||||
char *new = xmalloc(strlen(s) + 1);
|
||||
strcpy(new, s);
|
||||
return new;
|
||||
}
|
||||
|
||||
char *tostrupr(char *s)
|
||||
{
|
||||
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 *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 *textc_pad_left(int count, char *s, char pad) {
|
||||
char *buffer = xmalloc(strlen(s) + 1);
|
||||
|
||||
free(buffer);
|
||||
|
||||
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
|
||||
|
||||
35
lib/xmem.c
35
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,25 +40,19 @@
|
||||
|
||||
#include "xmem.h"
|
||||
|
||||
void *ensure_nonnull(void *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)
|
||||
{
|
||||
void *xrealloc(void *ptr, size_t size) {
|
||||
return ensure_nonnull(realloc(ptr, size));
|
||||
}
|
||||
|
||||
void *xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *xcalloc(size_t nmemb, size_t size) {
|
||||
return ensure_nonnull(calloc(nmemb, size));
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
61
src/yait.c
61
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,53 +33,51 @@
|
||||
*
|
||||
* 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' },
|
||||
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 }
|
||||
};
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
static int exit_status;
|
||||
|
||||
static void print_help();
|
||||
static void print_version();
|
||||
|
||||
static char *get_name()
|
||||
{
|
||||
static char *get_name() {
|
||||
int fds[2];
|
||||
if (pipe(fds) == -1)
|
||||
goto sysuser;
|
||||
@@ -95,8 +93,7 @@ static char *get_name()
|
||||
dup2(fds[1], STDOUT_FILENO);
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
execlp("git", "git", "config", "--get", "user.name",
|
||||
(char *)NULL);
|
||||
execlp("git", "git", "config", "--get", "user.name", (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
@@ -123,17 +120,16 @@ sysuser: {
|
||||
return str_dup("author");
|
||||
}
|
||||
|
||||
static int get_year()
|
||||
{
|
||||
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
|
||||
// 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 main(int argc, char **argv) {
|
||||
int optc;
|
||||
int lose = 0;
|
||||
char *package;
|
||||
@@ -149,8 +145,7 @@ int main(int argc, char **argv)
|
||||
|
||||
parse_standard_options(argc, argv, print_help, print_version);
|
||||
|
||||
while ((optc = getopt_long(argc, argv, "a:l:EqfS", longopts, NULL)) !=
|
||||
-1)
|
||||
while ((optc = getopt_long(argc, argv, "a:l:EqfS", longopts, NULL)) != -1)
|
||||
switch (optc) {
|
||||
case 'a':
|
||||
if (optarg) {
|
||||
@@ -1021,8 +1016,7 @@ end of file TODO\
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
static void print_help() {
|
||||
printf("Usage: %s [OPTION]... [project-name]...\n", PROGRAM);
|
||||
fputs("\
|
||||
Generates an opinionated C project.\n",
|
||||
@@ -1043,8 +1037,7 @@ Generates an opinionated C project.\n",
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
static void print_version()
|
||||
{
|
||||
static void print_version() {
|
||||
printf("%s %s %d\n", prog_name, VERSION, COMMIT);
|
||||
|
||||
printf("Copyright (C) %d GCK.\n", YEAR);
|
||||
|
||||
@@ -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