[comp.os.vms] example CD command which sets DCL prompt

GRANROTH%IOWASP.SPAN@STAR.STANFORD.EDU (Larry Granroth (04/06/88)

I'm sure many CD commands have been written for VMS, but since
seeley@dalcsug.UUCP posted a recent query about setting the DCL
prompt to show the current directory, I thought I'd volunteer my
own CD command procedure which also sets the prompt.  It's not
exactly what he asked for, but hey, it's free.

GRANROTH%IOWASP.SPAN@STAR.STANFORD.EDU

$ !----------------------------------------------------------------------
$ !
$ !	CD_VMS utility written by L. Granroth  02-03-87
$ !	to translate an MS-DOS CD command to a VMS SET DEFAULT.
$ !	Define the following foreign command in your LOGIN.COM:
$ !	$ CD	 :== @DISK$DAG:[GRANROTH]CD_VMS
$ !	(substitute your own device and directory name above)
$ !
$ !----------------------------------------------------------------------
$	if (p1 .eqs. ""  ) then goto setprompt
$	branch = "*"
$	path = f$trnlnm (p1)
$	if (path .nes. "") then goto verify
$	path = p1
$	if (p1 .eqs. "..") then path = "[-]"
$	if (p1 .eqs. "\" ) then path = f$trnlnm ("sys$login")
$	length = f$length (path)
$	if (f$locate ("[", path) .nes. length) then goto verify
$	if (f$locate ("<", path) .nes. length) then goto verify
$	if (f$extract (0, 2, path) .eqs. "..") then -
	  path = "-" + f$extract (2, length-2, path)
$	length = f$length (path)
$	device = ""
$	if (f$locate (":", path) .eqs. length) then goto xlate
$	index = f$locate ("\", path)
$	device = f$extract (0, index, path)
$	length = length-index
$	path  = f$extract (index, length, path)
$ xlate:
$	n = 0
$	if (path .eqs. "") then goto gotvms
$	vms_path = "[."
$	if (f$extract (0, 1, path) .nes. "\") then goto subst
$	vms_path = "["
$	length = length-1
$	path = f$extract (1, length, path)
$ subst:
$	part = f$element (n, "\", path)
$	if (part .eqs. "\") then goto gotvms
$	if (n .eq. 0) then vms_path = vms_path+part
$	if (n .ne. 0) then vms_path = vms_path+"."+part
$	branch = part
$	n = n+1
$	goto subst
$ gotvms:
$	if (n .eq. 0) then path = device
$	if (n .ne. 0) then path = device+vms_path+"]"
$ verify:
$	if (p1 .eqs. "..") then goto setdef
$	index = f$locate ("]", path)
$	if (index .eq. f$length (path)) then goto setdef
$	dirfile = f$extract (0, index, path) + ".-]''branch'.dir"
$	if (f$search (dirfile) .eqs. "") then goto badpath
$ setdef:
$	set def 'path'
$ setprompt:
$	path = f$directory ()
$	prompt = f$extract (1, f$length (path)-2, path) + ">"
$	set prompt = "''prompt'"
$	exit
$ badpath:
$	write sys$error "Bad path:  ''p1'"
$	exit