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<ch.ampersand/>$2}xg ) { $replacements = 1; }
54 if( $modified =~ s{ [[:space:]]+ - [[:space:]]+ }{<ch.emdash/>}xg ) { $replacements = 1; }
55 if( $modified =~ s{ (?<!\!) ([[:space:]])* -- ([[:space:]])* (?!>) }{$1<ch.emdash/>$2}xg ) { $replacements = 1; }
56 if( $modified =~ s{ [[:space:]]* \227 [[:space:]]* }{<ch.emdash/>}xg ) { $replacements = 1; }
57 if( $modified =~ s{ ([[:digit:]]) - ([[:digit:]]) }{$1<ch.endash/>$2}xg ) { $replacements = 1; }
58 if( $modified =~ s{ [[:space:]]* \227 [[:space:]]* }{<ch.endash/>}xg ) { $replacements = 1; }
59 if( $modified =~ s{ > [[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)? }{><ch.lellips/>}xg ) { $replacements = 1; }
60 if( $modified =~ s{ [[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)? }{<ch.ellips/>}xg ) { $replacements = 1; }
61 if( $modified =~ s{ (</?quote>) \1 }{<ch.thinspace/>}xg ) { $replacements = 1; }
62 if( $modified =~ s{ <quote> \' }{<quote><ch.thinspace/><ch.apos/>}xg ) { $replacements = 1; }
63 if( $modified =~ s{ \' </quote> }{<ch.apos/><ch.thinspace/></quote>}xg ) { $replacements = 1; }
64 if( $modified =~ s{ __+ }{<ch.blankline/>}xg ) { $replacements = 1; }
65 if( $modified =~ s{\%}{<ch.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{(<ch.ampersand/>)}{$encodedStart$1$stop}g;
100 $text =~ s{(<ch.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{(<ch.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{(<ch.lellips/>)}{$encodedStart$1$stop}g;
109 $text =~ s{ > ([[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)?) }{>$start$1$stop}xg;
110 $text =~ s{(<ch.ellips/>)}{$encodedStart$1$stop}g;
111 $text =~ s{ ([[:space:]]* \. [[:space:]]* \. ([[:space:]]* \.)?) }{$start$1$stop}xg;
112 $text =~ s{(<ch.thinspace/>)}{$encodedStart$1$stop}g;
113 $text =~ s{ (</?quote> \1) }{$start$1$stop}xg;
114 $text =~ s{ (<quote> <ch.apos/>) }{$start$1$stop}xg;
115 $text =~ s{ (<ch.apos/> </quote>) }{$start$1$stop}xg;
116 $text =~ s{(<ch.blankline/>)}{$encodedStart$1$stop}g;
117 $text =~ s{ (__+) }{$start$1$stop}xg;
118 $text =~ s{(<ch.percent/>)}{$encodedStart$1$stop}g;
119 $text =~ s{(\%)}{$start$1$stop}xg;