1 # Hey emacs! This is a -*- Perl -*- script!
2 # Text_utils -- Perl utility functions for lintian
4 # Copyright (C) 1998 Christian Schwarz and Richard Braakman
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 # requires wrap() function
27 # html_wrap -- word-wrap a paragaph. The wrap() function from Text::Wrap
28 # is not suitable, because it chops words that are longer than the line
31 my ($lead, @text) = @_;
32 my @words = split(' ', join(' ', @text));
33 # subtract 1 to compensate for the lack of a space before the first word.
34 my $ll = length($lead) - 1;
38 while ($cnt <= $#words) {
39 if ($ll + 1 + length($words[$cnt]) > 76) {
41 # We're at the start of a line, and word still does not
43 $r .= $lead . shift(@words) . "\n";
46 $r .= $lead . join(' ', splice(@words, 0, $cnt)) . "\n";
47 $ll = length($lead) - 1;
51 $ll += 1 + length($words[$cnt]);
58 $r .= $lead . join(' ', @words) . "\n";
64 # split_paragraphs -- splits a bunch of text lines into paragraphs.
65 # This function returns a list of paragraphs.
66 # Paragraphs are separated by empty lines. Each empty line is a
67 # paragraph. Furthermore, indented lines are considered a paragraph.
68 sub split_paragraphs {
69 return "" unless (@_);
71 my $t = join("\n",@_);
76 # starts with space or empty line?
77 if (($t =~ s/^([ \t][^\n]*)\n?//o) or ($t =~ s/^()\n//o)) {
90 elsif ($t =~ s/^([^\n]*)\n?//o) {
93 # what else can happen?
95 fail("internal error in wrap");
116 s,\&maint\;,<a href=\"mailto:lintian-maint\@debian.org\">Lintian maintainer</a>,o; # "
117 s,\&debdev\;,<a href=\"mailto:debian-devel\@lists.debian.org\">debian-devel</a>,o; # "
152 # substitute Lintian &tags;
153 s,&maint;,lintian-maint\@debian.org,go;
154 s,&debdev;,debian-devel\@lists.debian.org,go;
156 # substitute HTML <tags>
161 # substitute HTML &tags;
179 # wrap_paragraphs -- wrap paragraphs in dpkg/dselect style.
180 # indented lines are not wrapped but displayed "as is"
181 sub wrap_paragraphs {
185 if ($lead eq 'HTML') {
191 for my $t (split_paragraphs(@_)) {
192 # empty or indented line?
193 if ($t =~ /^$/ or $t =~ /^\s/) {
197 $o .= html_wrap($lead, "$t\n");
199 $o .= wrap($lead, $lead, "$t\n");