]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* lib/Automake/Wrap.pm, lib/Automake/tests/Wrap.pl: New files.
authorAlexandre Duret-Lutz <adl@gnu.org>
Wed, 21 May 2003 20:30:07 +0000 (20:30 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Wed, 21 May 2003 20:30:07 +0000 (20:30 +0000)
* lib/Automake/Makefile.am (dist_perllib_DATA): Add Wrap.pm.
* lib/Automake/tests/Makefile.am (TESTS): Add Wrap.pl.
* automake.in (handle_texinfo_helper, pretty_print_rule)
(variable_output): Adjust to use makefile_wrap instead of
pretty_print_internal.
(pretty_print_internal): Remove.  Renamed as Automake::Wrap::wrap
and augmented to accept the $eol and $max_len arguments.

12 files changed:
ChangeLog
Makefile.in
automake.in
lib/Automake/Makefile.am
lib/Automake/Makefile.in
lib/Automake/Wrap.pm [new file with mode: 0644]
lib/Automake/tests/Makefile.am
lib/Automake/tests/Makefile.in
lib/Automake/tests/Wrap.pl [new file with mode: 0644]
lib/Makefile.in
stamp-vti
version.texi

index d2388be7b6f9bf1f735f8b2618922994331dd8bb..f3e33b6f8b14183753b7d125747875e783358238 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-05-21  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * lib/Automake/Wrap.pm, lib/Automake/tests/Wrap.pl: New files.
+       * lib/Automake/Makefile.am (dist_perllib_DATA): Add Wrap.pm.
+       * lib/Automake/tests/Makefile.am (TESTS): Add Wrap.pl.
+       * automake.in (handle_texinfo_helper, pretty_print_rule)
+       (variable_output): Adjust to use makefile_wrap instead of
+       pretty_print_internal.
+       (pretty_print_internal): Remove.  Renamed as Automake::Wrap::wrap
+       and augmented to accept the $eol and $max_len arguments.
+
 2003-05-18  Alexandre Duret-Lutz  <adl@gnu.org>
 
        * lib/Autom4te/XFile.pm, lib/config.guess, lib/config.sub,
index ea09e6733149e09aefbebad6218bcf24c1e22b07..7cc30da6154bd76301fa5c3025669fecfd9c9b55 100644 (file)
@@ -340,11 +340,11 @@ dist-info: $(INFO_DEPS)
 
 mostlyclean-aminfo:
        -rm -rf automake.aux automake.cm automake.cp automake.cps automake.cv \
-         automake.fn automake.ky automake.kys automake.log automake.op \
-         automake.ov automake.pg automake.pgs automake.tmp \
-         automake.toc automake.tp automake.tps automake.tr automake.vr \
-         automake.vrs automake.dvi automake.pdf automake.ps \
-         automake.html
+         automake.fn automake.ky automake.kys automake.log \
+         automake.op automake.ov automake.pg automake.pgs \
+         automake.tmp automake.toc automake.tp automake.tps \
+         automake.tr automake.vr automake.vrs automake.dvi \
+         automake.pdf automake.ps automake.html
 
 maintainer-clean-aminfo:
        @list='$(INFO_DEPS)'; for i in $$list; do \
@@ -733,10 +733,10 @@ uninstall-info: uninstall-info-recursive
        info-recursive install install-am install-binSCRIPTS \
        install-data install-data-am install-data-recursive \
        install-exec install-exec-am install-exec-recursive \
-       install-info install-info-am install-info-recursive install-man \
-       install-recursive install-strip installcheck installcheck-am \
-       installdirs installdirs-am installdirs-recursive \
-       maintainer-clean maintainer-clean-aminfo \
+       install-info install-info-am install-info-recursive \
+       install-man install-recursive install-strip installcheck \
+       installcheck-am installdirs installdirs-am \
+       installdirs-recursive maintainer-clean maintainer-clean-aminfo \
        maintainer-clean-generic maintainer-clean-recursive \
        maintainer-clean-vti mostlyclean mostlyclean-aminfo \
        mostlyclean-generic mostlyclean-recursive mostlyclean-vti pdf \
index 6682be2decb8d8ffc3a257ed09732fe8ead09d34..eff902f24d4f7df5eb00d12cd5b0f01e8661ab31 100755 (executable)
@@ -129,6 +129,7 @@ use Automake::Location;
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
 use Automake::Version;
+use Automake::Wrap 'makefile_wrap';
 use File::Basename;
 use Tie::RefHash;
 use Carp;
@@ -3847,7 +3848,7 @@ sub handle_texinfo_helper
     &define_variable ('am__TEXINFO_TEX_DIR', $texinfodir, INTERNAL);
 
     # The return value.
-    my $texiclean = &pretty_print_internal ("", "\t  ", @texi_cleans);
+    my $texiclean = makefile_wrap ("", "\t  ", @texi_cleans);
 
     push (@dist_targets, 'dist-info');
 
@@ -5900,43 +5901,10 @@ sub derive_suffix ($$)
 
 ################################################################
 
-# Pretty-print something.  HEAD is what should be printed at the
-# beginning of the first line, FILL is what should be printed at the
-# beginning of every subsequent line.
-sub pretty_print_internal
-{
-    my ($head, $fill, @values) = @_;
-
-    my $column = length ($head);
-    my $result = $head;
-
-    # Fill length is number of characters.  However, each Tab
-    # character counts for eight.  So we count the number of Tabs and
-    # multiply by 7.
-    my $fill_length = length ($fill);
-    $fill_length += 7 * ($fill =~ tr/\t/\t/d);
-
-    foreach (@values)
-    {
-       # "71" because we also print a space.
-       if ($column + length ($_) > 71)
-       {
-           $result .= " \\\n" . $fill;
-           $column = $fill_length;
-       }
-       $result .= ' ' if $result =~ /\S\z/;
-       $result .= $_;
-       $column += length ($_) + 1;
-    }
-
-    $result .= "\n";
-    return $result;
-}
-
 # Pretty-print something and append to output_rules.
 sub pretty_print_rule
 {
-    $output_rules .= &pretty_print_internal (@_);
+    $output_rules .= &makefile_wrap (@_);
 }
 
 
@@ -6888,12 +6856,11 @@ sub variable_output ($@)
 
       if ($var_pretty{$var}{$cond} == VAR_PRETTY)
        {
-         # Suppress escaped new lines.  &pretty_print_internal will
+         # Suppress escaped new lines.  &makefile_wrap will
          # add them back, maybe at other places.
          $val =~ s/\\$//mg;
-         $output_vars .= pretty_print_internal ("$str$var $equals",
-                                                "$str\t",
-                                                split (' ' , $val));
+         $output_vars .= makefile_wrap ("$str$var $equals",
+                                        "$str\t", split (' ' , $val));
        }
       else                     # VAR_ASIS
        {
index c51546f78145f035771ff08ee876b71613ffdb3c..fc881f212bc154b86a02f9d3f17ee07c9f81b054 100644 (file)
@@ -29,4 +29,5 @@ dist_perllib_DATA = \
   Location.pm \
   Struct.pm \
   Version.pm \
-  XFile.pm
+  XFile.pm \
+  Wrap.pm
index bcca798335057785e84910d380d4f99365ff114e..d03e9d777d30ff92fd44f98f4a314b4d192a3a23 100644 (file)
@@ -137,7 +137,8 @@ dist_perllib_DATA = \
   Location.pm \
   Struct.pm \
   Version.pm \
-  XFile.pm
+  XFile.pm \
+  Wrap.pm
 
 all: all-recursive
 
@@ -434,22 +435,22 @@ uninstall-am: uninstall-dist_perllibDATA uninstall-info-am
 
 uninstall-info: uninstall-info-recursive
 
-.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am clean \
-       clean-generic clean-recursive ctags ctags-recursive distclean \
-       distclean-generic distclean-recursive distclean-tags distdir \
-       dvi dvi-am dvi-recursive html html-am html-recursive info \
-       info-am info-recursive install install-am install-data \
-       install-data-am install-data-recursive install-dist_perllibDATA \
-       install-exec install-exec-am install-exec-recursive \
-       install-info install-info-am install-info-recursive install-man \
-       install-recursive install-strip installcheck installcheck-am \
-       installdirs installdirs-am installdirs-recursive \
-       maintainer-clean maintainer-clean-generic \
-       maintainer-clean-recursive mostlyclean mostlyclean-generic \
-       mostlyclean-recursive pdf pdf-am pdf-recursive ps ps-am \
-       ps-recursive tags tags-recursive uninstall uninstall-am \
-       uninstall-dist_perllibDATA uninstall-info-am \
-       uninstall-info-recursive uninstall-recursive
+.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
+       clean clean-generic clean-recursive ctags ctags-recursive \
+       distclean distclean-generic distclean-recursive distclean-tags \
+       distdir dvi dvi-am dvi-recursive html html-am html-recursive \
+       info info-am info-recursive install install-am install-data \
+       install-data-am install-data-recursive \
+       install-dist_perllibDATA install-exec install-exec-am \
+       install-exec-recursive install-info install-info-am \
+       install-info-recursive install-man install-recursive \
+       install-strip installcheck installcheck-am installdirs \
+       installdirs-am installdirs-recursive maintainer-clean \
+       maintainer-clean-generic maintainer-clean-recursive \
+       mostlyclean mostlyclean-generic mostlyclean-recursive pdf \
+       pdf-am pdf-recursive ps ps-am ps-recursive tags tags-recursive \
+       uninstall uninstall-am uninstall-dist_perllibDATA \
+       uninstall-info-am uninstall-info-recursive uninstall-recursive
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/lib/Automake/Wrap.pm b/lib/Automake/Wrap.pm
new file mode 100644 (file)
index 0000000..7695701
--- /dev/null
@@ -0,0 +1,167 @@
+# Copyright (C) 2003  Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+package Automake::Wrap;
+
+use strict;
+
+require Exporter;
+use vars '@ISA', '@EXPORT_OK';
+@ISA = qw/Exporter/;
+@EXPORT_OK = qw/wrap makefile_wrap/;
+
+=head1 NAME
+
+Automake::Wrap - a paragraph formater
+
+=head1 SYNOPSIS
+
+  use Automake::Wrap 'wrap', 'makefile_wrap';
+
+  print wrap ($first_ident, $next_ident, $end_of_line, $max_length,
+              @values);
+
+  print makefile_wrap ("VARIABLE = ", "    ", @values);
+
+=head1 DESCRIPTION
+
+This modules provide facility to format list of strings.  It is
+comparable to Perl's L<Text::Wrap>, however we can't use L<Text::Wrap>
+because some versions will abort when some word to print exceed the
+maximum length allowed.  (Ticket #17141, fixed in Perl 5.8.0.)
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+# tab_length ($TXT)
+# -----------------
+# Compute the length of TXT, counting tab characters as 8 characters.
+sub tab_length($)
+{
+  my ($txt) = @_;
+  my $len = length ($txt);
+  $len += 7 * ($txt =~ tr/\t/\t/d);
+  return $len;
+}
+
+=item C<wrap ($head, $fill, $eol, $max_len, @values)>
+
+Format C<@values> as a block of text that starts with C<$head>,
+followed by the strings in C<@values> separated by spaces or by
+C<"$eol\n$fill"> so that the lenght of each line never exceed
+C<$max_len>.
+
+The C<$max_len> contraint is ignored for C<@values> items which
+are too big to fit alone one a line.
+
+The constructed paragraph is C<"\n">-terminated.
+
+=cut
+
+sub wrap($$$$@)
+{
+  my ($head, $fill, $eol, $max_len, @values) = @_;
+
+  my $result = $head;
+  my $column = tab_length ($head);
+
+  my $fill_len = tab_length ($fill);
+  my $eol_len = tab_length ($eol);
+
+  my $not_first_word = 0;
+
+  foreach (@values)
+    {
+      my $len = tab_length ($_);
+
+      # See if the new variable fits on this line.
+      # (The + 1 is for the space we add in front of the value.).
+      if ($column + $len + $eol_len + 1 > $max_len
+         # Do not break before the first word if it does not fit on
+         # the next line anyway.
+         && ($not_first_word || $fill_len + $len + $eol_len + 1 <= $max_len))
+       {
+         # Start a new line.
+         $result .= "$eol\n" . $fill;
+         $column = $fill_len;
+       }
+      elsif ($not_first_word)
+       {
+         # Add a space only if result does not already end
+         # with a space.
+         $_ = " $_" if $result =~ /\S\z/;
+         ++$len;
+       }
+      $result .= $_;
+      $column += $len;
+      $not_first_word = 1;
+    }
+
+  $result .= "\n";
+  return $result;
+}
+
+
+=item C<makefile_wrap ($head, $fill, @values)>
+
+Format C<@values> in a way which is suitable for F<Makefile>s.
+This is comparable to C<wrap>, except C<$eol> is known to
+be C<" \\">, and the maximum length has been hardcoded to C<72>.
+
+A space is appended to C<$head> when this is not already
+the case.
+
+This can be used to format variable definitions or dependency lines.
+
+  makefile_wrap ('VARIABLE =', "\t", @values);
+  makefile_wrap ('rule:', "\t", @dependencies);
+
+=cut
+
+sub makefile_wrap ($$@)
+{
+  my ($head, $fill, @values) = @_;
+  if (@values)
+    {
+      $head .= ' ' if $head =~ /\S\z/;
+      return wrap $head, $fill, " \\", 72, @values;
+    }
+  return "$head\n";
+}
+
+
+1;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
index 22127660eb1a8d09b9649d0b242ae2934bd6dc08..0ccd955e1576a886b99a8da98480a6d6d29cb8f5 100644 (file)
@@ -21,6 +21,7 @@ TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
 TESTS = \
 Condition.pl \
 DisjConditions.pl \
-Version.pl
+Version.pl \
+Wrap.pl
 
 EXTRA_DIST = $(TESTS)
index 0fcfa077cec88be1ac2651cd9343eb37794c7539..4a50e602bd2fde7266d9657bac03f8e3bccccb69 100644 (file)
@@ -116,7 +116,8 @@ TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
 TESTS = \
 Condition.pl \
 DisjConditions.pl \
-Version.pl
+Version.pl \
+Wrap.pl
 
 EXTRA_DIST = $(TESTS)
 all: all-am
diff --git a/lib/Automake/tests/Wrap.pl b/lib/Automake/tests/Wrap.pl
new file mode 100644 (file)
index 0000000..c579343
--- /dev/null
@@ -0,0 +1,82 @@
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+use Automake::Wrap 'wrap';
+
+my $failed = 0;
+
+sub test_wrap
+{
+  my ($in, $exp_out) = @_;
+
+  my $out = &wrap (@$in);
+  if ($out ne $exp_out)
+    {
+      print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
+      ++$failed;
+    }
+}
+
+my @tests = (
+  [["HEAD:", "NEXT:", "CONT", 13, "v" ,"a", "l", "ue", "s", "values"],
+"HEAD:v aCONT
+NEXT:l ueCONT
+NEXT:sCONT
+NEXT:values
+"],
+  [["rule: ", "\t", " \\", 20, "dep1" ,"dep2", "dep3", "dep4", "dep5",
+    "dep06", "dep07", "dep08"],
+"rule: dep1 dep2 \\
+\tdep3 dep4 \\
+\tdep5 dep06 \\
+\tdep07 \\
+\tdep08
+"],
+  [["big header:", "big continuation:", " END", 5, "diag1", "diag2", "diag3"],
+"big header:diag1 END
+big continuation:diag2 END
+big continuation:diag3
+"],
+  [["big header:", "cont: ", " END", 16, "word1", "word2"],
+"big header: END
+cont: word1 END
+cont: word2
+"]);
+
+
+test_wrap (@{$_}) foreach @tests;
+
+exit $failed;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
index 28b97103014aa7858a277ad7b4aa5653fe61a1a1..b44755e9331fd88830dc41a05c1dcb7ea53ccb21 100644 (file)
@@ -453,23 +453,24 @@ uninstall-am: uninstall-dist_pkgvdataDATA uninstall-dist_scriptDATA \
 
 uninstall-info: uninstall-info-recursive
 
-.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am clean \
-       clean-generic clean-recursive ctags ctags-recursive distclean \
-       distclean-generic distclean-recursive distclean-tags distdir \
-       dvi dvi-am dvi-recursive html html-am html-recursive info \
-       info-am info-recursive install install-am install-data \
+.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
+       clean clean-generic clean-recursive ctags ctags-recursive \
+       distclean distclean-generic distclean-recursive distclean-tags \
+       distdir dvi dvi-am dvi-recursive html html-am html-recursive \
+       info info-am info-recursive install install-am install-data \
        install-data-am install-data-recursive \
        install-dist_pkgvdataDATA install-dist_scriptDATA install-exec \
        install-exec-am install-exec-recursive install-info \
        install-info-am install-info-recursive install-man \
        install-recursive install-strip installcheck installcheck-am \
        installcheck-local installdirs installdirs-am \
-       installdirs-recursive maintainer-clean maintainer-clean-generic \
-       maintainer-clean-recursive mostlyclean mostlyclean-generic \
-       mostlyclean-recursive pdf pdf-am pdf-recursive ps ps-am \
-       ps-recursive tags tags-recursive uninstall uninstall-am \
-       uninstall-dist_pkgvdataDATA uninstall-dist_scriptDATA \
-       uninstall-info-am uninstall-info-recursive uninstall-recursive
+       installdirs-recursive maintainer-clean \
+       maintainer-clean-generic maintainer-clean-recursive \
+       mostlyclean mostlyclean-generic mostlyclean-recursive pdf \
+       pdf-am pdf-recursive ps ps-am ps-recursive tags tags-recursive \
+       uninstall uninstall-am uninstall-dist_pkgvdataDATA \
+       uninstall-dist_scriptDATA uninstall-info-am \
+       uninstall-info-recursive uninstall-recursive
 
 
 install-data-hook:
index b1db8c4300aa93a246c4a9c998d821a29a9e22f5..2c9e700471828477a56d4eba086ac33a702178cf 100644 (file)
--- a/stamp-vti
+++ b/stamp-vti
@@ -1,4 +1,4 @@
-@set UPDATED 17 May 2003
+@set UPDATED 21 May 2003
 @set UPDATED-MONTH May 2003
 @set EDITION 1.7a
 @set VERSION 1.7a
index b1db8c4300aa93a246c4a9c998d821a29a9e22f5..2c9e700471828477a56d4eba086ac33a702178cf 100644 (file)
@@ -1,4 +1,4 @@
-@set UPDATED 17 May 2003
+@set UPDATED 21 May 2003
 @set UPDATED-MONTH May 2003
 @set EDITION 1.7a
 @set VERSION 1.7a