# $Id: FileNames.pm,v 3.7 1999/09/15 15:40:01 v2kea318 Exp $
# $Log: FileNames.pm,v $
# Revision 3.7  1999/09/15  15:40:01  v2kea318
# We have to double the dirsep string (append it to itself) for windows.
#
# Revision 3.6  1999/09/15  15:17:17  v2kea318
# Use my OSProperties module to define the directory separator string.
#
# Revision 3.5  1999/08/20  16:59:40  v2kea318
# Fixed the regexp in trim_ws.
#
# Revision 3.4  1999/04/02  20:40:35  v2kea318
# Add the export stuff to make certain routines visible outside of the
# module.
#
# Revision 3.3  1999/02/09  16:19:06  v2kea318
# *** empty log message ***
#
# Revision 3.2  1999/01/08  17:38:45  v2kea318
# Made the path extraction more compact by avoiding the loop.  A single
# regex is now used and $& is returned.
#
# Revision 3.1  1999/01/08  17:32:27  v2kea318
# Got rid of the intermediate parsing routine.  Use each of the three
# functions with more compact regex.
#
# Revision 2.5  1998/10/26  19:19:59  v2kea318
# On parse_file_name(), operate on a local $_ variable.
#
# Revision 2.4  1998/01/06  12:16:02  saaron
# Made the code extracting the extension string a little simpler.
#
# Revision 2.3  1997/12/09 17:01:22  saaron
# Store the three file path parts as variables common to the module,
# rather than as locals to be returned.  This cuts down on copying.
#
# Revision 2.2  1997/12/09 16:59:45  saaron
# Handle the case where there is no extension properly.
#
# Revision 2.1  1997/12/09 16:29:06  saaron
# Redesigned the package by adding a generic parsing routine which
# extracts everything, and then having each function just return the
# appropriate string.  It now looks pretty much like the standard
# Basename.pm module.
#
# Revision 1.3  1997/12/09 15:44:11  saaron
# *** empty log message ***
#
# Revision 1.2  1997/12/03 12:54:16  saaron
# Work on locally defined variables rather than $_.
#
# Revision 1.1  1997/12/01 10:56:09  saaron
# Initial revision
#
#***************************************************************************
#
# Functions for parsing file name paths and extracting various parts.
#
#***************************************************************************

# package name
package FileNames;

# OO stuff to make routine names visible.
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(extension path basename);

# Other libraries.
use OSProperties;

# Define the directory separator character.  This is '/' for UNIX.
my $dirsep = $OSProperties::os_char_table{set_os()}->{dir_sep};
$dirsep = $dirsep . $dirsep if ($^O eq 'MSWin32');

#***************************************************************************

sub trim_ws(\$) {  # trim away white space
  my $s = shift();
  $$s =~ s/^\s*(.*?)\s*$/$1/o;
}

#***************************************************************************

sub extension($) {    # Determine the file extension.
  local $_ = shift();
  trim_ws($_);
  m!\.([^$dirsep\.]*)$!o;
  return $1 || '';
}

#***************************************************************************

sub path ($) {        # Extract the path.
  local $_ = shift();
  trim_ws($_);
  m!^$dirsep?([^$dirsep]+$dirsep)*!o;
  return $& || ".$dirsep";
}

#***************************************************************************

sub basename ($) {    # Extract the basename of the file.
  local $_ = shift();
  trim_ws($_);
  m!([^$dirsep]*)$!o;
  return $1;
}

#***************************************************************************

1;

