1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#!/usr/bin/perl -w
# Copyright (C) 2000-2003 Simon Huggins
# reformats longer lengths after the substitutions have taken place
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use vars qw($nomod);
BEGIN {
unless (eval "use Text::Balanced qw(gen_extract_tagged);1;") {
print STDERR "Text::Balanced not available, reformat plugin will not work\n";
$nomod=1;
}
}
return if $nomod;
sub remove_space($) {
my $text=shift;
# Remove whitespace at the end of lines but not newlines themselves.
# And don't remove the space if it comes directly after a -- which is
# anchored at the beginning of a line.
$text =~ s/(?<!^--)[ ]*$//mg;
# Remove any newlines from the very end of the string.
$text =~ s/\n*$//;
return $text;
}
sub reformat ($) {
my $text = shift;
my ($ext,$end,$beg,$otag,$ctag,$stuff);
my $process = gen_extract_tagged('<(?:CENTER|RIGHT|LEFT)\d+>',
undef,
'(?s).*(?=<(?:CENTER|RIGHT|LEFT)\d+>)',
{reject => ['<(?:CENTER|RIGHT|LEFT)\d+>']} );
while (1) {
($stuff, $end, $beg, $otag, $ext, $ctag) = &$process($text);
if (not defined $stuff) {
if ($text =~ /<(?:CENTER|RIGHT|LEFT)\d+>/) {
nicedie($@->{'error'});
}
}
last if !$stuff;
my $size = $otag;
$size =~ s/<(?:CENTER|RIGHT|LEFT)//;
$size =~ s/>//;
my $align = $otag;
$align =~ s/^.(.).*$/$1/;
my $c = chunksizealign($ext, $size, $align);
$stuff=quotemeta($stuff);
$text =~ s/$stuff/$c/;
}
return $text;
}
my ($tag,$sig,$newsig);
open(SIG, "<$cfg{'tmpsigfile'}")
or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
while(<SIG>) {
$sig .= $_;
}
close(SIG);
if (defined $sig) {
$sig = reformat($sig);
$sig = remove_space($sig);
if (defined $sig) {
open(SIG, ">$cfg{'tmpsigfile'}")
or htagdie
"$0: Could not open $cfg{'tmpsigfile'}: $!\n";
print SIG $sig;
close(SIG);
return;
} else {
return(10);
}
}
|