]> the.earth.li Git - htag.git/blob - plugins/22reformat
910c76850bbf21edc04736c1393bdefce0f774be
[htag.git] / plugins / 22reformat
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2000-2001 Simon Huggins
4 # reformats longer lengths after the substitutions have taken place
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 # for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc., 59
18 # Temple Place, Suite 330, Boston, MA 02111-1307  USA
19
20 return;
21
22 use strict;
23 use Text::Wrap;
24
25 $Text::Wrap::columns=defined $cfg{'maxlinelen'} ? $cfg{'maxlinelen'} : 72;
26 $cfg{'first'}  ||= "";
27 $cfg{'leader'} ||= "";
28
29 my $anal_merge_debug=0;
30
31 sub remove_space($) {
32         my $text=shift;
33
34 # Remove whitespace at the end of lines but not newlines themselves.
35 # And don't remove the space if it comes directly after a -- which is
36 # anchored at the beginning of a line.
37
38         $text =~ s/(?<!^--)[    ]*$//mg;
39
40 # Remove any newlines from the very end of the string.
41         $text =~ s/\n*$//;
42         return $text;
43 }
44
45 sub reformat($) {
46         my $sig = shift;
47 # LRC
48 #$chunk=&chunksizealign($chunk,$len,$align);
49         while ($sig =~ /\@(CENTER|RIGHT|LEFT)(\d+)?\@/) {
50         }
51
52         return $sig;
53 }
54
55 my ($tag,$sig,$newsig);
56 open(SIG, "<$cfg{'tmpsigfile'}")
57         or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
58 while(<SIG>) {
59         $sig .= $_;
60 }
61 close(SIG);
62 if (defined $sig) {
63         $sig =  reformat($sig);
64         if (defined $sig) {
65                 open(SIG, ">$cfg{'tmpsigfile'}")
66                         or htagdie
67                         "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
68                 print SIG $sig;
69                 close(SIG);
70                 return;
71         } else {
72                 return(10);
73         }
74 }