8 # Revision 1.1 2005/04/26 04:48:03 jonathan.blake
11 # Revision 1.2 2002/10/20 05:46:31 jblake
12 # Fixed a couple of bugs in the handling of carriage returns and
13 # added support for Freeway Warrior's CLOSE COMBAT SKILL.
15 # Revision 1.1 2002/10/20 03:18:35 jblake
19 # 21 Jun 2002 - Fixed bug in tagging of character-attributes
20 # 06 May 2002 - Incorporated funcionality of xmlize-all
21 # 20 Oct 2001 - Added more spaces to xmlized lines to make 'em purty
22 # in the final product
23 # 19 May 2001 - Updated to conform to new gamebook DTD
24 # 17 Apr 2001 - Repurposed as XMLizer
25 # 24 Feb 2001 - Commented out some of the filtering in favor of
26 # placing it in a separate script
27 # 22 Feb 2000 - Added filtering for &
28 # Padding ENDURANCE in combat <p> with spaces
29 # 21 Feb 2000 - Added filtering for \t
30 # 05 Feb 2000 - Added Action Chart linking
32 # Fixed the "A Giak" caps problem
34 ######################################################################
41 my( $inline, $infile ) = @_;
43 $inline =~ s/(\.\.\.|\.\s\.\s\.)/\&ellips\;/g;
45 $inline =~ s/\s{2,}/ /g;
47 $inline =~ s/\&\s/\&\; /g;
48 $inline =~ tr/\"\`\222\221/\'/;
49 $inline =~ s/(Random\sNumber\sTable)/<a idref=\"random\">$1<\/a>/gi;
50 $inline =~ s/(Action\sCharts?)/<a idref=\"action\">$1<\/a>/gi;
51 # \222 and \221 are some form of funky right and
52 # left quotes not present in ascii (of course)
53 $inline =~ tr/\227/-/;
54 # \227 is an em or en dash
56 $inline =~ s/^\s*(.*)\s*$/$1/;
58 if( $inline =~ /^\*/ ) {
59 $inline =~ s/^\*\s*/ <ul>\n <li>/;
60 $inline =~ s/\s*\*\s*/<\/li>\n <li>/g;
61 $inline .= "</li>\n </ul>";
63 elsif( $inline =~ /^\d+\)\s/ ) {
64 $inline =~ s/^\d+\)\s+/ <ol>\n <li>/;
65 $inline =~ s/\s*\d+\)\s+/<\/li>\n <li>/g;
66 $inline .= "</li>\n </ol>";
68 elsif( $inline =~ /^\<\!\-\-\spre\s\-\-\>/ ) {
69 $inline =~ s/^\<\!\-\-\spre\s\-\-\>//;
70 warn( "Warning: preformatted text in \"$infile\"\n" );
72 elsif( $inline =~ /^.+:\s+CLOSE\sCOMBAT\sSKILL/ ) {
73 $inline =~ s/^(.+):\s+CLOSE\sCOMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ <combat><enemy>$1<\/enemy><enemy-attribute class=\"closecombatskill\">$2<\/enemy-attribute><enemy-attribute class=\"endurance\">$3<\/enemy-attribute><\/combat>/g;
75 elsif( $inline =~ /^.+:\s+COMBAT\sSKILL/ ) {
76 $inline =~ s/^(.+):\s+COMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ <combat><enemy>$1<\/enemy><enemy-attribute class=\"combatskill\">$2<\/enemy-attribute><enemy-attribute class=\"endurance\">$3<\/enemy-attribute><\/combat>/;
78 elsif( $inline =~ /^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})/i ) {
79 $inline =~ s/^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})(.*)/ <choice idref=\"sect$4\">$1<link-text>$2$3$4<\/link-text>$5<\/choice>/i;
80 $inline =~ s/\s+<\/choice>/<\/choice>/;
82 elsif( $inline =~ /^\[/ ) {
83 $inline =~ s/\[(.*)\]/$1/;
84 $inline = " <signpost>$inline</signpost>";
85 $inline =~ s/\s+<\/signpost>/<\/signpost>/;
87 elsif( $inline eq "" ) {
89 elsif( $inline =~ /^<!--(.*)-->/ ) {
90 warn( "Warning: unknown comment \"$1\" in \"$infile\"\n" );
93 $inline = " <p>$inline</p>";
94 $inline =~ s/\s+<\/p>/<\/p>/;
97 # Interferes with selecting a combat paragraph if done earlier
98 $inline =~ s/(COMBAT\sSKILL|CLOSE\sCOMBAT\sSKILL|ENDURANCE|WILLPOWER|\bCS\b|\bEP\b)([^<])/<typ class="attribute">$1<\/typ>$2/g;
105 my $numberOfSections = shift @ARGV;
107 print << "(End of XML Header)";
108 <?xml version="1.0" encoding="ISO-8859-1"?>
109 <!DOCTYPE gamebook SYSTEM "gamebook.dtd" [
110 <!ENTITY % xhtml.characters SYSTEM "htmlchar.mod">
111 <!ENTITY % latex.characters SYSTEM "ltexchar.mod">
114 <!ENTITY % general.links SYSTEM "genlink.mod">
116 <!ENTITY % xhtml.links SYSTEM "htmllink.mod">
119 <!ENTITY % general.inclusions SYSTEM "geninc.mod">
123 <gamebook xml:lang="en-UK" version="0.10">
133 <title>[Insert Title]</title>
143 <title>Title Page</title>
144 <link class="next" idref="dedicate" />
151 <section class="numbered" id="numbered">
152 <meta><title>Numbered Sections</title></meta>
157 for( my $sectionNumber = 1; $sectionNumber <= $numberOfSections; ++$sectionNumber ) {
159 my $infile = "${sectionNumber}.txt";
161 open( INFILE, "<$infile" ) or die "Input file \"$infile\" is not readable.\n";
164 @oldlines = <INFILE>;
168 my $title = shift @oldlines;
169 my $section = shift @oldlines;
170 my $illustration = shift @oldlines;
172 $illustration =~ s/^Illustration\s+(\d+)\s+/$1/;
173 $illustration =~ s/\r//g;
174 shift @oldlines if( $illustration ne "" );
176 my @newlines = ( "" );
179 # Parsing waits for an empty line to XMLize and store
180 # the preceding lines.
181 push( @oldlines, "" ) if( @oldlines[ $#oldlines ] ne "" );
183 foreach my $oldline (@oldlines) {
184 $oldline =~ s/\r|\n/ /g;
185 $oldline =~ s/^\s*(\S*)\s*$/$1/;
186 $oldline =~ s/\s\s/ /;
187 if( $oldline ne "" ) {
188 $newline .= (" " . $oldline);
191 $newline = &xmlize( $newline, $infile );
192 $newline .= "\n" if( $newline ne "" );
193 push( @newlines, $newline );
198 print "\n\n <section class=\"numbered\" id=\"sect$sectionNumber\">\n <meta><title>$sectionNumber</title></meta>\n\n <data>\n";
200 print " </data>\n </section>";
203 print << "(End of XML footer)";