forked from TEIC/Stylesheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformtei
executable file
·227 lines (214 loc) · 6.48 KB
/
transformtei
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/sh
# convert between TEI and other formats. intended to be use as symlink to other scripts
# whose names will dictate the format and direction of conversion.
# Sebastian Rahtz, July 2011
# copyright: TEI Consortium
# license: GPL
# $Id$
script=`basename $0`
scriptdir=`dirname $0`
APPHOME=`(cd $scriptdir; pwd)`
defaultAPPHOME=`(cd $scriptdir; pwd)`
profiledir=$APPHOME/profiles
defaultprofiledir=$APPHOME/profiles
oxygenlib=/usr/share/oxygen/lib
die()
{
echo "ERROR: $@."
D=`date "+%Y-%m-%d %H:%M:%S"`
echo "This was a fatal error. $D"
exit 1
}
usageMsg()
{
echo "TEI conversion: from $from to $to"
echo ""
echo " Usage: $0 [options] inputfile [outputfile]"
echo
echo " Options, binary switches:"
echo " --verbose # be verbose"
echo " --debug # be verbose, do not delete intermediate files"
echo " --apphome=$APPHOME # where to find app directory"
echo " --profiledir=$profiledir # where to find profile directory"
echo " --profile=$profile # which transformation profile to use"
echo " --lang=$lang # which language to use
echo " --oxygenlib=$oxygenlib # where is oxygenlib"
case $format in
teitorelaxng) ;;
teitornc) ;;
teitodtd) ;;
teitoxsd) ;;
*)
echo " --odd # perform processing of ODD (if appropriate)"
echo " --localsource=DIR # where is local copy of source of TEI Guidelines"
echo " --summaryDoc # only make summary, when doing ODD processing"
;;
esac
if [ $script = "teitoepub" ]
then
echo " --fileperpage # create output files one per page "
echo " --nocompress # disable compression of epub output file"
fi
echo
echo " Options, shown with defaults:"
echo " --saxonjar=$SAXONJAR # location of Saxon jar file"
if [ $script = "teitoepub" ]
then
echo " --mediaoverlay # create media overlays from timeline data "
echo " --coverimage= # name of JPEG file for ebook cover"
echo " --css= # supply name of CSS file "
echo " --publisher= # name of publisher for ebook "
echo " --splitLevel=$splitLevel # splitting level "
echo " --subject= # subject/category for ebook "
echo " --uid= # unique URN for ebook "
echo " --viewportwidth= # viewport width for epub fixed-size pages "
echo " --viewportheight= # viewport height for epub fixed-size pages "
fi
echo
echo "Stylesheet family version: $version"
}
#-------------------------------------------------
fileperpage=
debug=
lang=en
profile=default
odd=false
verbose=false
summaryDoc=""
antflag=-q
TEISOURCE=
# epub only
overlayfile=
splitLevel=
publisher=
coverimage=
cover=
cssFile=
conversion=
subject=
uid=
viewportwidth=
viewportheight=
medioverlay=
nocompress=
# ---
version=`cat $APPHOME/VERSION`
SAXONJAR=/usr/share/saxon/saxon9he.jar
from=`echo $script | sed 's/to.*//'`
to=`echo $script | sed 's/.*to//'`
if [ $to = "tei" ]
then
direction=from
format=$from
outsuffix=.xml
else
direction=to
format=$to
outsuffix=.$to
fi
while test $# -gt 0; do
case $1 in
--coverimage=*) cover=`echo $1 | sed 's/.*=//'`;;
--css=*) cssFile=-DcssFile=`echo $1 | sed 's/.*=//'`;;
--fileperpage) splitLevel="-DsplitLevel=-1"; fileperpage="-DfilePerPage=true";;
--odd) odd=true;;
--lang=*) lang=`echo $1 | sed 's/.*=//'`;;
--localsource=*) TEISOURCE="`echo $1 | sed 's/.*=//'`";;
--mediaoverlay) mediaoverlay="-Dmediaoverlay=true";;
--profile=*) profile=`echo $1 | sed 's/.*=//'`;;
--oxygenlib=*) oxygenlib=`echo $1 | sed 's/.*=//'`;;
--profiledir=*) profiledir=`echo $1 | sed 's/.*=//'`;;
--apphome=*) APPHOME=`echo $1 | sed 's/.*=//'`;;
--publisher=*) publisher=`echo $1 | sed 's/.*=//'`;;
--saxonjar=*) SAXONJAR=`echo $1 | sed 's/.*=//'`;;
--splitLevel=*) splitLevel="-DsplitLevel=`echo $1 | sed 's/.*=//'`";;
--subject=*) subject="`echo $1 | sed 's/.*=//'`";;
--uid=*) uid=`echo $1 | sed 's/.*=//'`;;
--debug) debug="-Ddebug=true"; verbose=true; antflag=-v;;
--verbose) verbose=true;;
--summaryDoc) summaryDoc="-DsummaryDoc=true";;
--viewportwidth=*) viewportwidth="-DviewPortWidth=`echo $1 | sed 's/.*=//'`";;
--viewportheight=*) viewportheight="-DviewPortHeight=`echo $1 | sed 's/.*=//'`";;
--nocompress) nocompress="-DnoCompress=true";;
--help) usageMsg; exit 1;;
*) if test "$1" = "${1#--}" ; then
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
fi
fi
if test "x$TEISOURCE" = "x"
then
localsource=""
else
REALD=`dirname "$TEISOURCE"`
SDIR=`(cd $REALD; pwd)`
REALSOURCE=$SDIR/`basename $TEISOURCE`
echo using $REALSOURCE as default source
localsource=" -DdefaultSource=$REALSOURCE "
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
outfile=`basename "$1" .$from`$outsuffix
outdir=$indir
else
outfile=`basename $2`
O=`dirname $2`
outdir=`(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
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
;;
esac
echo Convert $infile to $outdir/$outfile \($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 $localsource \
-Dodd=$odd \
-Dsaxon.jar=${SAXONJAR} \
-Dverbose=$verbose \
-DinputFile="$indir/$infile" \
-DoutputFile="$outdir/$outfile" \
-Dprofiledir=$profiledir \
-Dprofile=$profile \
-Dpublisher=$publisher \
-Duid=$uid \
-Dlang=$lang \
-Dsubject=$subject \
-Dcoverimage=$cover \
-Doxygenlib=$oxygenlib