home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mutt / package / dir.mut < prev    next >
Text File  |  1995-01-14  |  4KB  |  138 lines

  1.   ;; dir.mut : directory stack stuff for UNIX versions of ME
  2.   ;; pgms defined:
  3.   ;; - cd   :  Change the current directory.
  4.   ;; - dirs :  Show the contents of the directory stack.  The top (or left
  5.   ;;     most) entry is the current directory, next is the directory you
  6.   ;;     left to get to the current directory.
  7.   ;; - pwd  :  Show the current directory.
  8.   ;; - pu   :  Change the current directory, using the stack to save the
  9.   ;;     changes.
  10.   ;;     (pu directory) pushes the current directory on the stack and sets
  11.   ;;       the current directory to directory.
  12.   ;;     (pu "") swaps the top 2 entries on the stack.
  13.   ;;     (pu +n) swaps the top of the stack with the nth stack item.  n
  14.   ;;       starts at zero.
  15.   ;;     (pu +)  Run dirs.
  16.   ;; - po discards the top entry on the stack and sets the current
  17.   ;;     directory to the new top of stack.
  18.   ;; C Durland 10/87 5/88 2/93        Public Domain
  19.  
  20. (include me.mh)
  21.  
  22. (const MAX-STACK-SIZE 20)  ;; the max number of entries on the directory stack
  23.  
  24. (small-int num-stack-entries)
  25.  
  26. (defun
  27.   init-dirstack MAIN { (clear-stack) (push (sub~ (current-directory))) }
  28.   cd
  29.   {
  30.     (if (current-directory (complete CC_FNAME "Change directory to: "))
  31.       {
  32.     (pop)    ;; nuke the first entry to make room for this one
  33.     (msg "moved to " (push (sub~ (current-directory))))
  34.     TRUE
  35.       }
  36.       { (msg "Not a valid directory") FALSE })
  37.   }
  38.   pwd { (msg "Current directory: " (sub~ (current-directory))) }
  39.   pu        ;; push directory
  40.   {
  41.     (string name name2)
  42.     (int n)
  43.  
  44.     (name (complete CC_FNAME "Push directory to: "))
  45.     (if (== name "")    ; swap top 2 items on stack
  46.     {
  47.       (if (< num-stack-entries 2)
  48.     { (msg "Directory stack too small to swap") FALSE (done) })
  49.       (name (pop)) (name2 (pop))
  50.       (push name)  (push name2)
  51.  
  52.       (cd name2)
  53.       (done)
  54.     })
  55.  
  56.     (if (== name "+") { (query-dir-stack)(done) })    ;; query dir stack
  57.  
  58.     (if (== (extract-element name 0) "+")   ; +n => move (n+1)th entry to top
  59.     {
  60.       (n (convert-to NUMBER (extract-elements name 1 10000)))
  61.       (if (>= n num-stack-entries)
  62.     { (msg "Only got " num-stack-entries " entries")(done) })
  63.       (name (popn n))
  64.       (push name)    ;; push a dummy that is nuked by (cd)
  65.  
  66.       (cd name)
  67.       (done)
  68.     })
  69.     (if (current-directory name)    ;; directory exists
  70.       {
  71.     (if (>= num-stack-entries MAX-STACK-SIZE)    ;; shrink stack
  72.         (popn (- num-stack-entries 1)))
  73.         (msg "Moved to " (push (sub~ (current-directory))))
  74.     TRUE
  75.       }
  76.       { (msg "Not a valid directory") FALSE })
  77.   }
  78.   po        ;; pop directory
  79.   {
  80.     (if (< num-stack-entries 2) { (msg "Directory stack empty") FALSE (done) })
  81.     (pop)
  82.     (cd (peek 0))
  83.   }
  84. )
  85.  
  86.  
  87. (defun
  88.   MAIN
  89.   {
  90.     (require "menu-box" "popup")        ;; for (dirs)
  91.   }
  92.   dirs { (query-dir-stack) }
  93.   query-dir-stack HIDDEN
  94.   {
  95.     (int j)
  96.  
  97.     (query-menu 2
  98.       {{ (if (< 2 (arg 0)) (pu (concat "+" (- (arg 0) 2)))) }}
  99.       ">Directory Stack"
  100.       "-"
  101. ;;;!!!!!!!!  Gack - bug around with (extract-element) and objects being
  102. ;;; GC'd in the local pool
  103. ;      (for (j 0) (< j num-stack-entries)(+= j 1) (push-arg (peek j)))
  104.       (for (j 0) (< j num-stack-entries)(+= j 1) (push-arg (concat (peek j))))
  105.     )
  106.   }
  107. )
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;; Stack Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112.  
  113. (list dir-stack)
  114.  
  115. (defun
  116.   clear-stack HIDDEN
  117.   {
  118.     (while (!= 0 num-stack-entries) (pop))
  119.   }
  120.   push (string dir) HIDDEN        ;; returns name
  121.   {
  122.     (insert-object dir-stack -1 dir)
  123.     (num-stack-entries (length-of dir-stack))
  124.     dir
  125.   }
  126.   peek (int n) HIDDEN { (extract-element dir-stack n) }
  127.   popn (int n) HIDDEN
  128.   {
  129.     (string dir)
  130.  
  131.     (dir (extract-element dir-stack n))
  132.     (remove-elements dir-stack n 1)
  133.     (num-stack-entries (length-of dir-stack))
  134.     dir
  135.   }
  136.   pop HIDDEN { (popn 0) }
  137. )
  138.