3 # Uses ANSI color escapes to highlight text and for cursor movement
8 my $usage = "Usage:\n gbfixquotes.pl [options] INFILE OUTFILE\n\t-f \tforce attempted fixes in malformed places\n\t-s LINES\tskip lines\n";
13 my $tags = qr{(p)|(choice)};
14 my $quoteMarks = qr{['`\221-\224]};
15 my $notQuoteMarks = qr{[^'`\221-\224]};
16 my $terminalPunctuation = qr{[.?!,]};
17 my $notTerminalPunctuation = qr{[^.?!,]};
19 my $spellNames = qr{(lightning[[:space:]]+hand)|(splinter)|(flameshaft)|(halt[[:space:]]+missile)|(strength)|(penetrate)|(energy[[:space:]]+grasp)|(slow[[:space:]]+fall)|(breathe[[:space:]]+water)|(power[[:space:]]+glyph)|(hold[[:space:]]+enemy)|(teleport)|(see[[:space:]]+illusion)|(mind[[:space:]]+charm)|(net)|(counterspell)|(sense[[:space:]]+evil)|(invisible[[:space:]]+fist)|(levitation)}i;
21 my ($infile, $outfile);
23 my $optsProcessed = 0;
26 while( $#ARGV > -1 && not $optsProcessed ) {
27 my $commandLineItem = shift @ARGV;
28 if( $commandLineItem eq "-f" ) {
31 elsif( $commandLineItem eq "-s" ) {
32 $skipLines = shift @ARGV or die $usage;
35 unshift @ARGV, $commandLineItem;
41 $infile = shift @ARGV;
42 $outfile = shift @ARGV;
48 if( $infile =~ m{(^.*$)} && -f $1 ) {
49 open( INFILE, "<$1" ) or die "Error: unable to read from \"$infile\": $!\n";
52 die "Error: bad input file\n";
55 if( $outfile =~ m{(^.*$)} ) {
56 open( OUTFILE, ">$1" ) or die "Error: unable to write to \"$outfile\": $!\n";
59 die "Error: bad output file\n";
62 while( my $line = <INFILE> ) {
63 if( $skipLines > $lineNumber ) { }
64 elsif( $line =~ m{<($tags)[[:space:]>]} ) {
66 unless( $line =~ m{</$tagName>} ) {
67 printWarning( "Warning ($lineNumber): <$tagName> found without </$tagName>, skipping tests for current line\n", $line );
69 elsif( $line =~ m{${quoteMarks}} ) {
70 $line = "ify( $line );
73 elsif( $forced && $line =~ m{${quoteMarks}} ) {
74 $line = "ify( $line );
76 elsif( $line =~ m{</($tags)>} ) {
77 printWarning( "Warning ($lineNumber): </$1> found without <$1>\n", $line );
79 elsif( $line =~ m{($quoteMarks)}x ) {
80 printWarning( "Warning ($lineNumber): unescaped quotation character \"$1\" found outside tested context\n", $line );
90 ################################################################################
100 {<spell>$1</spell>}xg;
108 {$1<quote>$2</quote>$3}xg;
110 ([[:alpha:]][[:space:]]*)
112 ([[:space:]]*[[:alpha:]])
117 (${notTerminalPunctuation}+?
118 ${terminalPunctuation})
121 {<quote>$1</quote>}xg;
127 {<quote>$1</quote>}xg;
129 print &highlight( $line ) . "\n";
130 print &highlight( $modified );
131 print "\033[7m (a)ccept, (r)eject, (q)uit: [accept]\033[0m >> ";
132 my $response = <STDIN>;
134 if( $response =~ m/^[aA]$/ || $response eq "" ) { $line = $modified; }
135 elsif( $response =~ m/^[qQ]$/ ) {
137 while( $line = <INFILE> ) {
148 $text =~ s{^[[:space:]]+}{};
149 $text =~ s{(<quote>)}{\033[1;36m$1\033[0m}g;
150 $text =~ s{(</quote>)}{\033[1;34m$1\033[0m}g;
151 $text =~ s{(</?spell>)}{\033[1;35m$1\033[0m}g;
152 $text =~ s{(<ch.apos/>)}{\033[1;32m$1\033[0m}g;
153 $text =~ s{($quoteMarks)}{\033[1m\033[43m$1\033[0m}g;
159 my ($message, $line) = @_;
162 print &highlight( $line ) . "\n";
163 print "\033[7m [continue]\033[0m >> ";
164 my $response = <STDIN>;