#!/usr/local/bin/perl # wants perl 5.0 or better # check_fascistly_overquoted.pl, by tchrist@mox.perl.com # # OPTIONS: -v for verbose flag, -t NN to change tolerance percentage from 50% # INPUT: a news article # OUTPUT: if -v, then shows how much it found and where # EXIT: 1 (failure) if tolerance exceeded, 0 (success) otherwise require 5.0; use Getopt::Std; getopts("vt:") || die "usage: $0 [-v] [-t tolerance] [input_file]\n"; $VERBOSE = $opt_v; $TOLERANCE = $opt_t || 50; $/ = ''; <>; # head header while ( <> ) { #last if eof && /^--/; if ($. == 2) { print; next; } # attribution s/\n+\Z/\n/; print qpara($_); } sub qpara { local $_ = shift; #print "BLOCK: \n$_\n"; $_ = qpara($_) if s/^(([^\w\s])(.*\n))(\2.*\n)+/$3/gm; return boxit($_); } sub boxit { local $_ = shift; s/^[-+]{2}\w+$//m if eof; return $_ unless split(/\n/); $max = 0; for (@_) { 1 while s/\t+/' 'x (length($&) * 8 - length($`) % 8)/e; $max = ($max > length) ? $max : length; } $edge = "+" . "-" x ($max+2) . "+\n"; $return = $edge; for (@_) { $return .= sprintf "| %-${max}s |\n", $_; } $return .= $edge . "\n"; return $return; }