D.11. latestdate.sh

#!/bin/sh

# This script finds the latest revision date for each book among its SGML source
# files, and then creates an entity file, dates.sgml, for those dates.

# Note to self: when I have time, add 'datahubwin' to 'gendriver' in
# an OR statement, to allow checking the main directory as well as
# subdirectories for datahubwin files.

recentdate () {
DIR=${1}
FILE=${2}

if [ "${1}" = "gendriver" ] || [ "${1}" = "datahubwin" ]; then
    DIR1=${1}
    DIR2=${2}
    FILE=${3}
    ls -t --time-style="+%B %d, %Y" -l ../../i/${DIR1}/${FILE}.sgml \
	../../i/${DIR2}/${FILE}.sgml \
    | cut -c44- | sed -e '2,$d' -e 's/\ \..*//' | sed '/^$/d'
else
    ls -t --time-style="+%B %d, %Y" -l ../../i/${DIR}/${FILE}.sgml \
    | cut -c44- | sed -e '2,$d' -e 's/\ \..*//' | sed '/^$/d'
fi
}

rm ../../i/common/dates.sgml
touch ../../i/common/dates.sgml
echo "<!-- Latest Dates -->" >> ../../i/common/dates.sgml
echo '<!entity api-date "' $(recentdate api '*') '">' >> ../../i/common/dates.sgml
echo '<!entity cs-date "' $(recentdate cserve '*') '">' >> ../../i/common/dates.sgml
echo '<!entity cx-date "' $(recentdate excel '*') '">' >> ../../i/common/dates.sgml
echo '<!entity qse-date "' $(recentdate datahubwin datahubwin/d '*') '">' >> ../../i/common/dates.sgml
echo '<!entity ccw-date "' $(recentdate datahubwin datahubwin/c '*') '">' >> ../../i/common/dates.sgml
echo '<!entity dhw-date "' $(recentdate datahubwin datahubwin/d '*') '">' >> ../../i/common/dates.sgml
echo '<!entity dh-date "' $(recentdate datahub '*') '">' >> ../../i/common/dates.sgml
echo '<!entity gm-date "' $(recentdate gamma '*') '">' >> ../../i/common/dates.sgml
echo '<!entity gl-date "' $(recentdate glossary '*') '">' >> ../../i/common/dates.sgml
echo '<!entity gg-date "' $(recentdate gtkgamma '*') '">' >> ../../i/common/dates.sgml
echo '<!entity gp-date "' $(recentdate phgamma '*') '">' >> ../../i/common/dates.sgml
echo '<!entity gq-date "' $(recentdate sqlgamma '*') '">' >> ../../i/common/dates.sgml
echo '<!entity hi-date "' $(recentdate historian '*') '">' >> ../../i/common/dates.sgml
echo '<!entity p1-date "' $(recentdate papers 'art1') '">' >> ../../i/common/dates.sgml
echo '<!entity p2-date "' $(recentdate papers 'art2') '">' >> ../../i/common/dates.sgml
echo '<!entity p3-date "' $(recentdate papers 'art3') '">' >> ../../i/common/dates.sgml
echo '<!entity p4-date "' $(recentdate papers 'art4') '">' >> ../../i/common/dates.sgml
echo '<!entity p5-date "' $(recentdate papers 'art5') '">' >> ../../i/common/dates.sgml
echo '<!entity p6-date "' $(recentdate papers 'art6') '">' >> ../../i/common/dates.sgml
echo '<!entity p7-date "' $(recentdate papers 'art7') '">' >> ../../i/common/dates.sgml
echo '<!entity p8-date "' $(recentdate papers 'art8') '">' >> ../../i/common/dates.sgml
echo '<!entity p9-date "' $(recentdate papers 'art9') '">' >> ../../i/common/dates.sgml
echo '<!entity sr-date "' $(recentdate srripc '*') '">' >> ../../i/common/dates.sgml
echo '<!entity drcf-date "' $(recentdate gendriver cfdriver '*') '">' >> ../../i/common/dates.sgml
echo '<!entity drdn-date "' $(recentdate gendriver dndriver '*') '">' >> ../../i/common/dates.sgml
echo '<!entity drpb-date "' $(recentdate gendriver pbdriver '*') '">' >> ../../i/common/dates.sgml
echo '<!entity drgn-date "' $(recentdate gendriver gendriver '*') '">' >> ../../i/common/dates.sgml
echo '<!entity drmb-date "' $(recentdate sstdrivers 'mb_man') '">' >> ../../i/common/dates.sgml
echo '<!entity drsd-date "' $(recentdate sstdrivers 'sd_man') '">' >> ../../i/common/dates.sgml
echo '<!entity tst-date "' $(recentdate ../o/testfile2 '*') '">' >> ../../i/common/dates.sgml
echo '<!entity sm-date "' $(recentdate sales '*') '">' >> ../../i/common/dates.sgml
echo '<!entity tl-date "' $(recentdate textlog '*') '">' >> ../../i/common/dates.sgml
echo '<!entity tu-date "' $(recentdate tutorial '*') '">' >> ../../i/common/dates.sgml
echo '<!entity pd-date "' $(recentdate prepdoc '*') '">' >> ../../i/common/dates.sgml
echo '<!entity wp-date "' $(recentdate papers '*') '">' >> ../../i/common/dates.sgml
echo '<!entity ar-date "' $(recentdate articles '*') '">' >> ../../i/common/dates.sgml
echo '<!entity today-date "' $(date +"%B %-d, %Y") '">' >> ../../i/common/dates.sgml