danielwong@zgov05.dec.com (Daniel Wong @ZGO (PDE/Test)) (02/04/88)
Since the following resulted from a direct attempt to get the default
directory on my prompt and then finding that it's not much fun if you've
got long directory names and deep directory trees; I'm posting this
although I'm sure there are scores of programs like it out there.
Call it something like cd.com and define cd in your login.com to be
@cd.com wherever it may be.
<DANIEL>
----------------------cut---------------here------------------------------------
$!Hacked by Daniel Wong Su Chun
$!30 Nov 1987
$if p1 .eqs. "\" then goto goroot
$if p1 .eqs. "" then goto lp6
$nexdir="["+"''p1'"+"]"
$strlen=f$length(nexdir)
$lp0:
$ x=f$locate("..",nexdir)
$ if x .eq. strlen then goto lp1
$ sub=f$extract(0,x,nexdir)
$ nexdir=sub+"-"+f$extract(x+2,strlen-x-1,nexdir)
$ strlen=f$length(nexdir)
$ goto lp0
$lp1:
$ x=f$locate("-\-",nexdir)
$ if x .eq. strlen then goto lp3
$ sub=f$extract(0,x,nexdir)
$ nexdir=sub+"-"+f$extract(x+2,strlen-x-1,nexdir)
$ strlen=f$length(nexdir)
$ goto lp1
$lp3:
$ x=f$locate("\",nexdir)
$ if x .eq. strlen then goto lp5
$ sub=f$extract(0,x,nexdir)
$ nexdir=sub+"."+f$extract(x+1,strlen-x-1,nexdir)
$ goto lp3
$lp5:
$set default 'nexdir'
$goto lp6
$goroot:
$set default sys$login
$lp6:
$curdir=f$directory()
$strlen=f$length(curdir)
$lp7:
$ x=f$locate(".",curdir)
$ if x .eq. strlen then goto lp8
$ sub=f$extract(0,x,curdir)
$ curdir=sub+"\"+f$extract(x+1,strlen-x-1,curdir)
$ goto lp7
$lp8:
$curdir=f$extract(1,strlen-2,curdir)
$curdir="\"+curdir
$write sys$output curdir
$exit
----------------------cut---------------here------------------------------------