From: Jonathan Blake Date: Fri, 19 Jul 2019 02:02:18 +0000 (-0700) Subject: Reorganize XMLize script X-Git-Tag: 29tsoc-20200103~77 X-Git-Url: http://git.projectaon.org/?p=project-aon.git;a=commitdiff_plain;h=6df1169b0e3e8638309244e672fb9eb23fec0433;hp=a54ae3db6578b537bfa38b03c9e1ec6077a5cd08 Reorganize XMLize script --- diff --git a/common/scripts/xmlize.pl b/common/scripts/xmlize.pl index ad69f76..23f2066 100755 --- a/common/scripts/xmlize.pl +++ b/common/scripts/xmlize.pl @@ -1,77 +1,13 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl # # xmlize.pl # ###################################################################### -#use strict; +use strict; +use warnings; -$FILE_EXTENSION = 'txt'; - -#### Subroutines - -sub xmlize { - my( $inline, $infile ) = @_; - - $inline =~ s/[[:space:]]*(\.\.\.|\.\s\.\s\.)[[:space:]]*//g; - $inline =~ tr/\t/ /; - $inline =~ s/\s{2,}/ /g; - $inline =~ s/\s+$//; - $inline =~ s/\&\s//g; - $inline =~ tr/\"\`\222\221/\'/; - $inline =~ s/(Random\sNumber\sTable)/$1<\/a>/gi; - $inline =~ s/(Action\sCharts?)/$1<\/a>/gi; - # \222 and \221 are some form of funky right and - # left quotes not present in ascii (of course) - $inline =~ tr/\227/-/; - # \227 is an em or en dash - - $inline =~ s/^\s*(.*)\s*$/$1/; - - if( $inline =~ /^\*/ ) { - $inline =~ s/^\*\s*/
    \n
  • /; - $inline =~ s/\s*\*\s*/<\/li>\n
  • /g; - $inline .= "
  • \n
"; - } - elsif( $inline =~ /^\d+\)\s/ ) { - $inline =~ s/^\d+\)\s+/
    \n
  1. /; - $inline =~ s/\s*\d+\)\s+/<\/li>\n
  2. /g; - $inline .= "
  3. \n
"; - } - elsif( $inline =~ /^\<\!\-\-\spre\s\-\-\>/ ) { - $inline =~ s/^\<\!\-\-\spre\s\-\-\>//; - warn( "Warning: preformatted text in \"$infile\"\n" ); - } - elsif( $inline =~ /^.+:\s+CLOSE\sCOMBAT\sSKILL/ ) { - $inline =~ s/^(.+):\s+CLOSE\sCOMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ $1<\/enemy>$2<\/enemy-attribute>$3<\/enemy-attribute><\/combat>/g; - } - elsif( $inline =~ /^.+:\s+COMBAT\sSKILL/ ) { - $inline =~ s/^(.+):\s+COMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ $1<\/enemy>$2<\/enemy-attribute>$3<\/enemy-attribute><\/combat>/; - } - elsif( $inline =~ /^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})/i ) { - $inline =~ s/^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})(.*)/ $1$2$3$4<\/link-text>$5<\/choice>/i; - $inline =~ s/\s+<\/choice>/<\/choice>/; - } - elsif( $inline =~ /^\[/ ) { - $inline =~ s/\[(.*)\]/$1/; - $inline = " $inline"; - $inline =~ s/\s+<\/signpost>/<\/signpost>/; - } - elsif( $inline eq "" ) { - } - elsif( $inline =~ /^/ ) { - warn( "Warning: unknown comment \"$1\" in \"$infile\"\n" ); - } - else { - $inline = "

$inline

"; - $inline =~ s/\s+<\/p>/<\/p>/; - } - -# Interferes with selecting a combat paragraph if done earlier - $inline =~ s/(COMBAT\sSKILL|CLOSE\sCOMBAT\sSKILL|ENDURANCE|WILLPOWER|\bCS\b|\bEP\b)([^<])/$1<\/typ>$2/g; - - return $inline; -} +my $FILE_EXTENSION = 'txt'; #### Main Routine @@ -176,3 +112,68 @@ print << "(End of XML footer)"; (End of XML footer) + +#### Subroutines + +sub xmlize { + my( $inline, $infile ) = @_; + + $inline =~ s/[[:space:]]*(\.\.\.|\.\s\.\s\.)[[:space:]]*//g; + $inline =~ tr/\t/ /; + $inline =~ s/\s{2,}/ /g; + $inline =~ s/\s+$//; + $inline =~ s/\&\s//g; + $inline =~ tr/\"\`\222\221/\'/; + $inline =~ s/(Random\sNumber\sTable)/
$1<\/a>/gi; + $inline =~ s/(Action\sCharts?)/$1<\/a>/gi; + # \222 and \221 are some form of funky right and + # left quotes not present in ascii (of course) + $inline =~ tr/\227/-/; + # \227 is an em or en dash + + $inline =~ s/^\s*(.*)\s*$/$1/; + + if( $inline =~ /^\*/ ) { + $inline =~ s/^\*\s*/
    \n
  • /; + $inline =~ s/\s*\*\s*/<\/li>\n
  • /g; + $inline .= "
  • \n
"; + } + elsif( $inline =~ /^\d+\)\s/ ) { + $inline =~ s/^\d+\)\s+/
    \n
  1. /; + $inline =~ s/\s*\d+\)\s+/<\/li>\n
  2. /g; + $inline .= "
  3. \n
"; + } + elsif( $inline =~ /^\<\!\-\-\spre\s\-\-\>/ ) { + $inline =~ s/^\<\!\-\-\spre\s\-\-\>//; + warn( "Warning: preformatted text in \"$infile\"\n" ); + } + elsif( $inline =~ /^.+:\s+CLOSE\sCOMBAT\sSKILL/ ) { + $inline =~ s/^(.+):\s+CLOSE\sCOMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ $1<\/enemy>$2<\/enemy-attribute>$3<\/enemy-attribute><\/combat>/g; + } + elsif( $inline =~ /^.+:\s+COMBAT\sSKILL/ ) { + $inline =~ s/^(.+):\s+COMBAT\sSKILL\s+([0-9]+)\s+ENDURANCE\s+([0-9]+)/ $1<\/enemy>$2<\/enemy-attribute>$3<\/enemy-attribute><\/combat>/; + } + elsif( $inline =~ /^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})/i ) { + $inline =~ s/^(.*)\b(return|turn|go)([a-zA-Z\s]+?to )(\d{1,3})(.*)/ $1$2$3$4<\/link-text>$5<\/choice>/i; + $inline =~ s/\s+<\/choice>/<\/choice>/; + } + elsif( $inline =~ /^\[/ ) { + $inline =~ s/\[(.*)\]/$1/; + $inline = " $inline"; + $inline =~ s/\s+<\/signpost>/<\/signpost>/; + } + elsif( $inline eq "" ) { + } + elsif( $inline =~ /^/ ) { + warn( "Warning: unknown comment \"$1\" in \"$infile\"\n" ); + } + else { + $inline = "

$inline

"; + $inline =~ s/\s+<\/p>/<\/p>/; + } + +# Interferes with selecting a combat paragraph if done earlier + $inline =~ s/(COMBAT\sSKILL|CLOSE\sCOMBAT\sSKILL|ENDURANCE|WILLPOWER|\bCS\b|\bEP\b)([^<])/$1<\/typ>$2/g; + + return $inline; +}