#!/bin/csh -f
#
# fixRelPathsDown
#
# x-kernel v3.2
#
# Copyright (c) 1991  Arizona Board of Regents
#
# $Revision: 1.2 $
# $Date: 1991/10/09 18:46:44 $
# 
# Takes a list of filenames on the input stream and
# rewrites each name relative to a directory below it.  The number of
# levels below is specified on the command line.
#
# E.g., fixRelPathsDown 2  will rewrite non-absolute pathnames 
# such as foo1/foo2 as ../../foo1/foo2.

set numDown = $1
set pfx=""
while ($numDown) 
	set pfx=$pfx"../"
	@ numDown -= 1
end

# Three cases:
#	/foo	-- don't rewrite
#	./foo	-- rewrite as ../foo
#	foo 	-- rewrite as ../foo

awk -F/ ' /^\//	    	{ print $0; next }		\
	  /^.\// 	{ print dir""substr($0, 3); next }	\
	          	{ print dir""$0 }		\
	' dir=$pfx -
		

