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 >
Wrap
Text File
|
1995-01-14
|
4KB
|
138 lines
;; dir.mut : directory stack stuff for UNIX versions of ME
;; pgms defined:
;; - cd : Change the current directory.
;; - dirs : Show the contents of the directory stack. The top (or left
;; most) entry is the current directory, next is the directory you
;; left to get to the current directory.
;; - pwd : Show the current directory.
;; - pu : Change the current directory, using the stack to save the
;; changes.
;; (pu directory) pushes the current directory on the stack and sets
;; the current directory to directory.
;; (pu "") swaps the top 2 entries on the stack.
;; (pu +n) swaps the top of the stack with the nth stack item. n
;; starts at zero.
;; (pu +) Run dirs.
;; - po discards the top entry on the stack and sets the current
;; directory to the new top of stack.
;; C Durland 10/87 5/88 2/93 Public Domain
(include me.mh)
(const MAX-STACK-SIZE 20) ;; the max number of entries on the directory stack
(small-int num-stack-entries)
(defun
init-dirstack MAIN { (clear-stack) (push (sub~ (current-directory))) }
cd
{
(if (current-directory (complete CC_FNAME "Change directory to: "))
{
(pop) ;; nuke the first entry to make room for this one
(msg "moved to " (push (sub~ (current-directory))))
TRUE
}
{ (msg "Not a valid directory") FALSE })
}
pwd { (msg "Current directory: " (sub~ (current-directory))) }
pu ;; push directory
{
(string name name2)
(int n)
(name (complete CC_FNAME "Push directory to: "))
(if (== name "") ; swap top 2 items on stack
{
(if (< num-stack-entries 2)
{ (msg "Directory stack too small to swap") FALSE (done) })
(name (pop)) (name2 (pop))
(push name) (push name2)
(cd name2)
(done)
})
(if (== name "+") { (query-dir-stack)(done) }) ;; query dir stack
(if (== (extract-element name 0) "+") ; +n => move (n+1)th entry to top
{
(n (convert-to NUMBER (extract-elements name 1 10000)))
(if (>= n num-stack-entries)
{ (msg "Only got " num-stack-entries " entries")(done) })
(name (popn n))
(push name) ;; push a dummy that is nuked by (cd)
(cd name)
(done)
})
(if (current-directory name) ;; directory exists
{
(if (>= num-stack-entries MAX-STACK-SIZE) ;; shrink stack
(popn (- num-stack-entries 1)))
(msg "Moved to " (push (sub~ (current-directory))))
TRUE
}
{ (msg "Not a valid directory") FALSE })
}
po ;; pop directory
{
(if (< num-stack-entries 2) { (msg "Directory stack empty") FALSE (done) })
(pop)
(cd (peek 0))
}
)
(defun
MAIN
{
(require "menu-box" "popup") ;; for (dirs)
}
dirs { (query-dir-stack) }
query-dir-stack HIDDEN
{
(int j)
(query-menu 2
{{ (if (< 2 (arg 0)) (pu (concat "+" (- (arg 0) 2)))) }}
">Directory Stack"
"-"
;;;!!!!!!!! Gack - bug around with (extract-element) and objects being
;;; GC'd in the local pool
; (for (j 0) (< j num-stack-entries)(+= j 1) (push-arg (peek j)))
(for (j 0) (< j num-stack-entries)(+= j 1) (push-arg (concat (peek j))))
)
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; Stack Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(list dir-stack)
(defun
clear-stack HIDDEN
{
(while (!= 0 num-stack-entries) (pop))
}
push (string dir) HIDDEN ;; returns name
{
(insert-object dir-stack -1 dir)
(num-stack-entries (length-of dir-stack))
dir
}
peek (int n) HIDDEN { (extract-element dir-stack n) }
popn (int n) HIDDEN
{
(string dir)
(dir (extract-element dir-stack n))
(remove-elements dir-stack n 1)
(num-stack-entries (length-of dir-stack))
dir
}
pop HIDDEN { (popn 0) }
)