From: Alexandre Duret-Lutz Date: Wed, 21 May 2003 20:30:07 +0000 (+0000) Subject: * lib/Automake/Wrap.pm, lib/Automake/tests/Wrap.pl: New files. X-Git-Tag: Release-1-7b~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=926cb59f728ce33d6242cd8cb9524142668c476a;p=thirdparty%2Fautomake.git * 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. --- diff --git a/ChangeLog b/ChangeLog index d2388be7b..f3e33b6f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-05-21 Alexandre Duret-Lutz + + * 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 * lib/Autom4te/XFile.pm, lib/config.guess, lib/config.sub, diff --git a/Makefile.in b/Makefile.in index ea09e6733..7cc30da61 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ diff --git a/automake.in b/automake.in index 6682be2de..eff902f24 100755 --- a/automake.in +++ b/automake.in @@ -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 { diff --git a/lib/Automake/Makefile.am b/lib/Automake/Makefile.am index c51546f78..fc881f212 100644 --- a/lib/Automake/Makefile.am +++ b/lib/Automake/Makefile.am @@ -29,4 +29,5 @@ dist_perllib_DATA = \ Location.pm \ Struct.pm \ Version.pm \ - XFile.pm + XFile.pm \ + Wrap.pm diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in index bcca79833..d03e9d777 100644 --- a/lib/Automake/Makefile.in +++ b/lib/Automake/Makefile.in @@ -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 index 000000000..76957013b --- /dev/null +++ b/lib/Automake/Wrap.pm @@ -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, however we can't use L +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 + +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 + +Format C<@values> in a way which is suitable for Fs. +This is comparable to C, 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: diff --git a/lib/Automake/tests/Makefile.am b/lib/Automake/tests/Makefile.am index 22127660e..0ccd955e1 100644 --- a/lib/Automake/tests/Makefile.am +++ b/lib/Automake/tests/Makefile.am @@ -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) diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index 0fcfa077c..4a50e602b 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -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 index 000000000..c57934364 --- /dev/null +++ b/lib/Automake/tests/Wrap.pl @@ -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: diff --git a/lib/Makefile.in b/lib/Makefile.in index 28b971030..b44755e93 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -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: diff --git a/stamp-vti b/stamp-vti index b1db8c430..2c9e70047 100644 --- 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 diff --git a/version.texi b/version.texi index b1db8c430..2c9e70047 100644 --- a/version.texi +++ b/version.texi @@ -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