P4 enroute to P5.bash
Jump to navigation
Jump to search
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
# P4_enroute_to_P5.bash
#
# Driver script to automate a large portion of the process to convert
# a TEI P4 (XML) instance into a TEI P5 instance.
#
# This script has been tesetd on only a Mac OS X and a Debian
# GNU/Linux system. It is not intended to run on any other, but it
# might.
#
# Copyleft 2006 by Syd Bauman and the Text Encoding Initiative
# Consortium
#set -o xtrace
# set up various constants for use later NB: Dot-two.xslt should be LAST!
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
# initialize variables
N=0
time=""
# establish an error exit procedure
function error {
echo "---------"
D=`date " %FT%T"`
echo "fatal error at $D: $@."
exit 1
}
# subroutine to derive an output filename from the input
# Note: this routine has the side-effect of setting $OUT
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
}
# subroutine to execute one stylesheet
# presume input is in TMPIN, and return
# the output there. If debugging, also
# leave the output in an audit-trail file.
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
}
# ensure that we have a working xsltproc
echo "Checking for executable \"xsltproc\":"
which xsltproc || error "I could not find an `xsltproc` command to run, so I'm giving up"
# process options
# Currently, there is only 1 option: -d for debug
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