#!/bin/csh -f

while ( $#argv > 0 )
	if (x"$1:q" =~ x/* && ! -f ."$1:q") then
		echo 'Copying '$1:q
		cp $1:q tmp
		goto proces
	else if ( -f "$1:q") then
		echo 'Skipping '$1:q' is a file'
	else if (x"$1:q" =~ xnews:*) then
		echo 'Skipping '$1:q' is netnews'
	else if (x"$1:q" =~ xtelnet:*) then
		echo 'Skipping '$1:q' is telnet'
	else
		echo 'Fetching '$1:q''
		/afs/cs/usr/bsy/bin/url_fetch $1:q >tmp
proces:
		set dirs = (`echo -n $1:q | tr -c -.:a-zA-Z0-9/_ '_' | tr / ' '`)
		set this = "."
		foreach d (`echo $dirs | sed 's/ [^ ]*$//'`)
			set this = "$this/$d"
			if (! -d "$this") then
				echo '  Creating '$this
				mkdir $this
				if ($status) then
					echo FAILURE at $this
					break
				endif
			endif
		end
		set this = "$this/$dirs[$#dirs]"
		if ( -d $this ) then
			echo DIRECTORY $this already exists
		else if ( -f $this ) then
			echo FILE $this already exists
		else
			echo ' Writing '$this
			mv tmp $this
			
		endif
		rm -f tmp
	endif
	shift
end

