P4 enroute to P5.bash

This is a bash shell script for executing all of the various P4 to P5 stylesheets in a row. It is intended for use in Mac OS X, Debian GNU/Linux, or simiilar system. #! /bin/bash


 * 1) P4_enroute_to_P5.bash
 * 2) Driver script to automate a large portion of the process to convert
 * 3) a TEI P4 (XML) instance into a TEI P5 instance.
 * 4) This script has been tesetd on only a Mac OS X and a Debian
 * 5) GNU/Linux system. It is not intended to run on any other, but it
 * 6) might.
 * 7) Copyleft 2006 by Syd Bauman and the Text Encoding Initiative
 * 8) Consortium
 * 1) Copyleft 2006 by Syd Bauman and the Text Encoding Initiative
 * 2) Consortium
 * 1) Consortium


 * 1) set -o xtrace

STYLESHEETS=' Id-to-xml-id.xslt DateStructLess.xslt Change2change.xslt Remove-Default-Attributes.xsl Janus.xslt IDREFs2bareNames.xslt DescAttribute2Element.xslt Dot-two.xslt ' TMP=/tmp TEMP=$TMP/`basename $0 .bash`_$$ TMPIN=${TEMP}_in TMPOUT=${TEMP}_out DEBUG=false
 * 1) set up various constants for use later NB: Dot-two.xslt should be LAST!

N=0 time=""
 * 1) initialize variables

function error { echo "-" D=`date " %FT%T"` echo "fatal error at $D: $@." exit 1 }
 * 1) establish an error exit procedure

function outPath { case "${1##*.}" in	xml  ) OUT=`basename $1 .xml`.tei ;;	teip4 ) OUT=`basename $1 .teip4`.teip5 ;; p4   ) OUT=`basename $1 .p4`.p5 ;;	tei   ) OUT=`basename $1 .tei`.teip5 ;; *    ) OUT="${1}.xml" ;;    esac }
 * 1) subroutine to derive an output filename from the input
 * 2) Note: this routine has the side-effect of setting $OUT

function transform { N=$(($N 1)) if [ "$DEBUG" = "true" ] ; then echo "xsltproc $1 $TMPIN > $TMPOUT" else echo "$1 ..." fi   $time xsltproc $1 $TMPIN > $TMPOUT if [ "$DEBUG" = "true" ] ; then echo "leaving output in ${TEMP}_${N}_${1}.out" cp $TMPOUT ${TEMP}_${N}_${1}.out fi   mv $TMPOUT $TMPIN }
 * 1) subroutine to execute one stylesheet
 * 2) presume input is in TMPIN, and return
 * 3) the output there. If debugging, also
 * 4) leave the output in an audit-trail file.

echo "Checking for executable \"xsltproc\":" which xsltproc || error "I could not find an `xsltproc` command to run, so I'm giving up"
 * 1) ensure that we have a working xsltproc

while getopts ":d" opt; do   case $opt in	d ) DEBUG=true ;;	* ) echo "usge: $0 [-d] path/to/input [path/to/output]" echo "(Any names can be used if both input
 * 1) process options
 * 2) Currently, there is only 1 option: -d for debug