C-------------------------------------------------------------------C
C Save stacks, etc. in symbols DM$SYM1 and DM$SYM2.                 C
C-------------------------------------------------------------------C
       Subroutine Save_Stack(Who)
       Implicit Integer*4 (A - Z)
       Character*250 Symbol
       Character*1 Who
       Include 'common.include'
C-------------------------------------------------------------------C
       Symbol(1:1) = Who ! signal this as not 1st time into dm
       Encode(5, 2000, Symbol(5:9)) Cursorline
       Encode(5, 2000, Symbol(10:14)) TopLine
       Encode(5, 2000, Symbol(15:19)) StkIndex
       Encode(5, 2000, Symbol(20:24)) Srchsize
       Encode(5, 2000, Symbol(25:29)) Fast
       Encode(5, 2000, Symbol(30:34)) Forward
       Encode(80, 2001, Symbol(71:150)) Search
       Stat = Lib$Set_Symbol('DM$SYM1', Symbol)
       If (.not. Stat) Call Lib$Stop(%Val(Stat))
       J = 1
       Do I = 1, 15
         Encode(1, 2002, Symbol(J:J)) FStack(I)
         Encode(1, 2002, Symbol(J+1:J+1)) FastStack(I)
         Encode(5, 2000, Symbol(J+2:J+6)) Cstack(I)
         Encode(5, 2000, Symbol(J+7:J+11)) TStack(I)
         J = J + 12
       End Do
2000   Format(5I5)
2001   Format(A80)
2002   Format(I1)
       Stat = Lib$Set_Symbol('DM$SYM2', Symbol)
       If (.not. Stat) Call Lib$Stop(%Val(Stat))
       Return
       End
C-------------------------------------------------------------------C
C Pop the stack (Go to the previous directory)                      C
C-------------------------------------------------------------------C
       Subroutine POPSTACK
       Implicit Integer*4 (A - Z)
       Character*128 Dname2,RealName2,PreName2
       Character*40 Tempxx
       Character*1 C
       Include 'common.include'
C-------------------------------------------------------------------C
       Pur = 1
       Call GetName(Ld(2), TempName, Type)
       TempName = PreName
       Dir = 1
       Dname2 = Dname
       PreName2 = PreName
       RealName2 = Realname
       Call Sys$SetdDir(TempName,%Val(0),%Val(0)) !New Default
       Call Sys$SetdDir(%Val(0),%Val(0),DName)   !Get Default dir
       Call RealDir(Dname, RealName) ! [aaa.bbb] --> [aaa]bbb.DIR
       Call PreDir(RealName, PreName)
       If (StkIndex .GT. 0) then 
         SaveFast = Fast
         Fast = FastStack(StkIndex) ! GETLD needs this info.
       Else
         SaveFast = 1
         Fast = 1
       End If
       Temp = IncluCount
       IncluCount = 0
       Call GetLd(RealName, Err)
       If (Err .EQ. 1) then 
         IncluCount = Temp
         Fast = SaveFast
         Dname = Dname2
         PreName = PreName2
         Realname = Realname2
         Call Sys$SetdDir(Dname, %Val(0), %Val(0)) ! old default
       Else
         If (StkIndex .GT. 0) then 
           TopLine = TStack(StkIndex)
           Cursorline = CStack(StkIndex)
           Forward = FStack(StkIndex)
           Fast = FastStack(StkIndex)
           Downlast = Forward
           StkIndex = StkIndex - 1
         Else
           TopLine = 1
           CursorLine = FirstUsed
           Forward = 1
           DownLast = 1
         End If
       End If
       Call Write24
       Return
       End
