From b6a47803b28e68031548b0066b4df7ad4998c1f7 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 5 May 2024 08:38:51 -0700 Subject: [PATCH 1/3] Improve bin/gen-top-html.sh It is now possible to specify select files to generate like the comment at the top suggested (but was not actually allowed). This is useful rarely but there is a case for it and that has been updated and it runs a fair bit quicker now. It is an error if no files specified are in the allowed set (the variable TOP_MD_SET). If at least one file specified is in TOP_MD_SET it will process that or those files but it will skip any that are not. This is to prevent trying to process other markdown files like README.md files without the proper script. --- Makefile | 2 +- bin/gen-top-html.sh | 248 +++++++++++++++++++++++++++++++------------- 2 files changed, 177 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 37754f32a..68520fd45 100644 --- a/Makefile +++ b/Makefile @@ -406,7 +406,7 @@ gen_top_html: ${GEN_TOP_HTML} # Just kidding .. So Long, and Thanks for All the Fish :-) thanks: ${GEN_TOP_HTML} thanks-for-help.md @echo "Thanks for all the help ..." - @${GEN_TOP_HTML} + @${GEN_TOP_HTML} thanks-for-help @echo "... and thanks for all the fish :-)" # build entry HTML files from markdown other than README.md to index.html diff --git a/bin/gen-top-html.sh b/bin/gen-top-html.sh index c4432f1a4..f8cb18f88 100755 --- a/bin/gen-top-html.sh +++ b/bin/gen-top-html.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# gen-top-html.sh - generate select top level HTML files from markdown files +# gen-top-html.sh - generate all or select top level HTML files from markdown files # # We also generate the bin/index.html file from the bin/README.md file. # We also generate the inc/index.html file from the inc/README.md file. @@ -8,6 +8,12 @@ # # Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved. # +# Cody Boone Ferguson made an improvement where one can specify the select top +# html files to generate to save time. Works just like the script without args +# but if any args are specified and the markdown file exists it will just +# generate that or those html files. This is to save time for some Makefile +# rules that only need update one file. +# # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright, this permission notice and text @@ -130,6 +136,7 @@ TOP_MD_SET+=("next/guidelines") TOP_MD_SET+=("next/rules") TOP_MD_SET+=("nojs-menu") TOP_MD_SET+=("thanks-for-help") +declare -ag TOP_MD_SELECT_SET # export NOOP= export DO_NOT_PROCESS= @@ -283,7 +290,22 @@ shift $(( OPTIND - 1 )); if [[ $V_FLAG -ge 5 ]]; then echo "$0: debug[5]: file argument count: $#" 1>&2 fi -# + +# allow specifying specific files to generate +FILE_COUNT="$#" +while [[ $# -ne 0 ]]; do + for (( index=0; index < ${#TOP_MD_SET[@]}; index++ )); do + if [[ "${TOP_MD_SET[$index]}" = "$1" ]]; then + TOP_MD_SELECT_SET+=("$1") + fi + done + shift 1 +done +if [[ "$FILE_COUNT" != 0 && ${#TOP_MD_SELECT_SET[@]} = 0 ]]; then + echo "$0: ERROR: no select files specified are in allowed set" 1>&2 + exit 3 +fi + if [[ $# -ne 0 ]]; then echo "$0: ERROR: expected 0 args, found: $#" 1>&2 exit 3 @@ -414,6 +436,11 @@ if [[ $V_FLAG -ge 3 ]]; then echo "$0: debug[3]: PANDOC_WRAPPER=$PANDOC_WRAPPER" 1>&2 echo "$0: debug[3]: REPO_URL=$REPO_URL" 1>&2 echo "$0: debug[3]: SITE_URL=$SITE_URL" 1>&2 + if (( ${#TOP_MD_SELECT_SET[@]} )); then + for index in "${!TOP_MD_SELECT_SET[@]}"; do + echo "$0: debug[3]: TOP_MD_SELECT_SET[$index]=${TOP_MD_SELECT_SET[$index]}" 1>&2 + done + fi for index in "${!TOP_MD_SET[@]}"; do echo "$0: debug[3]: TOP_MD_SET[$index]=${TOP_MD_SET[$index]}" 1>&2 done @@ -442,80 +469,157 @@ fi # process the entire markdown set # -for name in "${TOP_MD_SET[@]}"; do +if (( ${#TOP_MD_SELECT_SET[@]} )); then + for name in "${TOP_MD_SELECT_SET[@]}"; do - # verify that the markdown file exists at the topdir - # - export MD_FILE="$name.md" - if [[ ! -e $MD_FILE ]]; then - echo "$0: Warning: markdown file does not exist: $MD_FILE" 1>&2 - EXIT_CODE=8 # exit 8 - echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 - continue - fi - if [[ ! -f $MD_FILE ]]; then - echo "$0: Warning: markdown file is not a regular file: $MD_FILE" 1>&2 - EXIT_CODE=8 # exit 8 - echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 - continue - fi - if [[ ! -r $MD_FILE ]]; then - echo "$0: Warning: markdown file is not a readable file: $MD_FILE" 1>&2 - EXIT_CODE=8 # exit 8 - echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 - continue - fi - if [[ ! -s $MD_FILE ]]; then - echo "$0: Warning: markdown file is not a non-empty readable file: $MD_FILE" 1>&2 - EXIT_CODE=8 # exit 8 - echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 - continue - fi - export HTML_FILE="$name.html" - # bin/README is a special case - if [[ $name == bin/README ]]; then - HTML_FILE="bin/index.html" - fi - # inc/README is a special case - if [[ $name == inc/README ]]; then - HTML_FILE="inc/index.html" - fi - # next/README is a special case - if [[ $name == next/README ]]; then - HTML_FILE="next/index.html" - fi - # archive/historic/README is a special case - if [[ $name == archive/historic/README ]]; then - HTML_FILE="archive/historic/index.html" - fi - - # use the md2html.sh tool to form the HTML file, unless -n - # - if [[ -z $NOOP ]]; then - if [[ $V_FLAG -ge 1 ]]; then - echo "$0: debug[1]: about to run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ - "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 - fi - "$MD2HTML_SH" -U "$SITE_URL/$HTML_FILE" "${TOOL_OPTION[@]}" \ - -m "$MD_FILE" -- "$MD_FILE" "$HTML_FILE" - status="$?" - if [[ $status -ne 0 ]]; then - echo "$0: Warning: md2html.sh: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ - "-m $MD_FILE -- $MD_FILE $HTML_FILE" \ - "failed, error: $status" 1>&2 - EXIT_CODE="1" # exit 1 + # verify that the markdown file exists at the topdir + # + export MD_FILE="$name.md" + if [[ ! -e $MD_FILE ]]; then + echo "$0: Warning: markdown file does not exist: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 - elif [[ $V_FLAG -ge 3 ]]; then - echo "$0: debug[3]: now up to date: $HTML_FILE" 1>&2 + continue + fi + if [[ ! -f $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a regular file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + if [[ ! -r $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a readable file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + if [[ ! -s $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a non-empty readable file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + export HTML_FILE="$name.html" + # bin/README is a special case + if [[ $name == bin/README ]]; then + HTML_FILE="bin/index.html" + fi + # inc/README is a special case + if [[ $name == inc/README ]]; then + HTML_FILE="inc/index.html" + fi + # next/README is a special case + if [[ $name == next/README ]]; then + HTML_FILE="next/index.html" + fi + # archive/historic/README is a special case + if [[ $name == archive/historic/README ]]; then + HTML_FILE="archive/historic/index.html" fi - # report disabled by -n - # - elif [[ $V_FLAG -ge 5 ]]; then - echo "$0: debug[5]: because of -n, did not run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ - "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 - fi -done + # use the md2html.sh tool to form the HTML file, unless -n + # + if [[ -z $NOOP ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: about to run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 + fi + "$MD2HTML_SH" -U "$SITE_URL/$HTML_FILE" "${TOOL_OPTION[@]}" \ + -m "$MD_FILE" -- "$MD_FILE" "$HTML_FILE" + status="$?" + if [[ $status -ne 0 ]]; then + echo "$0: Warning: md2html.sh: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" \ + "failed, error: $status" 1>&2 + EXIT_CODE="1" # exit 1 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: now up to date: $HTML_FILE" 1>&2 + fi + + # report disabled by -n + # + elif [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: because of -n, did not run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 + fi + done +else + for name in "${TOP_MD_SET[@]}"; do + + # verify that the markdown file exists at the topdir + # + export MD_FILE="$name.md" + if [[ ! -e $MD_FILE ]]; then + echo "$0: Warning: markdown file does not exist: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + if [[ ! -f $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a regular file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + if [[ ! -r $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a readable file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + if [[ ! -s $MD_FILE ]]; then + echo "$0: Warning: markdown file is not a non-empty readable file: $MD_FILE" 1>&2 + EXIT_CODE=8 # exit 8 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + continue + fi + export HTML_FILE="$name.html" + # bin/README is a special case + if [[ $name == bin/README ]]; then + HTML_FILE="bin/index.html" + fi + # inc/README is a special case + if [[ $name == inc/README ]]; then + HTML_FILE="inc/index.html" + fi + # next/README is a special case + if [[ $name == next/README ]]; then + HTML_FILE="next/index.html" + fi + # archive/historic/README is a special case + if [[ $name == archive/historic/README ]]; then + HTML_FILE="archive/historic/index.html" + fi + + # use the md2html.sh tool to form the HTML file, unless -n + # + if [[ -z $NOOP ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: about to run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 + fi + "$MD2HTML_SH" -U "$SITE_URL/$HTML_FILE" "${TOOL_OPTION[@]}" \ + -m "$MD_FILE" -- "$MD_FILE" "$HTML_FILE" + status="$?" + if [[ $status -ne 0 ]]; then + echo "$0: Warning: md2html.sh: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" \ + "failed, error: $status" 1>&2 + EXIT_CODE="1" # exit 1 + echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2 + elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: now up to date: $HTML_FILE" 1>&2 + fi + + # report disabled by -n + # + elif [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: because of -n, did not run: $MD2HTML_SH -U $SITE_URL/$HTML_FILE ${TOOL_OPTION[*]}" \ + "-m $MD_FILE -- $MD_FILE $HTML_FILE" 1>&2 + fi + done +fi # All Done!!! -- Jessica Noll, Age 2 # From 8a5534978313fb7b6393e4e98d368c3a583dec80 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 5 May 2024 08:44:04 -0700 Subject: [PATCH 2/3] Update version & usage string in gen-top-html.sh This is for the previous commit that allows one to specify select files to rebuild (if in the allowed set). --- bin/gen-top-html.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gen-top-html.sh b/bin/gen-top-html.sh index f8cb18f88..dbc536bc4 100755 --- a/bin/gen-top-html.sh +++ b/bin/gen-top-html.sh @@ -93,7 +93,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an # set variables referenced in the usage message # -export VERSION="1.4.5 2024-04-23" +export VERSION="1.4.6 2024-05-05" NAME=$(basename "$0") export NAME export V_FLAG=0 @@ -150,7 +150,7 @@ declare -ag TOOL_OPTION # usage # export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-D docroot/] [-n] [-N] - [-t tagline] [-T md2html.sh] [-p tool] [-u repo_url] + [-t tagline] [-T md2html.sh] [-p tool] [-u repo_url] [file...] -h print help message and exit -v level set verbosity level (def level: 0) From 2a563087bb6c645d1874066cb230aa380445bd51 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 5 May 2024 09:08:14 -0700 Subject: [PATCH 3/3] Don't build alt automatically in 1985/sicherman This was done at first to try and protect against clang but this was decided against. The thanks file has this updated too but it is not being committed yet as there are many other fixes and more to be done before that can happen. README.md was updated and index.html was rebuilt, however. --- 1985/sicherman/Makefile | 6 ++++-- 1985/sicherman/README.md | 9 ++------- 1985/sicherman/index.html | 8 ++------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/1985/sicherman/Makefile b/1985/sicherman/Makefile index e765bb2a9..cb300a033 100644 --- a/1985/sicherman/Makefile +++ b/1985/sicherman/Makefile @@ -136,14 +136,16 @@ all: data ${TARGET} sandwich supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c ${PROG}.alt.c - ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} || \ - ${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS} + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} # alternative executable # alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + ${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/1985/sicherman/README.md b/1985/sicherman/README.md index cbf54d1f6..b78855022 100644 --- a/1985/sicherman/README.md +++ b/1985/sicherman/README.md @@ -4,9 +4,8 @@ make all ``` -There is another version that will be compiled in case the first fails. This -should happen automatically. See [Alternate code](#alternate-code) below for -more details on it. +There is another version that can be compiled in case the first fails. +See [Alternate code](#alternate-code) below for more details on it. ## To use: @@ -40,15 +39,11 @@ audience. ### Alternate build: -Although this will be built if the original fails to compile you can do it -manually like: ``` make alt ``` -In this case it will be built as `sicherman.alt`. - ### Alternate use: diff --git a/1985/sicherman/index.html b/1985/sicherman/index.html index 55ef82f9f..ae8c5a759 100644 --- a/1985/sicherman/index.html +++ b/1985/sicherman/index.html @@ -397,9 +397,8 @@ Location: US - United States of America

To build:

    make all
-

There is another version that will be compiled in case the first fails. This -should happen automatically. See Alternate code below for -more details on it.

+

There is another version that can be compiled in case the first fails. +See Alternate code below for more details on it.

To use:

    ./sicherman < file
 
@@ -417,10 +416,7 @@ will be built in the case of the Alternate build:
-

Although this will be built if the original fails to compile you can do it -manually like:

    make alt
-

In this case it will be built as sicherman.alt.

Alternate use:

    ./sicherman.alt < file

Alternate try: