5 ######################################################################
9 $FILE_EXTENSION = 'txt';
14 my( $inline, $infile ) = @_;
16 $inline =~ s/[[:space:]]*(\.\.\.|\.\s\.\s\.)[[:space:]]*/<ch.ellips\/>/g;
18 $inline =~ s/\s{2,}/ /g;
20 $inline =~ s/\&\s/<ch.ampersand\/>/g;
21 $inline =~ tr/\"\`\222\221/\'/;
22 $inline =~ s/(Random\sNumber\sTable)/<a idref=\"random\">$1<\/a>/gi;
23 $inline =~ s/(Action\sCharts?)/<a idref=\"action\">$1<\/a>/gi;
24 # \222 and \221 are some form of funky right and
25 # left quotes not present in ascii (of course)
26 $inline =~ tr/\227/-/;
27 # \227 is an em or en dash
29 $inline =~ s/^\s*(.*)\s*$/$1/;
31 if( $inline =~ /^\*/ ) {
32 $inline =~ s/^\*\s*/ <ul>\n <li>/;
33 $inline =~ s/\s*\*\s*/<\/li>\n <li>/g;
34 $inline .= "</li>\n </ul>";
36 elsif( $inline =~ /^\d+\)\s/ ) {
37 $inline =~ s/^\d+\)\s+/ <ol>\n <li>/;
38 $inline =~ s/\s*\d+\)\s+/<\/li>\n <li>/g;
39 $inline .= "</li>\n </ol>";
41 elsif( $inline =~ /^\<\!\-\-\spre\s\-\-\>/ ) {
42 $inline =~ s/^\<\!\-\-\spre\s\-\-\>//;
43 warn( "Warning: preformatted text in \"$infile\"\n" );
45 elsif( $inline =~ /^.+:\s+CLOSE\sCOMBAT\sSKILL/ ) {
46 $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;
48 elsif( $inline =~ /^.+:\s+COMBAT\sSKILL/ ) {
49 $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>/;
51 elsif( $inline =~ /^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})/i ) {
52 $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;
53 $inline =~ s/\s+<\/choice>/<\/choice>/;
55 elsif( $inline =~ /^\[/ ) {
56 $inline =~ s/\[(.*)\]/$1/;
57 $inline = " <signpost>$inline</signpost>";
58 $inline =~ s/\s+<\/signpost>/<\/signpost>/;
60 elsif( $inline eq "" ) {
62 elsif( $inline =~ /^<!--(.*)-->/ ) {
63 warn( "Warning: unknown comment \"$1\" in \"$infile\"\n" );
66 $inline = " <p>$inline</p>";
67 $inline =~ s/\s+<\/p>/<\/p>/;
70 # Interferes with selecting a combat paragraph if done earlier
71 $inline =~ s/(COMBAT\sSKILL|CLOSE\sCOMBAT\sSKILL|ENDURANCE|WILLPOWER|\bCS\b|\bEP\b)([^<])/<typ class="attribute">$1<\/typ>$2/g;
78 die "xmlize.pl maxSectionNumber [minSectionNumber]\n" if $#ARGV < 0;
79 my $minSectionNumber = 1;
80 my $numberOfSections = shift @ARGV;
81 $minSectionNumber = shift @ARGV if $#ARGV > -1;
83 print << "(End of XML Header)";
84 <?xml version="1.0" encoding="ISO-8859-1"?>
85 <!DOCTYPE gamebook SYSTEM "gamebook.dtd" [
86 <!ENTITY % general.links SYSTEM "genlink.mod">
88 <!ENTITY % xhtml.links SYSTEM "htmllink.mod">
91 <!ENTITY % general.inclusions SYSTEM "geninc.mod">
95 <gamebook xml:lang="en-UK" version="0.12">
98 <title>[Insert Title]</title>
108 <title>Title Page</title>
109 <link class="next" idref="dedicate" />
116 <section class="numbered" id="numbered">
117 <meta><title>Numbered Sections</title></meta>
122 for( my $sectionNumber = $minSectionNumber; $sectionNumber <= $numberOfSections; ++$sectionNumber ) {
124 my $infile = "${sectionNumber}.${FILE_EXTENSION}";
126 open( INFILE, "<$infile" ) or die "Input file \"$infile\" is not readable.\n";
129 @oldlines = <INFILE>;
133 my $title = shift @oldlines;
134 my $section = shift @oldlines;
135 my $illustration = shift @oldlines;
137 $illustration =~ s/^Illustration\s+(\d+)\s+/$1/;
138 $illustration =~ s/\r//g;
139 shift @oldlines if( $illustration ne "" );
141 my @newlines = ( "" );
144 # Parsing waits for an empty line to XMLize and store
145 # the preceding lines.
146 push( @oldlines, "" ) if( $oldlines[ $#oldlines ] ne "" );
148 foreach my $oldline (@oldlines) {
149 $oldline =~ s/\r|\n/ /g;
150 $oldline =~ s/^\s*(\S*)\s*$/$1/;
151 $oldline =~ s/\s\s/ /;
152 if( $oldline ne "" ) {
153 $newline .= (" " . $oldline);
156 $newline = &xmlize( $newline, $infile );
157 $newline .= "\n" if( $newline ne "" );
158 push( @newlines, $newline );
163 print "\n\n <section class=\"numbered\" id=\"sect$sectionNumber\">\n <meta><title>$sectionNumber</title></meta>\n\n <data>\n";
165 print " </data>\n </section>";
168 print << "(End of XML footer)";