6 # Creates LaTeX gamebook from XML source. This should subsequently be
7 # used to create a PDF or PostScript version.
13 if ( ! defined($ENV{'AONPATH'}) && ! defined ($ENV{'AONDATA'}) ) {
14 print STDERR "AONPATH environment variable not set, it should be defined to\n";
15 print STDERR "the root directory of the repository of the AON files are.\n";
20 my $PROGRAM_NAME = "gbtolatex";
25 my $BOOK_PATH = $ENV{'AONPATH'}."/common/pdf/build";
27 my $USE_ILLUSTRATORS = "";
31 # my $XMLPROC = "xalan";
32 # my $XMLPROC = "/usr/local/bin/xmlto";
33 my $XMLPROC = "/usr/bin/xsltproc";
34 # my $JAVA = "/cygdrive/c/WINDOWS/java.exe";
35 my $JAVA = "/usr/bin/java";
37 $EXTRAPARMS=$ENV{'XMLPARMS'} if defined($ENV{'XMLPARMS'});
40 unless( $ARGV[ 0 ] ) { die "Usage:\n\t${PROGRAM_NAME} book-code [LANGUAGE] [OUTPUTFILE]\n"; }
42 # Check that all the binaries are were want them
45 push @BINARIES, ($XMLPROC, $JAVA);
49 die "$PROGRAM_NAME: Cannot find binary '".$_."'. Please install it.\n";
54 print "Reminder:\n\tDid you uncomment the LaTeX special character\n\tdeclarations in the book's XML file?\n";
56 my $bookCode = $ARGV[ 0 ];
57 my $language = $ARGV[ 1 ] || "en"; # Use a language or default to 'en'
60 if ( defined ($ENV{'AONDATA'} ) ) {
61 $DATADIR=$ENV{'AONDATA'} ;
63 $DATADIR= $ENV{'AONPATH'}."/".$language."/xml";
65 if ( ! -d "$DATADIR" ) {
66 print STDERR "Cannot find data directory $DATADIR !\n";
69 # Data dir, where XSL files reside
70 # Note: This has to be set to the XML file location and not the XSL location
71 # because of the .inc and the .mod files
72 # We link the file later on to use it
74 my $XSLDIR = $ENV{'AONPATH'}."/common/xsl";
75 if ( ! -d "$XSLDIR" ) {
76 print STDERR "Cannot find XSL directory: $XSLDIR !\n";
81 # - convert the bookcode's if then else to a hash array
82 # - allow usage of unknown book codes
84 if( $bookCode eq "01fftd" ) {
85 $XML_SOURCE = "01fftd.xml";
86 $BOOK_PATH .= "/lw/01fftd";
87 $TITLE_COLOR = "0.0,0.4,0.2";
88 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
90 elsif( $bookCode eq "01hdlo" ) {
91 $XML_SOURCE = "01hdlo.xml";
92 $BOOK_PATH .= "/lw/01hdlo";
93 $TITLE_COLOR = "0.0,0.4,0.2";
94 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
96 elsif( $bookCode eq "02fotw" ) {
97 $XML_SOURCE = "02fotw.xml";
98 $BOOK_PATH .= "/lw/02fotw";
99 $TITLE_COLOR = "0.0,0.6,0.6";
100 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
102 elsif( $bookCode eq "02fsea" ) {
103 $XML_SOURCE = "02fsea.xml";
104 $BOOK_PATH .= "/lw/02fsea";
105 $TITLE_COLOR = "0.0,0.6,0.6";
106 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
108 elsif( $bookCode eq "03tcok" ) {
109 $XML_SOURCE = "03tcok.xml";
110 $BOOK_PATH .= "/lw/03tcok";
111 $TITLE_COLOR = "0.0,0.6,0.8";
112 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
114 elsif( $bookCode eq "03lcdk" ) {
115 $XML_SOURCE = "03lcdk.xml";
116 $BOOK_PATH .= "/lw/03lcdk";
117 $TITLE_COLOR = "0.0,0.6,0.8";
118 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
120 elsif( $bookCode eq "04tcod" ) {
121 $XML_SOURCE = "04tcod.xml";
122 $BOOK_PATH .= "/lw/04tcod";
123 $TITLE_COLOR = "0.0,0.0,0.6";
124 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
126 elsif( $bookCode eq "04eam" ) {
127 $XML_SOURCE = "04eam.xml";
128 $BOOK_PATH .= "/lw/04eam";
129 $TITLE_COLOR = "0.0,0.0,0.6";
130 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
132 elsif( $bookCode eq "05sots" ) {
133 $XML_SOURCE = "05sots.xml";
134 $BOOK_PATH .= "/lw/05sots";
135 $TITLE_COLOR = "0.8,0.6,0.0";
136 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
138 elsif( $bookCode eq "05eddls" ) {
139 $XML_SOURCE = "05eddls.xml";
140 $BOOK_PATH .= "/lw/05eddls";
141 $TITLE_COLOR = "0.8,0.6,0.0";
142 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
144 elsif( $bookCode eq "06tkot" ) {
145 $XML_SOURCE = "06tkot.xml";
146 $BOOK_PATH .= "/lw/06tkot";
147 $TITLE_COLOR = "0.6,0.6,0.0";
148 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
150 elsif( $bookCode eq "06lpdlc" ) {
151 $XML_SOURCE = "06lpdlc.xml";
152 $BOOK_PATH .= "/lw/06lpdlc";
153 $TITLE_COLOR = "0.6,0.6,0.0";
154 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
156 elsif( $bookCode eq "07cd" ) {
157 $XML_SOURCE = "07cd.xml";
158 $BOOK_PATH .= "/lw/07cd";
159 $TITLE_COLOR = "0.0,0.8,0.4";
160 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
162 elsif( $bookCode eq "07meec" ) {
163 $XML_SOURCE = "07meec.xml";
164 $BOOK_PATH .= "/lw/07meec";
165 $TITLE_COLOR = "0.6,0.6,0.0";
166 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
168 elsif( $bookCode eq "08tjoh" ) {
169 $XML_SOURCE = "08tjoh.xml";
170 $BOOK_PATH .= "/lw/08tjoh";
171 $TITLE_COLOR = "0.4,0.6,0.4";
172 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:";
174 elsif( $bookCode eq "08ljdlh" ) {
175 $XML_SOURCE = "08ljdlh.xml";
176 $BOOK_PATH .= "/lw/08ljdlh";
177 $TITLE_COLOR = "0.4,0.6,0.4";
178 $USE_ILLUSTRATORS = ":Gary Chalk:JC Alvarez & Jonathan Blake:Jonathan Blake:Daniel Strong:";
180 elsif( $bookCode eq "09tcof" ) {
181 $XML_SOURCE = "09tcof.xml";
182 $BOOK_PATH .= "/lw/09tcof";
183 $TITLE_COLOR = "1.0,0.6,0.0";
184 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
186 elsif( $bookCode eq "09ecdm" ) {
187 $XML_SOURCE = "09ecdm.xml";
188 $BOOK_PATH .= "/lw/09ecdm";
189 $TITLE_COLOR = "1.0,0.6,0.0";
190 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:Daniel Strong:";
192 elsif( $bookCode eq "10tdot" ) {
193 $XML_SOURCE = "10tdot.xml";
194 $BOOK_PATH .= "/lw/10tdot";
195 $TITLE_COLOR = "1.0,0.0,0.0";
196 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
198 elsif( $bookCode eq "10lmdt" ) {
199 $XML_SOURCE = "10lmdt.xml";
200 $BOOK_PATH .= "/lw/10lmdt";
201 $TITLE_COLOR = "1.0,0.0,0.0";
202 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:Daniel Strong:";
204 elsif( $bookCode eq "11tpot" ) {
205 $XML_SOURCE = "11tpot.xml";
206 $BOOK_PATH .= "/lw/11tpot";
207 $TITLE_COLOR = "0.5,0.5,0.4";
208 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
210 elsif( $bookCode eq "11pdt" ) {
211 $XML_SOURCE = "11pdt.xml";
212 $BOOK_PATH .= "/lw/11pdt";
213 $TITLE_COLOR = "0.5,0.5,0.4";
214 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:Daniel Strong:";
216 elsif( $bookCode eq "12tmod" ) {
217 $XML_SOURCE = "12tmod.xml";
218 $BOOK_PATH .= "/lw/12tmod";
219 $TITLE_COLOR = "0.6,0.0,0.0";
220 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
222 elsif( $bookCode eq "12lsdlo" ) {
223 $XML_SOURCE = "12lsdlo.xml";
224 $BOOK_PATH .= "/lw/12lsdlo";
225 $TITLE_COLOR = "0.6,0.0,0.0";
226 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:Daniel Strong:";
228 elsif( $bookCode eq "13tplor" ) {
229 $XML_SOURCE = "13tplor.xml";
230 $BOOK_PATH .= "/lw/13tplor";
232 $TITLE_COLOR = "0.6,0.0,0.0";
233 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
235 elsif( $bookCode eq "13lsdlpdr" ) {
236 $XML_SOURCE = "13lsdlpdr.xml";
237 $BOOK_PATH .= "/lw/13lsdlpdr";
239 $TITLE_COLOR = "0.6,0.0,0.0";
240 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
242 elsif( $bookCode eq "14tcok" ) {
243 $XML_SOURCE = "14tcok.xml";
244 $BOOK_PATH .= "/lw/14tcok";
246 $TITLE_COLOR = "0.6,0.0,0.0";
247 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
249 elsif( $bookCode eq "15tdc" ) {
250 $XML_SOURCE = "15tdc.xml";
251 $BOOK_PATH .= "/lw/15tdc";
253 $TITLE_COLOR = "0.6,0.0,0.0";
254 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
256 elsif( $bookCode eq "16tlov" ) {
257 $XML_SOURCE = "16tlov.xml";
258 $BOOK_PATH .= "/lw/16tlov";
260 $TITLE_COLOR = "0.6,0.0,0.0";
261 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
263 elsif( $bookCode eq "17tdoi" ) {
264 $XML_SOURCE = "17tdoi.xml";
265 $BOOK_PATH .= "/lw/17tdoi";
267 $TITLE_COLOR = "0.6,0.0,0.0";
268 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
270 elsif( $bookCode eq "18dotd" ) {
271 $XML_SOURCE = "18dotd.xml";
272 $BOOK_PATH .= "/lw/18dotd";
274 $TITLE_COLOR = "0.6,0.0,0.0";
275 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
277 elsif( $bookCode eq "19wb" ) {
278 $XML_SOURCE = "19wb.xml";
279 $BOOK_PATH .= "/lw/19wb";
281 $TITLE_COLOR = "0.6,0.0,0.0";
282 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
284 elsif( $bookCode eq "20tcon" ) {
285 $XML_SOURCE = "20tcon.xml";
286 $BOOK_PATH .= "/lw/20tcon";
288 $TITLE_COLOR = "0.6,0.0,0.0";
289 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
291 elsif( $bookCode eq "21votm" ) {
292 $XML_SOURCE = "21votm.xml";
293 $BOOK_PATH .= "/lw/21votm";
295 $TITLE_COLOR = "0.6,0.0,0.0";
296 $USE_ILLUSTRATORS = ":Trevor Newton:Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
298 elsif( $bookCode eq "22tbos" ) {
299 $XML_SOURCE = "22tbos.xml";
300 $BOOK_PATH .= "/lw/22tbos";
302 $TITLE_COLOR = "0.6,0.0,0.0";
303 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
305 elsif( $bookCode eq "23mh" ) {
306 $XML_SOURCE = "23mh.xml";
307 $BOOK_PATH .= "/lw/23mh";
309 $TITLE_COLOR = "0.6,0.0,0.0";
310 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
312 elsif( $bookCode eq "24rw" ) {
313 $XML_SOURCE = "24rw.xml";
314 $BOOK_PATH .= "/lw/24rw";
316 $TITLE_COLOR = "0.6,0.0,0.0";
317 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
319 elsif( $bookCode eq "25totw" ) {
320 $XML_SOURCE = "25totw.xml";
321 $BOOK_PATH .= "/lw/25totw";
323 $TITLE_COLOR = "0.6,0.0,0.0";
324 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
326 elsif( $bookCode eq "26tfobm" ) {
327 $XML_SOURCE = "26tfobm.xml";
328 $BOOK_PATH .= "/lw/26tfobm";
330 $TITLE_COLOR = "0.6,0.0,0.0";
331 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
333 elsif( $bookCode eq "27v" ) {
334 $XML_SOURCE = "27v.xml";
335 $BOOK_PATH .= "/lw/27v";
337 $TITLE_COLOR = "0.6,0.0,0.0";
338 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
340 elsif( $bookCode eq "28thos" ) {
341 $XML_SOURCE = "28thos.xml";
342 $BOOK_PATH .= "/lw/28thos";
344 $TITLE_COLOR = "0.6,0.0,0.0";
345 $USE_ILLUSTRATORS = ":Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
347 # TODO - fix title color for Grey Star books
348 elsif( $bookCode eq "01gstw" ) {
349 $XML_SOURCE = "01gstw.xml";
350 $BOOK_PATH .= "/gs/01gstw";
352 $TITLE_COLOR = "0.0,0.4,0.2";
353 $USE_ILLUSTRATORS = ":Paul Bonner:Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
355 elsif( $bookCode eq "02tfc" ) {
356 $XML_SOURCE = "02tfc.xml";
357 $BOOK_PATH .= "/gs/02tfc";
359 $TITLE_COLOR = "0.0,0.4,0.2";
360 $USE_ILLUSTRATORS = ":Paul Bonner:Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
362 elsif( $bookCode eq "03btng" ) {
363 $XML_SOURCE = "03btng.xml";
364 $BOOK_PATH .= "/gs/03btng";
366 $TITLE_COLOR = "0.0,0.4,0.2";
367 $USE_ILLUSTRATORS = ":Paul Bonner:Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
369 elsif( $bookCode eq "04wotw" ) {
370 $XML_SOURCE = "04wotw.xml";
371 $BOOK_PATH .= "/gs/04wotw";
373 $TITLE_COLOR = "0.0,0.4,0.2";
374 $USE_ILLUSTRATORS = ":Paul Bonner:Brian Williams:JC Alvarez & Jonathan Blake:Jonathan Blake:";
376 else{ die "Error:\n\tUknown book code.\n"; }
379 #chdir( "$DATADIR" ) or die( "Cannot open Project Aon data directory \"$DATADIR\": $!" );
382 # Check that the XML file is there
383 if ( ! -r $DATADIR."/".$XML_SOURCE ) {
384 die "Could not find source file $XML_SOURCE in $DATADIR!";
386 if ( ! -e $DATADIR."/latex.xsl" ) {
387 if ( ! -r $XSLDIR."/latex.xsl" ) {
388 die "Could not find LaTeX stylesheet (latex.xsl) in $XSLDIR!";
390 # Link, if it does not exist the XSL file to the DATADIR
391 if ( ! link $XSLDIR."/latex.xsl", $DATADIR."/latex.xsl" ) {
392 die "Could not link the LaTeX stylesheet (latex.xsl) from $XSLDIR to $DATADIR!";
395 if ( ! -e $DATADIR."/latex.xsl" ) {
396 die "Could not find LaTeX stylesheet (latex.xsl) in $DATADIR!";
401 # Create the output directory if it does not exist already
402 print "Checking directory $BOOK_PATH...";
403 if ( ! -d "$BOOK_PATH/" ) {
404 print "...directory does not exist.\n";
405 print "Creating $BOOK_PATH ...";
406 mkdir "$BOOK_PATH" || die "Could not create output directory $BOOK_PATH: $!";
410 my $OUTPUTFILE = $ARGV[ 2 ] || "$BOOK_PATH/$bookCode.tex";
412 if ( -e $OUTPUTFILE ) {
413 print "WARN: Outputfile $OUTPUTFILE already exists, will overwrite\n";
416 # Run the XML preprocessor
417 # TODO: use system() properly here and check return value
418 print "Processing book $bookCode and storing result in $OUTPUTFILE...\n";
421 # For Xmlto, which uses xsltproc:
423 # `$XMLPROC -v -o $BOOK_PATH -x ${XSLDIR}/latex.xsl dvi ${DATADIR}/${XML_SOURCE}`;
424 if ( $XMLPROC =~ /xalan/ ) {
426 $command="$XMLPROC -in ${DATADIR}/${XML_SOURCE} -xsl ${XSLDIR}/latex.xsl -out $OUTPUTFILE -param title-color \"\'$TITLE_COLOR\'\" -param use-illustrators \"\'$USE_ILLUSTRATORS\'\" -param language \"\'$language\'\" $EXTRAPARMS";
428 elsif ( $XMLPROC =~ /xsltproc/ ) {
430 $command="$XMLPROC --output $OUTPUTFILE --param title-color \"\'$TITLE_COLOR\'\" --param use-illustrators \"\'$USE_ILLUSTRATORS\'\" --param language \"\'$language\'\" $EXTRAPARMS ${XSLDIR}/latex.xsl ${DATADIR}/${XML_SOURCE}";
433 die "Error: Unsupported XSLT processor '$XMLPROC'.";
435 #print "Executing $command";
437 # Apache Xalan, Java version:
438 # print qx{$JAVA org.apache.xalan.xslt.Process -IN $XML_PATH/$XML_SOURCE -XSL $XML_PATH/latex.xsl -OUT $OUTPUTFILE -PARAM title-color \"$TITLE_COLOR\" -PARAM use-illustrators \"$USE_ILLUSTRATORS\"};