home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / PATHSTAK.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-31  |  3KB  |  74 lines

  1. @echo off
  2. REM ************************************************************************
  3. REM *** PathStak.cmd - Utility to save or restore a path location using  ***
  4. REM *** ver.1          environment variables to remember.  The paths are ***
  5. REM ***                saved in the PATH_STACK environment variable.     ***
  6. REM ***                Return ERRORLEVEL 0 for success and ERRORLEVEL 1  ***
  7. REM ***                if there was a problem.  No error on restore or   ***
  8. REM ***                forget if there is nothing saved.                 ***
  9. REM ************************************************************************
  10. CALL CEnviSet.cmd %0.cmd %1 %2
  11. GOTO CENVI_EXIT
  12.  
  13. main(argc,argv)
  14. {
  15.    if ( 2 != argc ) {
  16.       Instructions();
  17.       Success = False;
  18.    } else {
  19.       Success = True;
  20.       command = argv[1], len = strlen(command);
  21.       // determine how many paths are currently saved
  22.       PathStackDepth = defined(PATH_STACK) ? (GetArraySpan(PATH_STACK) + 1) : 0 ;
  23.       if ( !strnicmp("PUSH",command,len) ) {
  24.          PATH_STACK[PathStackDepth] = FullPath(".") // current directory
  25.       } else if ( !strnicmp("POP",command,len) ) {
  26.          if ( 0 != PathStackDepth ) {
  27.             OldPath = PATH_STACK[PathStackDepth-1];
  28.             // set PATHSTAK_SET_PATH to be the new environment to change to
  29.             sprintf(PATHSTAK_SET_PATH,"cd %s",OldPath)
  30.             // set PATHSTAK_SET_DRIVE to be the new drive letter
  31.             strcpy(PATHSTAK_SET_DRIVE,OldPath)
  32.             PATHSTAK_SET_DRIVE[2] = 0; // cut down to drive:
  33.             // remove this final element from the PATH_STACK array
  34.             if ( 1 == PathStackDepth ) {
  35.                undefine(PATH_STACK);
  36.             } else {
  37.                SetArraySpan(PATH_STACK,PathStackDepth - 2);
  38.             }
  39.          }
  40.       } else if ( !strnicmp("FORGET",command,len) ) {
  41.          undefine(PATH_STACK);
  42.       } else {
  43.          Instructions();
  44.          Success = False;
  45.       }
  46.    }
  47.    return( Success ? 0 : 1 );
  48. }
  49.  
  50. Instructions()
  51. {
  52.    printf("\a\n")
  53.    printf("PathStak.cmd - Save or restore directory paths.\n")
  54.    printf("\n")
  55.    printf("SYNTAX: PathStak PUSH | POP | FORGET\n")
  56.    printf("\n")
  57.    printf("Where:  PUSH    Save the current directory as most recent.\n")
  58.    printf("        POP     Return to the most recently saved directory.\n")
  59.    printf("        FORGET  Forget all saved directories.\n")
  60.    printf("\n")
  61. }
  62.  
  63.  
  64. :CENVI_EXIT
  65. REM ****************************************************************************
  66. REM *** The previous code set PATHSTAK_SET_DRIVE to the new drive letter and ***
  67. REM *** PATHSTAK_SET_PATH to the new path, and so set those variables and    ***
  68. REM *** then remove the environment variables.                               ***
  69. REM ****************************************************************************
  70. %PATHSTAK_SET_PATH%
  71. set PATHSTAK_SET_PATH=
  72. %PATHSTAK_SET_DRIVE%
  73. set PATHSTAK_SET_DRIVE=
  74.