Index: ChangeLog from Akim Demaille * lib/Autom4te/General.pm (&find_file, &mtime, &update_file) (&xsystem, &contents): Remove, since they are exported by... * lib/Autom4te/FileUtils.pm: this. More perldoc. Index: bin/autom4te.in =================================================================== RCS file: /cvsroot/autoconf/autoconf/bin/autom4te.in,v retrieving revision 1.84 diff -u -u -r1.84 autom4te.in --- bin/autom4te.in 20 Jun 2003 07:55:35 -0000 1.84 +++ bin/autom4te.in 20 Aug 2003 08:25:49 -0000 @@ -43,6 +43,7 @@ package Request; use Data::Dumper; +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::Struct; use Autom4te::XFile; @@ -235,6 +236,7 @@ package Autom4te; +use Autom4te::FileUtils; use Autom4te::General; use File::Basename; use Autom4te::XFile; Index: bin/autoreconf.in =================================================================== RCS file: /cvsroot/autoconf/autoconf/bin/autoreconf.in,v retrieving revision 1.114 diff -u -u -r1.114 autoreconf.in --- bin/autoreconf.in 16 May 2003 09:54:46 -0000 1.114 +++ bin/autoreconf.in 20 Aug 2003 08:25:49 -0000 @@ -39,6 +39,7 @@ $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos'); } +use Autom4te::FileUtils; use Autom4te::General; use Autom4te::XFile; # Do not use Cwd::chdir, since it might hang. Index: lib/Autom4te/FileUtils.pm =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/FileUtils.pm,v retrieving revision 1.1 diff -u -u -r1.1 FileUtils.pm --- lib/Autom4te/FileUtils.pm 20 Aug 2003 06:51:34 -0000 1.1 +++ lib/Autom4te/FileUtils.pm 20 Aug 2003 08:25:49 -0000 @@ -17,6 +17,20 @@ package Autom4te::FileUtils; +=head1 NAME + +Autom4te::FileUtils - handling files + +=head1 SYNOPSIS + + use Autom4te::FileUtils + +=head1 DESCRIPTION + +This perl module provides various general purpose file handling functions. + +=cut + use strict; use Exporter; use File::stat; @@ -27,18 +41,27 @@ use vars qw (@ISA @EXPORT); @ISA = qw (Exporter); address@hidden = qw (&find_file &mtime &update_file &xsystem &contents); address@hidden = qw (&contents + &find_file &mtime &update_file + &xsystem &xqx); +=item C + +Return the first path for a C<$filename> in the Cs. + +We match exactly the behavior of GNU M4: first look in the current +directory (which includes the case of absolute file names), and, if +the file is not absolute, just fail. Otherwise, look in C<@include>. + +If the file is flagged as optional (ends with C), then return undef +if absent, otherwise exit with error. + +=cut + # $FILENAME # find_file ($FILENAME, @INCLUDE) # ------------------------------- -# We match exactly the behavior of GNU m4: first look in the current -# directory (which includes the case of absolute file names), and, if -# the file is not absolute, just fail. Otherwise, look in the path. -# -# If the file is flagged as optional (ends with `?'), then return undef -# if absent. sub find_file ($@) { use File::Spec; @@ -71,11 +94,16 @@ return undef; } +=item C + +Return the mtime of C<$file>. Missing files, or C<-> standing for +C or C are ``obsolete'', i.e., as old as possible. + +=cut + # $MTIME # MTIME ($FILE) # ------------- -# Return the mtime of $FILE. Missing files, or `-' standing for STDIN -# or STDOUT are ``obsolete'', i.e., as old as possible. sub mtime ($) { my ($file) = @_; @@ -90,10 +118,16 @@ } +=item C + +Rename C<$from> as C<$to>, preserving C<$to> timestamp if it has not +changed. Recognize C<$to> = C<-> standing for C. C<$from> is +always removed/renamed. + +=cut + # &update_file ($FROM, $TO) # ------------------------- -# Rename $FROM as $TO, preserving $TO timestamp if it has not changed. -# Recognize `$TO = -' standing for stdin. sub update_file ($$) { my ($from, $to) = @_; @@ -174,9 +208,14 @@ } } +=item C + +Same as C (but in scalar context), but fails on errors. + +=cut + # xqx ($COMMAND) # -------------- -# Same as `qx' (but in scalar context), but fails on errors. sub xqx ($) { my ($command) = @_; @@ -192,6 +231,13 @@ } +=item C + +Same as C, but fails on errors, and reports the C<$command> +in verbose mode. + +=cut + # xsystem ($COMMAND) # ------------------ sub xsystem ($) @@ -206,9 +252,14 @@ } +=item C + +Return the contents of c<$filename>. + +=cut + # contents ($FILENAME) # -------------------- -# Swallow the contents of file $FILENAME. sub contents ($) { my ($file) = @_; Index: lib/Autom4te/General.pm =================================================================== RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/General.pm,v retrieving revision 1.28 diff -u -u -r1.28 General.pm --- lib/Autom4te/General.pm 2 Jun 2003 06:56:51 -0000 1.28 +++ lib/Autom4te/General.pm 20 Aug 2003 08:25:49 -0000 @@ -52,10 +52,10 @@ # Functions we define and export. my @export_subs = - qw (&catfile &canonpath &contents &debug &error - &file_name_is_absolute &find_configure_ac &find_file - &getopt &mktmpdir &mtime - &uniq &update_file &up_to_date_p &verbose &xsystem &xqx); + qw (&catfile &canonpath &debug &error + &file_name_is_absolute &find_configure_ac + &getopt &mktmpdir + &uniq &up_to_date_p &verbose); # Functions we forward (coming from modules we use). my @export_forward_subs = @@ -266,27 +266,6 @@ } -=item C - -Return the contents of c<$filename>. Exit with diagnostic on failure. - -=cut - -# &contents ($FILENAME) -# --------------------- -# Swallow the contents of file $FILENAME. -sub contents ($) -{ - my ($file) = @_; - verbose "reading $file"; - local $/; # Turn on slurp-mode. - my $f = new Autom4te::XFile "< $file"; - my $contents = $f->getline; - $f->close; - return $contents; -} - - =item C If the debug mode is enabled (C<$debug> and C<$verbose>), report the @@ -380,51 +359,6 @@ } -=item C - -Return the first path for a C<$filename> in the Cs. - -We match exactly the behavior of GNU M4: first look in the current -directory (which includes the case of absolute file names), and, if -the file is not absolute, just fail. Otherwise, look in C<@include>. - -If the file is flagged as optional (ends with C), then return undef -if absent, otherwise exit with error. - -=cut - -# $FILENAME -# find_file ($FILENAME, @INCLUDE) -# ------------------------------- -sub find_file ($@) -{ - my ($filename, @include) = @_; - my $optional = 0; - - $optional = 1 - if $filename =~ s/\?$//; - - return canonpath ($filename) - if -e $filename; - - if (file_name_is_absolute ($filename)) - { - error "no such file or directory: $filename" - unless $optional; - return undef; - } - - foreach my $path (@include) - { - return canonpath (catfile ($path, $filename)) - if -e catfile ($path, $filename); - } - - error "no such file or directory: $filename" - unless $optional; - - return undef; -} =item C @@ -508,30 +442,6 @@ } -=item C - -Return the mtime of C<$file>. Missing files, or C<-> standing for -C or C are ``obsolete'', i.e., as old as possible. - -=cut - -# $MTIME -# MTIME ($FILE) -# ------------- -sub mtime ($) -{ - my ($file) = @_; - - return 0 - if $file eq '-' || ! -f $file; - - my $stat = stat ($file) - or croak "$me: cannot stat $file: $!\n"; - - return $stat->mtime; -} - - =item C Return C<@list> with no duplicates, keeping only the first @@ -557,7 +467,6 @@ return wantarray ? @res : "@res"; } - =item C Is C<$file> more recent than C<@dep>? @@ -586,64 +495,6 @@ } -=item C - -Rename C<$from> as C<$to>, preserving C<$to> timestamp if it has not -changed. Recognize C<$to> = C<-> standing for C. C<$from> is -always removed/renamed. - -=cut - -# &update_file ($FROM, $TO) -# ------------------------- -sub update_file ($$) -{ - my ($from, $to) = @_; - my $SIMPLE_BACKUP_SUFFIX = $ENV{'SIMPLE_BACKUP_SUFFIX'} || '~'; - use File::Compare; - use File::Copy; - - if ($to eq '-') - { - my $in = new IO::File ("$from"); - my $out = new IO::File (">-"); - while ($_ = $in->getline) - { - print $out $_; - } - $in->close; - unlink ($from) - or error "cannot not remove $from: $!"; - return; - } - - if (-f "$to" && compare ("$from", "$to") == 0) - { - # File didn't change, so don't update its mod time. - verbose "`$to' is unchanged"; - unlink ($from) - or error "cannot not remove $from: $!"; - return - } - - if (-f "$to") - { - # Back up and install the new one. - move ("$to", "$to$SIMPLE_BACKUP_SUFFIX") - or error "cannot not backup $to: $!"; - move ("$from", "$to") - or error "cannot not rename $from as $to: $!"; - verbose "`$to' is updated"; - } - else - { - move ("$from", "$to") - or error "cannot not rename $from as $to: $!"; - verbose "`$to' is created"; - } -} - - =item C If the verbose mode is enabled (C<$verbose>), report the C<@message> @@ -705,50 +556,6 @@ error "$command exited abnormally"; } } -} - - -=item C - -Same as C (but in scalar context), but fails on errors. - -=cut - -# xqx ($COMMAND) -# -------------- -sub xqx ($) -{ - my ($command) = @_; - - verbose "running: $command"; - - $! = 0; - my $res = `$command`; - handle_exec_errors $command - if $?; - - return $res; -} - - -=item C - -Same as C, but fails on errors, and reports the C<$command> -in verbose mode. - -=cut - -# xsystem ($COMMAND) -# ------------------ -sub xsystem ($) -{ - my ($command) = @_; - - verbose "running: $command"; - - $! = 0; - handle_exec_errors $command - if system $command; } =back