/*--- XFILESPEC opt,string - MS/PCDOS/DOSBOX/Unix/Linux --------------*/
/* Breaks String into Drive:\Path\filespec.ext components */
/* T = "D:\PATH1\PATH2\FILESPEC.EXT" */
/* R = XFILESPEC(OPTION,T) 2005 - Mark McDonald */
/* Option Returns */
/* D D: */
/* P \PATH1\PATH2\ */
/* N FILESPEC.EXT */
/* F FILESPEC */
/* E EXT */
/* H D:\PATH1\PATH2\ */
/* M D:\PATH1\PATH2\FILESPEC */
/* W D: \PATH1\PATH2\ FILESPEC EXT */
/* C D:,\PATH1\PATH2\,FILESPEC,EXT */
/* Uses XTRIML */
/*--------------------------------------------------------------------*/
XFILESPEC: PROCEDURE
PARSE ARG OPT,X
TSLASH = "/" ;/*Unix/Linux */
/* --- Drive Letter Present? (Then DOS/WIN) --*/
IF POS(":",X,1) > 0 THEN
DO
TSLASH = "\" ;/*DOS/Win Slash */
XDRV = LEFT(X,2) ;/*Extract Drive Let */
X = XTRIML(X,2) ;/*Remove Drive Let */
END
/* --- Path Present? ---*/
IF POS(TSLASH,X,1) > 0 THEN
DO
SP = POS(TSLASH,X,1) ;/*1st Slash Pos */
EP = LASTPOS(TSLASH,X) ;/*Last Slash Pos */
IF SP <> EP THEN XPATH = SUBSTR(X,SP,EP-SP+1)
IF SP = EP THEN XPATH = TSLASH
X = XTRIML(X,EP) ;/*Remove Path fr str*/
END
XNAME = X ;/*Get Filespec Only */
SP = POS(".",X,1) ;/*Find Filespec Dot */
IF SP > 0 THEN
DO
XSPEC = LEFT(X,SP-1) ;/*Found Dot Get Name*/
X = XTRIML(X,SP) ;/*Rm Name frm String*/
XEXT = X ;/*Get Filespec .EXT */
END
IF OPT = "D" THEN XR = STRIP(XDRV)
IF OPT = "P" THEN XR = STRIP(XPATH)
IF OPT = "N" THEN XR = STRIP(XNAME)
IF OPT = "F" THEN XR = STRIP(XSPEC)
IF OPT = "E" THEN XR = STRIP(XEXT)
IF OPT = "H" THEN XR = STRIP(XDRV""XPATH)
IF OPT = "M" THEN XR = STRIP(XDRV""XPATH""XSPEC)
IF OPT = "W" THEN XR = STRIP(XDRV" "XPATH" "XSPEC" "XEXT)
IF OPT = "C" THEN XR = STRIP(XDRV","XPATH","XSPEC","XEXT)
RETURN (XR)
/*---------------------------------------------------------------*/
XTRIML: PROCEDURE
PARSE ARG X, N
IF LENGTH(X) - 1 >= N THEN
XR = RIGHT(X,LENGTH(X) - N)
ELSE
XR = X
RETURN (XR)