use yet even more bin/jval-wrapper.sh instead of direct grep of JSON files

We use the `bin/jval-wrapper.sh` tool to obtain information from JSON
files instead of attempting using a "GROSS HACK" that involved using
`grep(1)` (and friends) as those "GROSS HACK"s assumed that the layout of
the JSON was canonical.  The `bin/jval-wrapper.sh` tool is able to deal
with various layouts of JSON including non-canonical layouts.  Moreover,
by using the `bin/jval-wrapper.sh` tool we greatly reduce the places in
bin tools that contain "GROSS HACK"s.

Adjusted `bin/gen-status.sh` to use `bin/jval-wrapper.sh`.

Changed `bin/gen-status.sh` VERSION from "1.5.8 2024-08-05"
to "1.6 2024-08-17".

Performed `make gen_status` to test the above under macOS.

Adjusted `bin/gen-years.sh` to use `bin/jval-wrapper.sh`.

Changed `bin/gen-years.sh` VERSION from "1.3.7 2024-08-05"
to "1.4 2024-08-17".

Performed `make gen_years` to test the above under macOS.

Adjusted `bin/output-index-author.sh` to use `bin/jval-wrapper.sh`.

Changed `bin/output-index-author.sh` VERSION from "1.7.3 2024-08-05"
to "1.8 2024-08-17".

Performed `make entry_index` to test the above under macOS.

Added `make quick_year_index` to generate year level index.html files
when year level `YYYY/README.md` is newer.

The `make quick_www` calls `quick_year_index` instead of `make gen_year_index`.

The `bin` directory is now sat as `BIN_PATH=$TOPDIR/bin`, where
`$TOPDIR` is determined by top of the git repo (as determined by
the command: `git rev-parse --is-inside-work-tree`) and potentially
modified by `-d topdir`.  After `cd $TOPDIR`, we set `BIN_DIR=bin`.

All tools from this repo are now assumed to under "$BIN_DIR".  Removed
command like options such as `-T md2html.sh`, and `-p tool` that used
to be able to change the location of a `bin` tool.

Changed `bin/gen-authors.sh` VERSION from "1.11 2024-08-13"
to "1.12 2024-08-18".

Changed `bin/gen-location.sh` VERSION from "1.5 2024-08-17"
to "1.6 2024-08-18".

Changed `bin/readme2index.sh` VERSION from "1.2.7 2024-08-05"
to "1.3 2024-08-17".

Modified `bin/all-run.sh` to use the `bin` directory mechanism.
Modified `bin/all-years.sh` to use the `bin` directory mechanism.
Modified `bin/gen-other-html.sh` to use the `bin` directory mechanism.
Modified `bin/gen-year-index.sh` to use the `bin` directory mechanism.
Modified `bin/md2html.sh` to use the `bin` directory mechanism.
Modified `bin/quick-readme2index.sh` to use the `bin` directory mechanism.
Modified `bin/readme2index.sh` to use the `bin` directory mechanism.

Changed `bin/all-run.sh` VERSION from "1.3.6 2024-08-05"
to "1.4 2024-08-17".

Changed `bin/all-years.sh` VERSION from "1.0.5 2024-08-05"
to "1.1 2024-08-17".

Changed `bin/gen-other-html.sh` VERSION from "1.3 2024-08-11"
to "1.4 2024-08-17".

Changed `bin/gen-year-index.sh` VERSION from "1.1.2 2024-08-05"
to "1.2 2024-08-17".

Changed `bin/quick-readme2index.sh` VERSION from "1.1.7 2024-08-05"
to "1.2 2024-08-17".

Changed `bin/md2html.sh` VERSION from "1.5.5 2024-08-05"
to "1.6 2024-08-17".

Added some whitespace in the form of empty lines to tools.

Made checks for tools under `bin` directory more consistent.

When using `-Q` (quick mode) and the prerequisite files are newer,
we force the target to be touched so that a later run will not
have to build the target HTML file.

Performed `make quick_www` to test the above under macOS.

Performed `make www` to test the above under macOS.
This commit is contained in:
Landon Curt Noll committed 2024-08-18 02:10:25 -07:00
1 parent f159369a0a
commit 0e5864b8b0
39 files changed
+1694 -795

No files matched your search

+59 -25
View File
@@ -53,6 +53,7 @@
#
# Share and enjoy! :-)
# firewall - run only with a bash that is version 5.1.8 or later
#
# The "/usr/bin/env bash" command must result in using a bash that
@@ -96,6 +97,7 @@ if [[ -z ${BASH_VERSINFO[0]} ||
exit 4
fi
# setup bash file matching
#
# We must declare arrays with -ag or -Ag, and we need loops to "export" modified variables.
@@ -108,6 +110,7 @@ shopt -u nocaseglob # disable strict case matching
shopt -u extglob # enable extended globbing patterns
shopt -s globstar # enable ** to match all files and zero or more directories and subdirectories
# set variables referenced in the usage message
#
export VERSION="1.4.4 2024-08-05"
@@ -131,12 +134,12 @@ export REPO_TOP_URL="https://github.com/ioccc-src/temp-test-ioccc"
# GitHub puts individual files under the "blob/master" sub-directory.
export REPO_URL="$REPO_TOP_URL/blob/master"
export SITE_URL="https://ioccc-src.github.io/temp-test-ioccc"
export PANDOC_WRAPPER="bin/pandoc-wrapper.sh"
# set usage message
#
export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-n] [-N]
[-p tool] [-U URL] [-w site_url] [-e string ..] [-E exitcode]
[-U URL] [-w site_url] [-e string ..] [-E exitcode]
YYYY [more_options]
-h print help message and exit
@@ -150,8 +153,6 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-n] [-N]
-n go thru the actions, but do not update any files (def: do the action)
-N do not process file, just parse arguments and ignore the file (def: process the file)
-p tool run 'pandoc wrapper tool' (not pandoc path) during HTML phase number 21 (def: use $PANDOC_WRAPPER)
-U url URL of HTML file being formed (def: $URL)
-w site_url Base URL of the website (def: $SITE_URL)
@@ -174,16 +175,11 @@ Exit codes:
$NAME version: $VERSION"
# output_award
#
# Write the award name to standard output (stdout)
#
# XXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - XXX
# XXX - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - XXX
# XXX - until we have the jnamval command, we must FAKE PARSE the .entry.json file - XXX
# XXX - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - GROSS HACK - XXX
# XXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - XXX
#
# usage:
# output_award YYYY/dir/.entry.json
#
@@ -194,7 +190,6 @@ $NAME version: $VERSION"
function output_award
{
local ENTRY_JSON_PATH; # the .entry.json path
local AWARD_STRING; # winning entry award string
# parse args
#
@@ -218,15 +213,11 @@ function output_award
# obtain the award string
#
AWARD_STRING=$(grep -F '"award" : "' "$ENTRY_JSON_PATH" | sed -e 's/^.*"award" : "//' -e 's/",//')
if [[ -z $AWARD_STRING ]]; then
echo "$0: ERROR: in output_award: no award found in .entry.json file: $ENTRY_JSON_PATH" 1>&2
return 5
fi
echo "$AWARD_STRING"
"$JVAL_WRAPPER" -w -b "$ENTRY_JSON_PATH" '$..award'
return 0
}
# output_ordinal
#
# Write the numerical ordinal form of a non-negative integer to standard output (stdout)
@@ -288,14 +279,16 @@ function output_ordinal
return 0
}
# setup
#
export NOOP=
export DO_NOT_PROCESS=
# parse command line
#
while getopts :hv:Vd:D:nNp:U:w:e:E: flag; do
while getopts :hv:Vd:D:nNU:w:e:E: flag; do
case "$flag" in
h) echo "$USAGE" 1>&2
exit 2
@@ -322,8 +315,6 @@ while getopts :hv:Vd:D:nNp:U:w:e:E: flag; do
;;
N) DO_NOT_PROCESS="-N"
;;
p) PANDOC_WRAPPER="$OPTARG"
;;
U) URL="$OPTARG"
;;
w) SITE_URL="$OPTARG"
@@ -349,7 +340,7 @@ while getopts :hv:Vd:D:nNp:U:w:e:E: flag; do
;;
esac
done
#
# parse the command line arguments
#
if [[ $V_FLAG -ge 1 ]]; then
@@ -372,6 +363,7 @@ if [[ -z $YYYY ]]; then
exit 3
fi
# verify that we have a topdir directory
#
REPO_NAME=$(basename "$REPO_TOP_URL")
@@ -392,6 +384,7 @@ if [[ ! -d $TOPDIR ]]; then
exit 6
fi
# cd to topdir
#
if [[ ! -e $TOPDIR ]]; then
@@ -415,21 +408,51 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2
fi
# verify we have the pandoc wrapper
# verify that we have a bin subdirectory
#
export BIN_PATH="$TOPDIR/bin"
if [[ ! -d $BIN_PATH ]]; then
echo "$0: ERROR: bin is not a directory under topdir: $BIN_PATH" 1>&2
exit 6
fi
export BIN_DIR="bin"
# verify that the bin/pandoc-wrapper.sh tool is executable
#
export PANDOC_WRAPPER="$BIN_DIR/pandoc-wrapper.sh"
if [[ ! -e $PANDOC_WRAPPER ]]; then
echo "$0: ERROR: pandoc wrapper tool does not exist: $PANDOC_WRAPPER" 1>&2
echo "$0: ERROR: bin/md2html.sh does not exist: $PANDOC_WRAPPER" 1>&2
exit 5
fi
if [[ ! -f $PANDOC_WRAPPER ]]; then
echo "$0: ERROR: pandoc wrapper tool is not a file: $PANDOC_WRAPPER" 1>&2
echo "$0: ERROR: bin/md2html.sh is not a regular file: $PANDOC_WRAPPER" 1>&2
exit 5
fi
if [[ ! -x $PANDOC_WRAPPER ]]; then
echo "$0: ERROR: pandoc wrapper tool is not an executable file: $PANDOC_WRAPPER" 1>&2
echo "$0: ERROR: bin/md2html.sh is not an executable file: $PANDOC_WRAPPER" 1>&2
exit 5
fi
# verify that the bin/jval-wrapper.sh tool is executable
#
JVAL_WRAPPER="$BIN_DIR/jval-wrapper.sh"
if [[ ! -e $JVAL_WRAPPER ]]; then
echo "$0: ERROR: bin/jval-wrapper.sh does not exist: $JVAL_WRAPPER" 1>&2
exit 5
fi
if [[ ! -f $JVAL_WRAPPER ]]; then
echo "$0: ERROR: bin/jval-wrapper.sh is not a regular file: $JVAL_WRAPPER" 1>&2
exit 5
fi
if [[ ! -x $JVAL_WRAPPER ]]; then
echo "$0: ERROR: bin/jval-wrapper.sh is not an executable file: $JVAL_WRAPPER" 1>&2
exit 5
fi
# verify that YYYY is an entry directory
#
if [[ ! -d $YYYY ]]; then
@@ -441,6 +464,7 @@ if [[ ! -r $YYYY ]]; then
exit 6
fi
# verify we have a non-empty readable .top file
#
export TOP_FILE=".top"
@@ -461,6 +485,7 @@ if [[ ! -s $TOP_FILE ]]; then
exit 6
fi
# verify that YYYY has a non-empty readable .year file
#
export YEAR_FILE="$YYYY/.year"
@@ -481,6 +506,7 @@ if [[ ! -s $YEAR_FILE ]]; then
exit 6
fi
# determine The N-th IOCCC string
#
LINE_NUM=$(sed -n "/$YYYY/=" "$TOP_FILE" | head -1)
@@ -496,6 +522,7 @@ if [[ -z $ORDINAL ]]; then
exit 11
fi
# parameter debugging
#
if [[ $V_FLAG -ge 3 ]]; then
@@ -519,6 +546,7 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: ORDINAL=$ORDINAL" 1>&2
fi
# If -N, time to exit
#
if [[ -n $DO_NOT_PROCESS ]]; then
@@ -528,6 +556,7 @@ if [[ -n $DO_NOT_PROCESS ]]; then
exit 0
fi
# create a temporary markdown for pandoc to process
#
export TMP_FILE=".tmp.$NAME.FILE.$$.tmp"
@@ -550,6 +579,7 @@ elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary markdown file is not used: $TMP_FILE" 1>&2
fi
# output leading markdown for this IOCCC year
#
{
@@ -568,6 +598,7 @@ else
fi
fi
# process each entry under YYYY
#
export YYYY_DIR
@@ -658,6 +689,7 @@ else
fi
fi
# write trailing markdown for this IOCCC year
#
{
@@ -674,6 +706,7 @@ else
fi
fi
# convert temporary markdown file into HTML
#
if [[ -z $NOOP ]]; then
@@ -694,6 +727,7 @@ elif [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: -n disabled execution of: $PANDOC_WRAPPER $TMP_FILE -" 1>&2
fi
# All Done!!! All Done!!! -- Jessica Noll, Age 2
#
if [[ -z $NOOP ]]; then