]> granicus.if.org Git - fortune-mod/commitdiff
Refactoring / code cleanup.
authorShlomi Fish <shlomif@shlomifish.org>
Fri, 25 Feb 2022 07:12:11 +0000 (09:12 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Fri, 25 Feb 2022 07:12:11 +0000 (09:12 +0200)
See:

* https://en.wikipedia.org/wiki/Code_refactoring

* https://www.refactoring.com/

* https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/

Some small optimisations may have slipped in as well.

fortune-mod/datfiles/data/rules-of-acquisition-gen.sh

index 710800ed09b7f6ca349a46eefb100f6823783130..37543a953ce6718cde7cceeb5b41e7d0beece329 100644 (file)
@@ -8,25 +8,29 @@
 # -------------------------------------------------------------------------
 
 # Configuration
-CSV_DELIMITER="|"
-TITLE_TEMPLATE="Ferengi Rule of Acquisition %s:"
-RULE_TEMPLATE="%s"
-SOURCE_TEMPLATE="-- %s"
-FOOTER_TEMPLATE="%%"
-LINE_MAXLEN=78
+csv_delimiter="|"
+title_template="Ferengi Rule of Acquisition %s:"
+rule_template="%s"
+source_template="-- %s"
+footer_template="%%"
+line_maxlen=78
 
 # Check command line
-if [ $# -ne 2 ]; then
+if [ $# -ne 2 ]
+then
        echo "Usage: ${0##*/} INFILE OUTFILE"
        exit 2
 fi
 infile="$1"
-outfile="$2"
+shift
+outfile="$1"
+shift
 
 # Convert CSV to DAT + wrap long lines + remove trailing whitespace
-while IFS="${CSV_DELIMITER}" read -r number rule source; do
-       printf -- "${TITLE_TEMPLATE}\n" "${number}"
-       printf -- "${RULE_TEMPLATE}\n" "${rule}"
-       printf -- "${SOURCE_TEMPLATE}\n" "${source}"
-       printf -- "${FOOTER_TEMPLATE}\n"
-done < "${infile}" | fold -sw ${LINE_MAXLEN} | sed -e 's/[[:space:]]*$//' > "${outfile}"
+while IFS="${csv_delimiter}" read -r number rule source
+do
+       printf -- "${title_template}\n" "${number}"
+       printf -- "${rule_template}\n" "${rule}"
+       printf -- "${source_template}\n" "${source}"
+       printf -- "${footer_template}\n"
+done < "${infile}" | fold -sw "${line_maxlen}" | sed -e 's/[[:space:]]*$//' > "${outfile}"