X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=plugins%2F22reformat;fp=plugins%2F22reformat;h=02c9518008f32df427768d7e08c2bf54fb9adf38;hb=5fea61b142fcdeaaca2f6640f17e16a0d4e7b5c9;hp=910c76850bbf21edc04736c1393bdefce0f774be;hpb=f96cd91ac242f68bc9c7b14b5e4ef45af00cfe60;p=htag.git diff --git a/plugins/22reformat b/plugins/22reformat index 910c768..02c9518 100644 --- a/plugins/22reformat +++ b/plugins/22reformat @@ -1,6 +1,6 @@ #!/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 @@ -17,16 +17,16 @@ # 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; @@ -42,14 +42,35 @@ sub remove_space($) { 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); @@ -60,7 +81,8 @@ while() { } close(SIG); if (defined $sig) { - $sig = reformat($sig); + $sig = reformat($sig); + $sig = remove_space($sig); if (defined $sig) { open(SIG, ">$cfg{'tmpsigfile'}") or htagdie