3 # Uses ANSI color escapes to highlight text and for cursor movement
8 my $usage = "Usage:\n\tgbfixquotes.pl INFILE OUTFILE\n";
12 my ($infile, $outfile);
15 $infile = shift @ARGV;
16 $outfile = shift @ARGV;
22 if( $infile =~ m{(^.*$)} && -f $1 ) {
23 open( INFILE, "<$1" ) or die "Error: unable to read from \"$infile\": $!\n";
26 die "Error: bad input file\n";
29 if( $outfile =~ m{(^.*$)} ) {
30 open( OUTFILE, ">$1" ) or die "Error: unable to write to \"$outfile\": $!\n";
33 die "Error: bad output file\n";
36 while( my $line = <INFILE> ) {
37 $line = &encodify( $line );
46 ################################################################################
53 if( $modified =~ s{ ([[:space:]]) \& ([[:space:]]) }{$1\&ersand;$2}xg ) { $replacements = 1; }
54 if( $modified =~ s{ [[:space:]]+ - [[:space:]]+ }{\&emdash;}xg ) { $replacements = 1; }
55 if( $modified =~ s{ (?<!\!) ([[:space:]])* -- ([[:space:]])* (?!>) }{$1\&emdash;$2}xg ) { $replacements = 1; }
56 if( $modified =~ s{ [[:space:]]* \227 [[:space:]]* }{\&emdash;}xg ) { $replacements = 1; }
57 if( $modified =~ s{ ([[:digit:]]) - ([[:digit:]]) }{$1\&endash;$2}xg ) { $replacements = 1; }
58 if( $modified =~ s{ [[:space:]]* \227 [[:space:]]* }{\&endash;}xg ) { $replacements = 1; }
59 if( $modified =~ s{ > [[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)? }{>\&lellips;}xg ) { $replacements = 1; }
60 if( $modified =~ s{ [[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)? }{\&ellips;}xg ) { $replacements = 1; }
61 if( $modified =~ s{ (</?quote>) \1 }{\&thinspace;}xg ) { $replacements = 1; }
62 if( $modified =~ s{ <quote> \' }{<quote>\&thinspace;\'}xg ) { $replacements = 1; }
63 if( $modified =~ s{ \' </quote> }{\'\&thinspace;</quote>}xg ) { $replacements = 1; }
64 if( $modified =~ s{ __+ }{\&blankline;}xg ) { $replacements = 1; }
65 if( $modified =~ s{\%}{\&percent;}xg ) { $replacements = 1; }
69 print &highlight( $line ) . "\n";
70 print &highlight( $modified );
71 print "\033[7m (a)ccept, (r)eject, (q)uit: [accept]\033[0m >> ";
73 my $response = <STDIN>;
75 if( $response =~ m/^[aA]$/ || $response eq "" ) { $line = $modified; }
76 elsif( $response =~ m/^[qQ]$/ ) {
78 while( $line = <INFILE> ) {
85 else { return $line; }
91 my $start = "\033[45;30m";
92 my $encodedStart = "\033[40;35m";
93 my $dashStart = "\033[46;30m";
94 my $encodedDashStart = "\033[40;36m";
97 $text =~ s{^[[:space:]]+}{}g;
98 $text =~ s{ ([[:space:]]) \& ([[:space:]]) }{$1$start\&$stop$2}xg;
99 $text =~ s{(\&ersand;)}{$encodedStart$1$stop}g;
100 $text =~ s{(\&emdash;)}{$encodedDashStart$1$stop}g;
101 $text =~ s{ [[:space:]] (\&) [[:space:]] }{$dashStart$1$stop}xg;
102 $text =~ s{ ([[:space:]]+ - [[:space:]]+) }{$dashStart$1$stop}xg;
103 $text =~ s{ (?<!\!) ([[:space:]]* -- [[:space:]]*) }{$dashStart$1$stop}xg;
104 $text =~ s{ ([[:space:]]* \227 [[:space:]]*) }{$dashStart$1$stop}xg;
105 $text =~ s{(\&endash;)}{$encodedDashStart$1$stop}g;
106 $text =~ s{ ([[:digit:]]) - ([[:digit:]]) }{$1$dashStart-$stop$2}xg;
107 $text =~ s{ ([[:space:]]* \226 [[:space:]]*) }{$dashStart$1$stop}xg;
108 $text =~ s{(\&lellips;)}{$encodedStart$1$stop}g;
109 $text =~ s{ > ([[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)?) }{>$start$1$stop}xg;
110 $text =~ s{(\&ellips;)}{$encodedStart$1$stop}g;
111 $text =~ s{ ([[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)?) }{$start$1$stop}xg;
112 $text =~ s{(\&thinspace;)}{$encodedStart$1$stop}g;
113 $text =~ s{ (</?quote> \1) }{$start$1$stop}xg;
114 $text =~ s{ (<quote> \') }{$start$1$stop}xg;
115 $text =~ s{ (\' </quote>) }{$start$1$stop}xg;
116 $text =~ s{(\&blankline;)}{$encodedStart$1$stop}g;
117 $text =~ s{ (__+) }{$start$1$stop}xg;
118 $text =~ s{(\&percent;)}{$encodedStart$1$stop}g;
119 $text =~ s{(\%)}{$start$1$stop}xg;