]> granicus.if.org Git - fortune-mod/commitdiff
Extract a common expression into a variable/const.
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 3 May 2022 05:36:02 +0000 (08:36 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Tue, 3 May 2022 05:36:02 +0000 (08:36 +0300)
This is Refactoring / code cleanup.

See:

* https://refactoring.com/catalog/extractMethod.html

* 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 bf6a5b1ff9b671b04f2fe908f7f599294b188815..7b6e1081b4a433495853a1e6073cd60cb4f9f3d1 100644 (file)
@@ -26,9 +26,10 @@ then
        exit 2
 fi
 
+format="${title_template}\\n${rule_template}\\n${source_template}\\n${footer_template}\\n"
+
 # Convert CSV to DAT + wrap long lines + remove trailing whitespace
 while IFS="${csv_delimiter}" read -r number rule source
 do
-       printf -- "${title_template}\\n${rule_template}\\n${source_template}\\n${footer_template}\\n" \
-        "${number}" "${rule}" "${source}"
+       printf -- "${format}" "${number}" "${rule}" "${source}"
 done < "${infile}" | fold -sw "${line_maxlen}" | sed -e 's/[[:space:]]*$//' > "${outfile}"