/*********************************************/ /* pushd ... push directory on dir stack. */ /* jack j. woehr jax@well.com jwoehr@ibm.net */ /* http://www.well.com/user/jax/rcfb */ /* P.O. Box 51, Golden, Colorado 80402-0051 */ /*********************************************/ /* Copyright *C* 1998, All Rights Reserved. */ /* */ /* This Program is Free */ /* Softwoehr */ /* */ /* Permission to distribute this Softwoehr */ /* with copyright notice attached is granted.*/ /* */ /* Permission to modify for personal use at */ /* at home or for your personal use on the */ /* job is granted, but you may not publicly */ /* make available modified versions of this */ /* program without asking and getting the */ /* permission of the author, Jack Woehr. */ /* */ /* The permission will usually be granted if */ /* granted reciprocally by you for the mods. */ /* */ /* THERE IS NO GUARANTEE, NO WARRANTY AT ALL */ /*********************************************/ PARSE SOURCE src.hst src.cmd src.pgm src.lib src.usr PARSE ARG path /* Set up */ CALL init /* Where are we? */ curDir = Directory() /* Check arg */ IF path = '' THEN path = curDir /* Test if it is a directory. */ CALL SysFileTree path, pathstem, 'D' /* Did syscall succeed? */ IF RESULT = 2 THEN CALL exitOnError 2 "Out of memory." /* Is it a dir */ IF pathstem.0 = 0 THEN CALL exitOnError 1 path "is not a directory." /* Write to pushdir file and change directory */ CALL pushdir path curdir /* Done */ SIGNAL bye init: /* Init app */ CALL RxFuncAdd "SysLoadFuncs","RexxUtil","SysLoadFuncs" CALL SysLoadFuncs pushDirFile.0 = 0 pushDirFile.name = Strip(Value(PUSHFILE ,, 'OS2ENVIRONMENT'),'BOTH') IF pushDirFile.name = '' THEN CALL exitOnError 8, "You must first set the environment variable PUSHFILE to a valid filename." myRC = 0 RETURN pushdir: PROCEDURE EXPOSE pushDirFile. PARSE ARG path curdir /* See if pushdir data file already exists */ CALL SysFileTree pushDirFile.name, fileExists, 'F' /* If it does, slurp its lines */ IF fileExists.0 = 1 THEN CALL LoadPushDirFile /* Add a leading line, the current directory. */ pushDirFile.1 = curdir /* Write the file back out. */ CALL writePushDirFile /* Now change directories */ CALL Directory(path) /* Done */ RETURN 'OK' loadPushDirFile: PROCEDURE EXPOSE pushDirFile. /* Open the list of directories pushed */ CALL Stream pushDirFile.name, 'C', 'OPEN READ' IF RESULT \= 'READY:' THEN CALL exitOnError 9 "Couldn't read pushdir file" pushDirFile.name /* Read lines into buffer, offset by one line */ DO i = 2 WHILE LINES(pushDirFile.name) pushDirFile.i = LineIn(pushDirFile.name) pushDirFile.0 = i END /* Close list */ CALL Stream pushDirFile.name, 'C', 'CLOSE' /* Done */ RETURN 'OK' writePushDirFile: PROCEDURE EXPOSE pushDirFile. /* Overwrite the list of directories pushed */ CALL Stream pushDirFile.name, 'C', 'OPEN WRITE REPLACE' IF RESULT \= 'READY:' THEN CALL exitOnError 9 "Couldn't write pushdir file" pushDirFile.name /* If we never read any in, we still have one, the new directory to be pushed */ IF pushDirFile.0 = 0 THEN pushDirFile.0 = 1 /* Push directories back to list */ DO i = 1 TO pushDirFile.0 CALL LineOut pushDirFile.name, pushDirFile.i END /* Close list */ CALL Stream pushDirFile.name, 'C', 'CLOSE' /* Done */ RETURN 'OK' exitOnError: /* Leave program */ PROCEDURE PARSE ARG code message SAY message myRC = code bye: /* Clean up */ CALL SysDropFuncs end: /* All Done */ EXIT myRC /* End of program */