#!/usr/bin/perl -w
-# Copyright (C) 2000-2001 Simon Huggins
+# 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
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-return;
-
use strict;
-use Text::Wrap;
-
-$Text::Wrap::columns=defined $cfg{'maxlinelen'} ? $cfg{'maxlinelen'} : 72;
-$cfg{'first'} ||= "";
-$cfg{'leader'} ||= "";
+use vars qw($nomod);
-my $anal_merge_debug=0;
+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;
return $text;
}
-sub reformat($) {
- my $sig = shift;
-# LRC
-#$chunk=&chunksizealign($chunk,$len,$align);
- while ($sig =~ /\@(CENTER|RIGHT|LEFT)(\d+)?\@/) {
- }
+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;
- return $sig;
+ 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);
}
close(SIG);
if (defined $sig) {
- $sig = reformat($sig);
+ $sig = reformat($sig);
+ $sig = remove_space($sig);
if (defined $sig) {
open(SIG, ">$cfg{'tmpsigfile'}")
or htagdie