Fix whitespace issues in td

This commit is contained in:
Jordan Bancino 2022-12-14 01:00:52 +00:00
parent b63eeffb0f
commit 5255c3f773
2 changed files with 126 additions and 124 deletions

View file

@ -45,6 +45,8 @@ Added support for environment variable substitution in all site
files. This makes it easier to release
.Nm
versions.
.It
Fix whitespace issues in various shell scripts.
.El
.Sh v0.1.0
.Pp

View file

@ -35,9 +35,9 @@
CFLAGS="${CFLAGS} ${DEFINES} ${INCLUDES}"
if [ "$DEBUG" = "1" ]; then
CFLAGS="$CFLAGS -O0 -g"
LDFLAGS="-lm -pthread -v"
PROG="$PROG-debug"
CFLAGS="$CFLAGS -O0 -g"
LDFLAGS="-lm -pthread -v"
PROG="$PROG-debug"
fi
# Check the modificiation time of a file. This is used to do
@ -53,8 +53,8 @@ mod_time() {
stat -f %m "$1"
;;
*)
# Platform unknown, force rebuilding the whole
# project every time.
# Platform unknown, force rebuilding the whole
# project every time.
echo "0"
;;
esac
@ -84,72 +84,72 @@ setsubst() {
# Build the source code, and generate the 'build/telodendria'
# binary.
recipe_build() {
mkdir -p build
mkdir -p build
do_rebuild=0
objs=""
for src in $(find src -name '*.c'); do
obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/')
objs="$objs $obj"
do_rebuild=0
objs=""
for src in $(find src -name '*.c'); do
obj=$(echo "$src" | sed -e 's/^src/build/' -e 's/\.c$/\.o/')
objs="$objs $obj"
if [ $(mod_time "$src") -ge $(mod_time "$obj") ]; then
echo "CC $(basename $obj)"
obj_dir=$(dirname "$obj")
mkdir -p "$obj_dir"
if ! $CC $CFLAGS -c -o "$obj" "$src"; then
exit 1
fi
do_rebuild=1
fi
done
if [ $(mod_time "$src") -ge $(mod_time "$obj") ]; then
echo "CC $(basename $obj)"
obj_dir=$(dirname "$obj")
mkdir -p "$obj_dir"
if ! $CC $CFLAGS -c -o "$obj" "$src"; then
exit 1
fi
do_rebuild=1
fi
done
if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then
echo "LD $PROG"
$CC $LDFLAGS -o "build/$PROG" $objs
else
echo "Up to date."
fi
if [ $do_rebuild -eq 1 ] || [ ! -f "build/$PROG" ]; then
echo "LD $PROG"
$CC $LDFLAGS -o "build/$PROG" $objs
else
echo "Up to date."
fi
}
recipe_run() {
if [ -f "build/$PROG" ]; then
"build/$PROG" -f contrib/development.conf
else
echo "build/$PROG does not exist; build it first."
fi
if [ -f "build/$PROG" ]; then
"build/$PROG" -f contrib/development.conf
else
echo "build/$PROG does not exist; build it first."
fi
}
# Remove all build files, which can be regenerated by re-running the
# build recipe.
recipe_clean() {
rm -r build
rm -r build
}
# Format the source code by updating the copyright headers and
# then running indent(1) on each source code file.
recipe_format() {
find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do
# Update the headers
srcHeader=$(grep -n -m 1 '^ \*/' "$src" | cut -d ':' -f 1)
head "-n$srcHeader" "$src" |
diff -u -p - LICENSE.txt |
patch "$src" | grep -v "^Hmm"
find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do
# Update the headers
srcHeader=$(grep -n -m 1 '^ \*/' "$src" | cut -d ':' -f 1)
head "-n$srcHeader" "$src" |
diff -u -p - LICENSE.txt |
patch "$src" | grep -v "^Hmm"
# Format the source code
if indent "$src"; then
rm $(basename "$src").BAK
fi
done
# Format the source code
if indent "$src"; then
rm $(basename "$src").BAK
fi
done
}
# Deploy the Telodendria website by copying the required files to
# a web root defined by TELODENDRIA_PUB.
recipe_site() {
if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified."
echo "Set TELODENDRIA_PUB."
exit 1
fi
if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified."
echo "Set TELODENDRIA_PUB."
exit 1
fi
DATE=$(date)
@ -165,53 +165,53 @@ recipe_site() {
done
cd - > /dev/null
find man/ -name '*.[1-9]' | while IFS= read -r man; do
dir=$(dirname "$man")
html=$(basename "$man")
find man/ -name '*.[1-9]' | while IFS= read -r man; do
dir=$(dirname "$man")
html=$(basename "$man")
mkdir -p "$TELODENDRIA_PUB/$dir/"
mandoc -Thtml \
mkdir -p "$TELODENDRIA_PUB/$dir/"
mandoc -Thtml \
-O style=/style.css,man=man/man%S/%N.%S.html "$man" \
> "$TELODENDRIA_PUB/$dir/$html.html"
echo "$TELODENDRIA_PUB/$dir/$html.html"
done
echo "$TELODENDRIA_PUB/$dir/$html.html"
done
}
# Generate a release tarball, checksum and sign it, and push it to
# the web root.
recipe_release() {
if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified."
echo "Set TELODENDRIA_PUB."
exit 1
fi
if [ -z "$TELODENDRIA_PUB" ]; then
echo "No public root directory specified."
echo "Set TELODENDRIA_PUB."
exit 1
fi
# Tag the release at this point in time.
cvs tag "$CVS_TAG"
# Tag the release at this point in time.
cvs tag "$CVS_TAG"
mkdir -p "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
cd "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
mkdir -p "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
cd "$TELODENDRIA_PUB/pub/v$TELODENDRIA_VERSION"
# Generate the release tarball.
cvs export "-r$CVS_TAG" "Telodendria"
mv "Telodendria" "Telodendria-v$TELODENDRIA_VERSION"
tar -czf "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
"Telodendria-v$TELODENDRIA_VERSION"
rm -r "Telodendria-v$TELODENDRIA_VERSION"
# Generate the release tarball.
cvs export "-r$CVS_TAG" "Telodendria"
mv "Telodendria" "Telodendria-v$TELODENDRIA_VERSION"
tar -czf "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
"Telodendria-v$TELODENDRIA_VERSION"
rm -r "Telodendria-v$TELODENDRIA_VERSION"
# Checksum the release tarball.
sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
> "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256"
# Checksum the release tarball.
sha256 "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
> "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sha256"
# Sign the release tarball.
if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then
signify -S -s "$TELODENDRIA_SIGNIFY_SECRET" \
-m "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
-x "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sig"
else
echo "Warning: TELODENDRIA_SIGNIFY_SECRET not net."
echo "The built tarball will not be signed."
fi
# Sign the release tarball.
if [ ! -z "$TELODENDRIA_SIGNIFY_SECRET" ]; then
signify -S -s "$TELODENDRIA_SIGNIFY_SECRET" \
-m "Telodendria-v$TELODENDRIA_VERSION.tar.gz" \
-x "Telodendria-v$TELODENDRIA_VERSION.tar.gz.sig"
else
echo "Warning: TELODENDRIA_SIGNIFY_SECRET not net."
echo "The built tarball will not be signed."
fi
}
# Generate a formatted patch file. The Telodendria project isn't
@ -219,63 +219,63 @@ recipe_release() {
# best. Makes them easy to read.
recipe_patch() {
# If the user has not set their MXID, try to deduce one from
# their system.
if [ -z "$MXID" ]; then
MXID="@${USER}:$(hostname)"
fi
# If the user has not set their MXID, try to deduce one from
# their system.
if [ -z "$MXID" ]; then
MXID="@${USER}:$(hostname)"
fi
# If the user has not set their DISPLAY_NAME, try to deduce it
# from their system.
if [ -z "$DISPLAY_NAME" ]; then
DISPLAY_NAME=$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1)
fi
# If the user has not set their DISPLAY_NAME, try to deduce it
# from their system.
if [ -z "$DISPLAY_NAME" ]; then
DISPLAY_NAME=$(getent passwd "$USER" | cut -d ':' -f 5 | cut -d ',' -f 1)
fi
# If the user has not set their EDITOR, use a safe default.
# (vi should be available on any POSIX system)
if [ -z "$EDITOR" ]; then
EDITOR=vi
fi
# If the user has not set their EDITOR, use a safe default.
# (vi should be available on any POSIX system)
if [ -z "$EDITOR" ]; then
EDITOR=vi
fi
NORMALIZED_MXID=$(echo "$MXID" | sed -e 's/@//g' -e 's/:/-/g')
PATCH_FILE="${NORMALIZED_MXID}_$(date +%s).patch"
NORMALIZED_MXID=$(echo "$MXID" | sed -e 's/@//g' -e 's/:/-/g')
PATCH_FILE="${NORMALIZED_MXID}_$(date +%s).patch"
# Generate the actual patch file
# Here we write some nice headers, and then do a cvs diff.
(
printf 'From: "%s" <%s>\n' "$DISPLAY_NAME" "$MXID"
echo "Date: $(date)"
echo "Subject: "
echo
echo "[ ] I have read the Telodendria Project developer certificate"
echo " of origin, and certify that I have permission to submit"
echo " this patch under the conditions specified in it."
echo
cvs -q diff -uNp $PATCHSET | grep -v '^\? '
) > "$PATCH_FILE"
# Generate the actual patch file
# Here we write some nice headers, and then do a cvs diff.
(
printf 'From: "%s" <%s>\n' "$DISPLAY_NAME" "$MXID"
echo "Date: $(date)"
echo "Subject: "
echo
echo "[ ] I have read the Telodendria Project developer certificate"
echo " of origin, and certify that I have permission to submit"
echo " this patch under the conditions specified in it."
echo
cvs -q diff -uNp $PATCHSET | grep -v '^\? '
) > "$PATCH_FILE"
"$EDITOR" "$PATCH_FILE"
echo "$PATCH_FILE"
"$EDITOR" "$PATCH_FILE"
echo "$PATCH_FILE"
}
recipe_diff() {
tmp_patch="/tmp/telodendria-$(date +%s).patch"
cvs -q diff -uNp $PATCHSET > "$tmp_patch"
if [ -z "$PAGER" ]; then
PAGER="less -F"
fi
tmp_patch="/tmp/telodendria-$(date +%s).patch"
cvs -q diff -uNp $PATCHSET > "$tmp_patch"
if [ -z "$PAGER" ]; then
PAGER="less -F"
fi
$PAGER "$tmp_patch"
rm "$tmp_patch"
$PAGER "$tmp_patch"
rm "$tmp_patch"
}
# Execute the user-specified recipes.
for recipe in $@; do
recipe_$recipe
recipe_$recipe
done
# If no recipe was provided, run a build.
if [ -z "$1" ]; then
recipe_build
recipe_build
fi