/*********************************************/ /* popd ... pop directory from 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 . /* Set up */ CALL init /* Read from pushdir file, change directory, and rewrite pushdir file */ CALL popdir /* 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 popdir: PROCEDURE EXPOSE pushDirFile. /* 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 /* Write the file back out. */ CALL writePushDirFile /* Now change directories */ CALL Directory(pushDirFile.popDir) /* 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 in first line */ pushDirFile.popDir = LineIn(pushDirFile.name) /* Read remaining lines into buffer, offset by one line */ DO i = 1 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 /* Empty? Delete the file representing the list of pushed dirs. */ IF pushDirFile.0 = 0 THEN DO /* Close list and delete */ CALL Stream pushDirFile.name, 'C', 'CLOSE' CALL SysFileDelete(pushDirFile.name) END /* Not empty? Push directories back to list. */ ELSE DO DO i = 1 TO pushDirFile.0 CALL LineOut pushDirFile.name, pushDirFile.i END /* Close list */ CALL Stream pushDirFile.name, 'C', 'CLOSE' END /* 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 */