Skip to content

Commit

Permalink
Re-work how filenames are handled for #543:
Browse files Browse the repository at this point in the history
I _think_ I have this working right, but more testing is in order.
  • Loading branch information
sydb committed Sep 29, 2023
1 parent 3de5a7d commit d54dc0b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 86 deletions.
1 change: 1 addition & 0 deletions bin/oddtorng
2 changes: 1 addition & 1 deletion bin/teitorelaxng
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -e

echo "$0 has been superceded by teitorng (and oddtorng, which is the same as teitorng --odd)"
echo "$0 has been superceded by teitorng (and oddtorng, which is the same as \"teitorng --odd\")"
exit 13
171 changes: 86 additions & 85 deletions bin/transformtei
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ echo " --oxygenlib=$oxygenlib # where is oxygenlib"
echo " --splitLevel=$splitLevel # splitting level "
case $format in
rng|rnc|dtd|xsd)
if [ $from != odd ]; then echo " --odd # perform processing of ODD (if appropriate)"; fi
echo " --localsource=DIR # where is local copy of source of TEI Guidelines"
echo " --summaryDoc # only make summary, when doing ODD processing"
echo " --schema=NAME # process the schemaSpec called NAME"
;;
if [ $from != odd ]; then echo " --odd # perform processing of ODD (if appropriate)"; fi
echo " --localsource=DIR # where is local copy of source of TEI Guidelines"
echo " --summaryDoc # only make summary, when doing ODD processing"
echo " --schema=NAME # process the schemaSpec called NAME"
;;
esac
case "$script" in
teitoepub*) # could be teitoepub or teitoepub3
echo " --fileperpage # create output files one per page "
echo " --nocompress # disable compression of epub output file"
;;
echo " --fileperpage # create output files one per page "
echo " --nocompress # disable compression of epub output file"
;;
esac

echo
Expand Down Expand Up @@ -105,23 +105,61 @@ SAXONJAR=$APPHOME/lib/saxon10he.jar
TRANGJAR=$APPHOME/lib/trang.jar
from=`echo $script | sed 's/to.*//'`
to=`echo $script | sed 's/.*to//'`
if [ $to = "tei" ]
then
direction=from
format=$from
outsuffix=.xml

if [ $to = tei ]; then
direction=from
format=$from
outsuffix=.xml
else
direction=to
format=$to
outsuffix=.$to
direction=to
format=$to
outsuffix=.$to
fi
if [ $from = odd ] ; then odd=true; fi

case $to in
rnc|rng|dtd|xsd)
if [ $from = odd ]; then odd=true; fi
;;
*) ;;
esac
if [ $# -gt 2 ]; then
echo "Error: only one parameter (input file) or two parameters (input file and output file) allowed: $*"
exit 1
fi

infile=${1}
indir=$(dirname ${1})
infilename=$(basename ${1})
if [ $# -eq 1 ]; then # only 1 argument, output file is input with new extension
# strip off expected suffixes from input filename
infilebase=${infilename}
infilebase=${infilebase%.odd}
infilebase=${infilebase%.tei}
infilebase=${infilebase%.xml}
infilebase=${infilebase%.csv}
infilebase=${infilebase%.dbk}
infilebase=${infilebase%.docx}
infilebase=${infilebase%.html}
infilebase=${infilebase%.xhtml}
infilebase=${infilebase%.htm}
infilebase=${infilebase%.odt}
infilebase=${infilebase%.md}
infilebase=${infilebase%.wp}
infilebase=${infilebase%.xlsx}
# output goes in same dir as input
outdir=${indir}
# output filename is like input but with common prefix replaced with new one
outfilename=${infilebase}$outsuffix
else # 2 arguments (if there were more then 2 we would have already aborted)
outfile=${2}
# output directory is the directory specified
outdir=`dirname "${outfile}"`
# Following line tries to create the output directory if it does not exist yet
outdir=`(mkdir -p ${outdir}; cd ${outdir}; pwd)`
# output filename is as specified
outfilename=`basename ${outfile}`
fi

if [ ${indir}/${infilename} = ${outdir}/${outfilename} ] ; then die "input and output files are the same"; fi

if [ ! -f "${indir}/${infilename}" ] ; then die "Input file $infile does not exist"; fi

if [ ! -f "$SAXONJAR" ] ; then die "Saxon jar file $SAXONJAR does not exist"; fi

while test $# -gt 0; do
case $1 in
Expand All @@ -148,28 +186,20 @@ while test $# -gt 0; do
--summaryDoc) summaryDoc="-DsummaryDoc=true";;
--viewportwidth=*) viewportwidth="-DviewPortWidth=`echo $1 | sed 's/.*=//'`";;
--viewportheight=*) viewportheight="-DviewPortHeight=`echo $1 | sed 's/.*=//'`";;
--nocompress) nocompress="-DnoCompress=true";;
--nocompress) nocompress="-DnoCompress=true";;
--help) usageMsg; exit 1;;
*) if test "$1" = "${1#--}" ; then
break
else
echo "WARNING: Unrecognized option '$1' ignored"
fi ;;
break
else
echo "WARNING: Unrecognized option '$1' ignored"
fi ;;
esac
shift
done

if [ $# -gt 2 ]
then
echo Error: only two parameters \(input file and output file\) allowed: $*
exit 1
fi

if test "$defaultAPPHOME" != "$APPHOME"
then
if test "$profiledir" = "$defaultprofiledir"
then
profiledir=$APPHOME/profiles
if test "$defaultAPPHOME" != "$APPHOME" ; then
if test "$profiledir" = "$defaultprofiledir" ; then
profiledir=$APPHOME/profiles
fi
fi

Expand Down Expand Up @@ -204,66 +234,37 @@ else
die "unable to get localsource from $TEISOURCE"
fi

in=${1:?"no input file supplied; for usage syntax $0 --help"}
infile=`basename "$in"`
D=`dirname "$in"`
indir=`(cd $D; pwd)`
if [ $# -eq 1 ]
then
inputfilename=$1
inputfilename=${inputfilename%.odd}
inputfilename=${inputfilename%.tei}
inputfilename=${inputfilename%.xml}
outfile=`basename "$inputfilename"`$outsuffix
outdir=$indir
else
outfile=`basename $2`
O=`dirname "$2"`
outdir=`(mkdir -p $O; cd $O; pwd)`
fi
if ! test -f "$indir/$infile"
then
die "Input file $infile does not exist"
fi
if ! test -f "$SAXONJAR"
then
die "Saxon jar file $SAXONJAR does not exist"
fi
if ! test -f "$APPHOME/$format/build-$direction.xml"
then
if ! test -f "$APPHOME/$format/build-$direction.xml"; then
die "No support for $from to $to: ant task $APPHOME/$format/build-$direction.xml does not exist"
fi

case $format in
rnc) ;;
xsd) ;;
*) if ! test -f "$profiledir/$profile/$format/$direction.xsl"
then
die "No support for profile $profile: $profiledir/$profile/$format/$direction.xsl does not exist"
fi
;;
then
die "No support for profile $profile: $profiledir/$profile/$format/$direction.xsl does not exist"
fi
;;
esac
if [ $infile = $outfile ]; then die "Generated output filename same as input filename ($outfile)."; fi


echo Convert $infile to $outdir/$outfile \($from to $to\) using profile $profile $debug $fileperpage $splitLevel $viewportwidth $viewportheight
echo ant $antflag -f "$APPHOME/$format/build-$direction.xml" \
-lib "${SAXONJAR}" $debug \
echo Convert $infile to ${outdir}/${outfilename} \($from to $to\) using profile $profile $debug $fileperpage $splitLevel $viewportwidth $viewportheight
ant $antflag -f "$APPHOME/$format/build-$direction.xml" \
-lib "${SAXONJAR}" $debug \
$fileperpage $cssFile $splitLevel $viewportwidth $viewportheight $summaryDoc $mediaoverlay $nocompress \
-Dodd=$odd \
-Dsaxon.jar="${SAXONJAR}" \
-Dtrang.jar="${TRANGJAR}" \
-Dverbose=$verbose \
-DinputFile="$indir/$infile" \
-DoutputFile="$outdir/$outfile" \
-DinputFile="${indir}/${infilename}" \
-DoutputFile="${outdir}/${outfilename}" \
-Dprofiledir="$profiledir" \
-Dprofile="$profile" \
-Dpublisher=$publisher \
-Duid=$uid \
-Dpublisher=$publisher \
-Duid=$uid \
-DselectedSchema=$schema \
-Dlang=$lang \
-Dsubject=$subject \
-Dcoverimage=$cover \
-Doxygenlib=$oxygenlib \
-DdefaultSource=$defaultSource


-Dlang=$lang \
-Dsubject=$subject \
-Dcoverimage=$cover \
-Doxygenlib=$oxygenlib \
-DdefaultSource=$defaultSource

0 comments on commit d54dc0b

Please sign in to comment.