home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / pushd20.zip / POPD.CMD < prev    next >
OS/2 REXX Batch file  |  1993-05-30  |  2KB  |  64 lines

  1. /* POPD                                                                      */
  2. /* written:  Ken Neighbors  sometime before 13 May 93                        */
  3. /* revised:  Ken Neighbors  30 May 93  +n, comments, bug fixes, beautify     */
  4.  
  5. parse arg Argument rest
  6.  
  7. if ( rest <> '' ) then do
  8.     say 'popd:  Too many arguments.'
  9.     exit 1
  10. end
  11.  
  12. DirStack = value('PUSHD',,'OS2ENVIRONMENT')
  13.  
  14. /*
  15.  * first case: argument is "+n"--delete nth entry from stack
  16.  */
  17. if ( substr(Argument,1,1) == '+' ) then do
  18.     n = substr(Argument,2)
  19.  
  20.     /* check that n is a whole number, greater than zero, less than dirs */
  21.     if ( \datatype(n,'Whole number') | (n < 1) ) then do
  22.     say 'popd: Invalid cyclic parameter'
  23.     exit 3
  24.     end
  25.     NumDirs = words(DirStack)   /* plus one:  current dir */
  26.     if (n > NumDirs) then do
  27.     say 'popd: Directory stack not that deep'
  28.     exit 3
  29.     end
  30.  
  31.     DirStack = delword(DirStack,n,1)
  32.     call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
  33.     CurrentDir = _beaut(directory())
  34.     say CurrentDir DirStack
  35. end
  36. /*
  37.  * second case: no argument--pop top directory
  38.  */
  39. else do
  40.     parse var DirStack NewDir DirStack
  41.     if ( NewDir == '' ) then do
  42.     /* The stack is empty */
  43.     say 'There is no directory to pop.'
  44.     exit 1
  45.     end
  46.     else do
  47.     /* Switch current directory with the one on top of stack, NewDir */
  48.     NewDirVerify = _beaut(directory(NewDir))
  49.     if ( NewDirVerify <> '' ) then do
  50.         call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
  51.         say NewDirVerify DirStack
  52.     end
  53.     else do
  54.         /* could not change to NewDir, so just delete it from stack */
  55.         say insert(NewDir,': No such directory.')
  56.         call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
  57.         CurrentDir = _beaut(directory())
  58.         say CurrentDir DirStack
  59.         exit 2
  60.     end
  61.     end
  62. end
  63. exit 0
  64.