home *** CD-ROM | disk | FTP | other *** search
- package Autodoc::FileSupport;
-
- ###############################################################################
- ###############################################################################
- ##
- ## Written by Adam Swift (c) 1995 by Friday Software and Consulting
- ## All rights reserved.
- ##
- ## This notice may not be removed from this source code.
- ##
- ## This program is included in the MiscKit by permission from the author
- ## and its use is governed by the MiscKit license, found in the file
- ## "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- ## for a list of all applicable permissions and restrictions.
- ##
- ## Because AutoDoc is licensed free of charge, there is no warranty
- ## for the program. Copyright holder, Friday Software and Consulting,
- ## is providing this program "as is" and 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.
- ##
- ###############################################################################
- ###############################################################################
-
- require 5.000;
-
- ##########################
- # load required packages #
- ##########################
- use Exporter;
-
- @ISA = qw(Exporter);
- @EXPORT = qw(file_expandpath
- file_findnewest);
-
- ###########################
- # Set version information #
- ###########################
- $module_version = '$Revision: 1.3 $';
- $module_version =~ s!(\$\w+: | \$)!!g;
- $module_id = '$Id: FileSupport.pm,v 1.3 1995/10/20 22:16:26 aswift Exp $';
- $module_id =~ s!(\$\w+: | \$)!!g;
- $module_name = $module_id;
- $module_name =~ s!^([^\,]+).*$!$1!;
-
-
- ############################################################################
- #
- # Purpose: Module that encapsulates some file actions and tests
- #
- # HISTORY: START
- # $Log: FileSupport.pm,v $
- # Revision 1.3 1995/10/20 22:16:26 aswift
- # Added DevMan style changes Log support
- #
- #
- # HISTORY: END
- ############################################################################
-
-
-
- #############################################################################
- #
- # NAME: module_version
- #
- # ACTION: returns the version number of this module
- #
- # RETURN: the module version
- #
- #############################################################################
- sub module_version
- {
- return $module_version;
- }
-
- sub module_versionstamp
- {
- return "$module_name (rev-$module_version)";
- }
-
- #############################################################################
- #
- # NAME: expand_filepath
- #
- # ACTION: Replace the file path '~[user]' '.' or '..' references
- # with an expanded file path starting with '/'
- #
- # ARGUMENTS: A file path
- #
- # RETURN: The expanded file path
- #
- #############################################################################
- sub file_expandpath
- {
- local ($filepath, $expanddir);
- $filepath = $_[0];
-
- # If the path starts with '/' no expansion is needed.
- return $filepath if ($filepath =~ m!^/!);
-
- # If the path starts with '~' then user HOME from the user ENV
- if (($filepath =~ m!^~$!) || ($filepath =~ m!^~/!)) {
- $filepath =~ s!^~!$ENV{'HOME'}!;
- return $filepath;
- }
-
-
- # Otherwise, get lazy and make the filesystem to expand it for us
- if ($filepath =~ m!^([^/]+)!) {
- $expanddir = $1;
-
- # Check to see if the path is simply a file name (no directories)
- # if so, add a './' and expand from there.
- if (($expanddir eq $filepath) && !(-d $expanddir)) {
- $filepath = "./$filepath";
- $expanddir = ".";
- }
-
- if ($expanddir ne "") {
- open (EXPDIR, "cd $expanddir; pwd |");
- $expanddir = <EXPDIR>;
- close (EXPDIR);
- chop $expanddir if ($expanddir =~ m!\n$!);
-
- # if it is a directory, replace it in $filepath
- if (($expanddir ne "") && (-d $expanddir)) {
- $filepath =~ s!^[^/]+!$expanddir!;
- }
- }
- }
-
- return $filepath;
- }
-
-
- #############################################################################
- #
- # NAME: file_findnewest
- #
- # ACTION: Finds the newest file of all files passed as arguments and
- # returns it (the one with the latest time stamp).
- #
- # ARGUMENTS: Any number of file paths
- #
- # RETURN: The newest file's path
- #
- #############################################################################
- sub file_findnewest
- {
- local ($newest_file, $newest_age, $file, $fileage);
-
- $newest_file = "";
- $newest_age = 0;
-
- foreach $file (@_) {
- if (-r $file) {
- $fileage = -M $file;
- # print "file $file is age $fileage\n";
- if (($newest_age == 0) || ($fileage < $newest_age)) {
- $newest_file = $file;
- $newest_age = $fileage;
- }
- }
- }
- # print "latest file = $newest_file\n";
-
- return $newest_file;
- }
-
-
- 1;
-
-