sub split( string p1, dev, dir, word colon, bracket )
!	Written by Michael W. Wheeler (mww@tntech.bitnet)
!	VAX Basic V3.1
!	Copyright (c) by Michael W. Wheeler, September 1987
!	This program is intended for Public Domain, and may not be sold or
!	marketed in any form without the permision and written consent
!	from the author Michael W. Wheeler.  I retain all copyrights to
!	this program, in either the original or modified forms, and no
!	violation, deletion, or change of the copyright notice is
!	allowed.  Futhermore, I will have no liability or responsibilty
!	to any user with respect to loss or damage caused directly or
!	indirectly by this program.

external long function lib$sys_trnlog
declare long	return_status
%include "$ssdef" %from %library "sys$library:basic$starlet.tlb"

if colon = len(p1) then ! If it ends with a colon then
    dev = mid(p1, 0%, colon - 1%) ! Strip off colon
    return_status = lib$sys_trnlog( dev by desc,, dev by desc,,, ) ! Try to translate if as if it were a logical name.
    if return_status = ss$_notran then
	! If it didn't traslate then put the colon back on it.
	dev = dev + ":"
    else
	! If it translates into a rooted directory or a device name then
	! put it back like it was.
	if (instr(0%, dev, ".]")) or (instr(0%, dev, ":") = len(dev)) then
	    dev = p1
	end if
    end if
else
    ! Get the device part of the parameter.
    dev = mid(p1, 0%, colon)
end if
if bracket then
    ! Get the directory part of the parameter.
    dir = mid(p1, bracket, len(p1) - bracket + 1%)
else
    bracket = instr(0%, dev, "[") ! Locate the left bracket
    if bracket then
    	dir = mid(dev, bracket, len(dev) - bracket + 1%) ! get direcotry part of the parameter.
    	colon = instr(0%, dev, ":")
    	if colon then
    	    dev = mid(dev, 0%, colon) ! Get the device part of the parameter.
    	end if
    end if
end if
subend
