3 # Copyright (C) 2000-2001 Simon Huggins
4 # merge merges the sig and the tag but also merges the sig and the new style
5 # plugin things (i.e. all those silly files in $cfg{'tmpdir'}
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 2 of the License, or (at your option)
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc., 59
19 # Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 $Text::Wrap::columns=defined $cfg{'maxlinelen'} ? $cfg{'maxlinelen'} : 72;
26 $cfg{'leader'} ||= "";
28 my $anal_merge_debug=0;
33 # Remove whitespace at the end of lines but not newlines themselves.
34 # And don't remove the space if it comes directly after a -- which is
35 # anchored at the beginning of a line.
37 $text =~ s/(?<!^--)[ ]*$//mg;
39 # Remove any newlines from the very end of the string.
52 my ($plugin,$len,$align,$wascr);
55 while ($sig =~ /@([A-Za-z]?)([1-9][0-9]*)([RC]?)@/) {
61 } elsif (not defined $2) {
65 } elsif ($2 =~ /^[RC]$/) {
75 print STDERR "plugin,len,type = #$plugin#,#$len#,#$align#\n" if $anal_merge_debug;
77 $chunk = getplugin($plugin);
78 print STDERR "Got plugin $plugin and $chunk\n"
80 $sig =~ s/\@$plugin$len[RC]?@/$chunk/;
81 print STDERR "Sig is now:\n$sig" if $anal_merge_debug;
86 $chunk = substr $tag, 0, $len;
87 print STDERR "chunk,tag = #$chunk#,#$tag#".length($tag)." ".length($chunk)."\n"
89 if ($chunk =~ s/^([^\n]+)\n+(.*)$/$1/s) {
91 print STDERR "\$extra = [$extra]\n"
94 if (length($chunk) < $len) {
95 print STDERR "length(chunk) < $len\n"
97 $chunk=&chunksizealign($chunk,$len,$align);
98 print STDERR "chunk = #$chunk#\n"
101 if (length($tag) < $len + 1) {
102 $tag= $extra ? $extra : "";
103 print STDERR "length(tag) < $len + 1, tag now = #$tag#(extra = #$extra#)\n"
104 if $anal_merge_debug;
105 } elsif (substr $tag, 0, $len + 1 eq ' ') {
106 $tag=substr $tag, $len + 1;
107 $tag=$extra . $tag if defined $extra;
108 print STDERR "substr tag, 0, $len + 1 was a space. tag now = #$tag#\n"
109 if $anal_merge_debug;
111 $tag=substr $tag, $len;
112 ### Back up a word in $chunk
113 $tag=$extra . $tag if defined $extra;
114 print STDERR "didn't break at space. Backing up word. tag now = #$tag#\n"
115 if $anal_merge_debug;
116 if ($chunk =~ s/(.*) (.*)$/$1/) {
118 $chunk=&chunksizealign($chunk,$len,$align);
120 print STDERR "If space in chunk then change chunk and add word to tag.".
121 "Reformat chunk now = #$chunk# (tag = #$tag#)\n" if $anal_merge_debug;
123 $sig =~ s/\@$plugin$len[RC]?@/$chunk/;
126 $sig =~ s/@([0-9]+)[RC]?@/" " x $1/eg;
127 $cfg{'notag'} = $notag;
128 if ($tag and not $notag) {
131 return &remove_space($sig);
140 $count = $plugins{$plugin} if defined $plugins{$plugin};
141 open(IN, "$cfg{'tmpdir'}/$plugin") or htagdie "$0: Could not open $cfg{'tmpdir'}/$plugin: $!\n";
147 $plugins{$plugin} = $count+1;
155 my ($tag,$sig,$newsig);
156 open(SIG, "<$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
161 open(TAG, "<$cfg{'tmptagfile'}") or htagdie "$1: Could not open $cfg{'tmptagfile'}: $!\n";
166 if (defined $sig and $sig =~ /@[A-Za-z]?[1-9][0-9]*[RC]?@/) {
167 $sig = merge($tag,$sig);
169 my $formatted_tag = Text::Wrap::wrap($cfg{'first'},$cfg{'leader'},$tag);
170 $sig .= $formatted_tag;
171 $sig = &remove_space($sig);
175 open(SIG, ">$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
176 print SIG "\n" while $cfg{'newline'}--;