#!/u3/thesis/clipper/pl/perl
# A simple subroutine to get the absolute path when two paths are
# merged. Written by Khun Yee Fung (clipper@csd.uwo.ca)
# Copyright 1990 Khun Yee Fung
# See the end of the program for warranty information

sub pathname {
  local($path1) = $_[0];
  local($path2) = $_[1];
  local($arg, @path);
  local($num) = 0;

  if ($path2 eq /^~/) {
    $path2 = $ENV{'HOME'} . $path2;
  }
  if ($path2 =~ m|^~([^/]*)|) {
    if ($1 == "") {
      $path2 = $ENV{'HOME'} . $path2;
    }
    else {
      @ent = getpwnam($1) || (@ent = (""));
      $path2 = $ent[7] . $path2;
    }
  } 
  if ($path2 !~ m|^/|) {
    $path2 = $path1 . "/" . $path2;
  }
  local(@paths) = split(m|/|, $path2);
  foreach $arg (@paths) {
    ($arg =~ /^\.\.$/) && ($num--, next);
    ($arg =~ /^\.$/) && next;
    ($arg eq "") && next;
    $path[$num] = $arg;
    $num++;
  }
  $#path = $num - 1;
  $path1 = "";
  foreach $arg (@path) {
    $path1 = $path1 . $arg . "/";
  }
  chop($path1);
  $path1 = "/" . $path1 if ($path1 !~ "^/");
  $path1;
}
1;

# Copyright 1990 Khun Yee Fung <clipper@csd.uwo.ca>
#
# Permission to use, copy, modify, and distribute, this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of the copyright holders be used in
# advertising or publicity pertaining to distribution of the software with
# specific, written prior permission, and that no fee is charged for further
# distribution of this software, or any modifications thereof.  The copyright
# holder make no representations about the suitability of this software for
# any purpose.  It is provided "as is" without express or implied warranty.
#
# THE COPYRIGHT HOLDER DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA, PROFITS, QPA OR GPA, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
