home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
j6217.zip
/
j.ini
< prev
Wrap
Lisp/Scheme
|
1996-02-17
|
20KB
|
532 lines
; -*- mode:emacs-lisp;comment-column:48 -*-
(global-set-key 0 #\q '(kill-j))
(calc-screen-size)
;(spawn P_WAIT '("mode.com" "100,40")) (calc-screen-size)
;
; Define variables
; ================
;
(setq back-top-margin 2)
(setq back-bottom-margin 1)
(setq back-side-margin 1)
(setq default-sort-type ST_NAME)
(setq dialog-attribute (| (<< C_BLUE 4) C_LWHITE))
(setq selector-active-item-attribute (| (<< C_WHITE 4) C_LYELLOW))
(setq selector-item-attribute (| (<< C_WHITE 4) C_BLACK))
;
; Define functions
; ================
;
(defun hidden-file-p (fname atr) ; reserved name.
(or (!= 0 (& atr A_HIDDEN))
(string-tail= fname "~")
(and (= #\. (char fname 0)) (not (string= ".." fname)))))
(defun decide-file-color (fname atr) ; reserved name.
(let ((fore C_LWHITE) (back C_BLACK))
(cond ((!= 0 (& atr A_RONLY)) (setq fore C_LYELLOW))
((!= 0 (& atr A_DIR)) (setq fore C_LGREEN))
((archive-p fname) (setq fore C_LCYAN))
((string-tail= fname ".exe" ".com" ".bat" ".cmd") (setq fore C_LMAGENTA))
((hidden-file-p fname atr) (setq fore C_WHITE))
((string= fname "core") (setq fore C_LRED)))
(cons fore back)))
(defun archive-p (fname) ; reserved name.
(string-tail= fname ".lzh" ".zip"))
(defun redraw-all () ; reserved name.
(window-clear 2)
(redraw 0)
(redraw 1)
(window-set-attribute 2 (| (<< C_GREEN 4) C_LWHITE))
(window-print 2 0 0 "==== " (subseq (get-version) 0 17) " ====")
(window-set-attribute 2 (| (<< C_BLACK 4) C_LWHITE)))
(defun reload-redraw ()
(reload 0)
(reload 1)
(redraw-all))
(defun toggle-display-all-files ()
(toggle-display-all-flag)
(reload)
(redraw))
(defun go-root ()
(go (subseq (get-this-path) 0 3)))
(defun go-parent ()
(and (< 3 (length (get-this-path)))
(go (omit-period (concat (add-last-sep (get-this-path)) "..")))))
(defun go-drive (drive)
(go (getcwd1 drive)))
(defun mint-arrow-left ()
(if (= 0 (get-active-window)) (go-parent)
(other-window)))
(defun mint-arrow-right ()
(if (= 1 (get-active-window)) (go-parent)
(other-window)))
(defun select-all-files ()
(let ((i 0) (fl t))
(clear-select)
(while fl
(setq fl (get-nth-file-name-attribute i))
(and fl
(= 0 (& A_DIR (second fl)))
(select i))
(setq i (1+ i)))))
(defun select-all ()
(let ((i 0) (fl t))
(clear-select)
(while fl
(setq fl (get-nth-file-name i))
(and fl
(or (string= (basename fl) "..")
(select i)))
(setq i (1+ i)))))
(defun rename-copy (src destdir)
(let ((p (center-position 50 4)) w ret (n (basename src)) c r st (job t))
(setq r (if (= 0 (get-active-window)) -10 10))
(while job
(setq w (new-window (+ r (car p)) (cdr p) 50 4 dialog-attribute))
(window-print w 2 0 "Rename copy: " src)
(setq c (strrchr n #\.))
(setq c (if c c (length n)))
(setq ret (read-line w 3 2 44 n c))
(delete-window w)
(if ret (progn
(setq ret (concat (add-last-sep destdir) ret))
(setq *quiet-error* t)
(setq st (stat ret))
(setq *quiet-error* nil)
(if st (message ret " already exists.")
(progn
(copy-file src ret)
(setq job nil))))))))
(defun selective-copy (src destdir)
(let* ((dest (concat (add-last-sep destdir) (basename src)))
st sel sts)
(setq *quiet-error* t)
(setq st (stat dest))
(setq *quiet-error* nil)
(cond ((directory-p src)
(mkdir dest)
(setq sel (readdir src))
(while sel
(selective-copy (concat (add-last-sep src) (car sel)) dest)
(setq sel (cdr sel))))
(st
(setq sel (selector (if (= 0 (get-active-window)) (concat "Copy: " src " -> " destdir)
(concat "Copy: " destdir " <- " src))
'((#\u " Update " 0)
(#\o " Overwrite " 1)
(#\r " Rename " 2)
(#\n " Not copy " 3))))
(cond ((= sel 0) (setq sts (stat src)) (if (and sts (< (fourth st) (fourth sts))) (copy-file src dest)))
((= sel 1) (copy-file src dest))
((= sel 2) (rename-copy src destdir))))
(t (copy-file src dest)))))
(defun copy-to (dest)
(cond ((= 0 (get-number-of-selected)) (selective-copy (get-name-on-cursor) dest))
(t (let ((sel (get-selected-list)))
(while sel
(selective-copy (car sel) dest)
(setq sel (cdr sel))))))
(reload-redraw))
(defun move-to (dest)
(cond ((= 0 (get-number-of-selected))
(rename (get-name-on-cursor) (concat (add-last-sep dest) (basename (get-name-on-cursor)))))
(t (let ((li (get-selected-list)))
(while li
(rename (car li) (concat (add-last-sep dest) (basename (car li))))
(setq li (cdr li))))))
(reload-redraw))
(defun get-file-attribute (name)
(sixth (stat name)))
(defun get-file-size (name)
(second (stat name)))
(defun directory-p (name)
(!= 0 (& (get-file-attribute name) A_DIR)))
(defun read-only-p (name)
(!= 0 (& (get-file-attribute name) A_RONLY)))
(defun chmod-r (name)
(chmod name (& (get-file-attribute name) (~ A_RONLY))))
;
; Dialogs
; =======
;
(defun center-position (dx dy)
(cons (/ (- (car (get-screen-size)) dx) 2)
(/ (- (cdr (get-screen-size)) dy) 2)))
(defun confirm-message (str)
(let ((x (car (get-screen-size))) w)
(setq w (new-window (/ x 4) 4 (/ x 2) 8 dialog-attribute))
(window-print w 2 1 str)
(get-key)
(delete-window w)))
(defun y-or-n-p (str)
(let ((x (car (get-screen-size))) w k (ret nil))
(setq w (new-window (/ x 4) 4 (/ x 2) 8 dialog-attribute))
(window-print w 2 1 str " (y/n)?")
(while (null ret)
(setq k (get-key))
(cond ((or (= #\Y k) (= #\y k) (= K_RETURN k)) (setq ret 1))
((or (= #\N k) (= #\n k) (= K_ESC k)) (setq ret 2))))
(delete-window w)
(= ret 1)))
(defun eval-expression ()
(let ((p (center-position 50 3)) w ret r)
(setq w (new-window (car p) (cdr p) 50 3 dialog-attribute))
(window-print w 2 1 "Eval:")
(setq ret (read-line w 7 1 42))
(delete-window w)
(if ret (eval (lisp-parser ret)))))
(defun edit-command-line (type)
(let ((p (center-position 60 3)) w ret r)
(setq w (new-window (car p) (cdr p) 60 3 dialog-attribute))
(window-print w 2 0 "Command line:")
(setq ret (cond ((= 0 type)
(read-line w 2 1 56 (concat (get-name-on-cursor) " ") (1+ (length (get-name-on-cursor)))))
((= 1 type)
(read-line w 2 1 56 (concat " " (get-name-on-cursor)) 0))))
(delete-window w)
ret))
(defun remove-file (name)
(if (read-only-p name)
(and (y-or-n-p (concat name " is read-only.\n Remove"))
(chmod-r name)
(remove name))
(remove name)))
(defun remove-1 (name)
(cond ((directory-p name)
(and (y-or-n-p (concat "Remove " name )) (rm-fr name)))
(t (remove-file name))))
(defun remove-dialog ()
(if (in-archive-p)
(message "You are in archive.")
(progn
(cond ((= 0 (get-number-of-selected))
(if (directory-p (get-name-on-cursor))
(remove-1 (get-name-on-cursor))
(and (y-or-n-p (concat "Remove " (get-name-on-cursor))) (remove-file (get-name-on-cursor)))))
((y-or-n-p "Remove selected files")
(mapcar 'remove-1 (get-selected-list))))
(reload)
(redraw))))
(defun make-directory-dialog ()
(if (in-archive-p)
(message "You are in archive.")
(let ((p (center-position 50 4)) w ret r togo)
(setq r (if (= 0 (get-active-window)) -10 10))
(setq w (new-window (+ r (car p)) (cdr p) 50 4 dialog-attribute))
(window-print w 2 0 "Make new directory: " (get-this-path))
(setq ret (read-line w 3 2 (- 50 6)))
(delete-window w)
(if ret (progn
(setq ret (string-split ret))
(setq togo (if (= 1 (length ret)) (first ret) nil))
(while ret
(mkdir (concat (add-last-sep (get-this-path)) (car ret)))
(setq ret (cdr ret)))
(and togo
(go (concat (add-last-sep (get-this-path)) togo)))
(reload) (redraw))))))
(defun rename-dialog ()
(if (in-archive-p)
(message "You are in archive.")
(let ((p (center-position 50 4)) w ret (n (basename (get-name-on-cursor))) c r)
(setq r (if (= 0 (get-active-window)) -10 10))
(setq w (new-window (+ r (car p)) (cdr p) 50 4 dialog-attribute))
(window-print w 2 0 "Rename: " (get-name-on-cursor))
(setq c (strrchr n #\.))
(setq c (if c c (length n)))
(setq ret (read-line w 3 2 44 n c))
(delete-window w)
(if ret (progn
(setq ret (concat (add-last-sep (get-this-path)) ret))
(or (string= (get-name-on-cursor) ret)
(rename (get-name-on-cursor) ret))
(reload)
(redraw))))))
(defun duplicate-dialog ()
(if (or (in-archive-p) (directory-p (get-name-on-cursor)))
(message "Can't duplicate.")
(let ((p (center-position 50 4)) w ret (n (basename (get-name-on-cursor))) c r)
(setq r (if (= 0 (get-active-window)) -10 10))
(setq w (new-window (+ r (car p)) (cdr p) 50 4 dialog-attribute))
(window-print w 2 0 "Duplicate: " (get-name-on-cursor))
(setq c (strrchr n #\.))
(setq c (if c c (length n)))
(setq ret (read-line w 3 2 44 n c))
(delete-window w)
(if ret (progn
(setq ret (concat (add-last-sep (get-this-path)) ret))
(or (string= (get-name-on-cursor) ret)
(stat ret)
(copy-file (get-name-on-cursor) ret))
(reload)
(redraw))))))
(defun chmod-print1 (w n attr cur)
(let ((inv (| (>> dialog-attribute 4) (<< (& 0x0f dialog-attribute) 4))))
(window-set-attribute w dialog-attribute)
(cond ((= n 0)
(window-print w 0 3 " Read only: off on")
(window-set-attribute w (if (= n cur) 0xe1 inv))
(if (!= 0 (& attr A_RONLY)) (window-print w 19 3 "on") (window-print w 14 3 "off")))
((= n 1)
(window-print w 0 4 " Hidden: off on")
(window-set-attribute w (if (= n cur) 0xe1 inv))
(if (!= 0 (& attr A_HIDDEN)) (window-print w 19 4 "on") (window-print w 14 4 "off")))
((= n 2)
(window-print w 0 5 " System: off on")
(window-set-attribute w (if (= n cur) 0xe1 inv))
(if (!= 0 (& attr A_SYSTEM)) (window-print w 19 5 "on") (window-print w 14 5 "off")))
((= n 3)
(window-print w 0 6 " Archive: off on")
(window-set-attribute w (if (= n cur) 0xe1 inv))
(if (!= 0 (& attr A_ARCHIVE)) (window-print w 19 6 "on") (window-print w 14 6 "off")))
(t (message "chmod-dialog: internal error.")))))
(defun chmod-dialog ()
(if (in-archive-p)
(message "You are in archive.")
(let ((p (center-position 30 8)) w ret (job t) k
(attr (gemod (get-name-on-cursor))) (cur 0) r)
(setq r (if (= 0 (get-active-window)) -10 10))
(setq w (new-window (+ r (car p)) (cdr p) 30 8 dialog-attribute))
(window-print w 0 0 "Change attributes: ")
(window-print w 2 1 (get-name-on-cursor))
(chmod-print1 w 0 attr 0)
(chmod-print1 w 1 attr 0)
(chmod-print1 w 2 attr 0)
(chmod-print1 w 3 attr 0)
(while job
(setq k (get-key))
(cond ((or (= k K_ESC) (= k K_CTRL_G)) (setq cur nil job nil))
((= k K_RETURN) (setq job nil))
((and (or (= k K_UP) (= k K_CTRL_P)) (< 0 cur))
(chmod-print1 w cur attr -1)
(setq cur (1- cur))
(chmod-print1 w cur attr cur))
((and (or (= k K_DOWN) (= k K_CTRL_N)) (> 3 cur))
(chmod-print1 w cur attr -1)
(setq cur (1+ cur))
(chmod-print1 w cur attr cur))
((or (= k #\ ) (= k K_CTRL_F) (= k K_CTRL_B) (= k K_LEFT) (= k K_RIGHT))
(setq attr (^ attr (eval (nth cur '(A_RONLY A_HIDDEN A_SYSTEM A_ARCHIVE)))))
(chmod-print1 w cur attr cur))
((= k #\r)
(chmod-print1 w cur attr -1)
(setq cur 0 attr (^ attr A_RONLY))
(chmod-print1 w cur attr cur))
((= k #\h)
(chmod-print1 w cur attr -1)
(setq cur 1 attr (^ attr A_HIDDEN))
(chmod-print1 w cur attr cur))
((= k #\s)
(chmod-print1 w cur attr -1)
(setq cur 2 attr (^ attr A_SYSTEM))
(chmod-print1 w cur attr cur))
((= k #\a)
(chmod-print1 w cur attr -1)
(setq cur 3 attr (^ attr A_ARCHIVE))
(chmod-print1 w cur attr cur))))
(if cur (progn
(chmod (get-name-on-cursor) attr)
(reload)
(redraw)))
(delete-window w))))
(defun max (dat)
(cond ((= 1 (length dat)) (first dat))
((<= 2 (length dat)) (let ((m (max (cdr dat)))) (if (< (first dat) m) m (first dat))))
(t 0)))
(defun selector-print (dat y w atr)
(window-set-attribute w atr)
(window-print w 2 (+ 2 y) (second (nth y dat))))
(defun selector-search-key (dat k)
(cond ((null dat) nil)
((= k (caar dat)) 0)
(t (let (ret)
(setq ret (selector-search-key (cdr dat) k))
(if ret (1+ ret) nil)))))
(defun selector (title dat)
(let* ((len (length dat))
(dx (+ 4 (max (mapcar 'length (cons title (mapcar 'second dat))))))
(dy (+ 3 len))
(p (center-position dx dy))
(w (new-window (car p) (cdr p) dx dy dialog-attribute))
(cur 0) (i 0) (job t) k)
(window-print w 1 0 title) ;make window
(while (< i len) ;initial draw
(selector-print dat i w (if (= i cur) selector-active-item-attribute selector-item-attribute))
(setq i (1+ i)))
(while job ;key loop
(setq k (get-key))
(cond ((or (= k K_ESC) (= k K_CTRL_G)) (setq cur nil job nil))
((= k K_RETURN) (setq job nil))
((and (or (= k K_UP) (= k K_CTRL_P)) (< 0 cur))
(selector-print dat cur w selector-item-attribute)
(setq cur (1- cur))
(selector-print dat cur w selector-active-item-attribute))
((and (or (= k K_DOWN) (= k K_CTRL_N)) (> (1- len) cur))
(selector-print dat cur w selector-item-attribute)
(setq cur (1+ cur))
(selector-print dat cur w selector-active-item-attribute))
(t (setq i (selector-search-key dat k))
(if i (progn (selector-print dat cur w selector-item-attribute)
(setq cur i job nil)
(selector-print dat cur w selector-active-item-attribute))))))
(if cur (setq cur (eval (third (nth cur dat)))))
(delete-window w)
cur))
(defun sort-dialog ()
(selector "Sort:"
'((#\n "n Name (A-Za-z) " (sort ST_NAME))
(#\i "i Name (Aa-Zz) " (sort ST_NAMEIGNORECASE))
(#\e "e Extension " (sort ST_EXTENSION))
(#\t "t Timestamp " (sort ST_TIMESTAMP))
(#\l "l Length " (sort ST_LENGTH))))
(redraw))
;
; User environment dependent
; ==========================
;
(defun change-drive ()
(selector "Change drive:"
'((#\a " A: FAT floppy disk " (go-drive #\A))
(#\c " C: FAT MS-DOS 6.2/V & Windows3.1J " (go-drive #\C))
(#\d " D: FAT " (go-drive #\D))
(#\e " E: HPFS OS/2 Warp J " (go-drive #\E))
(#\f " F: HPFS " (go-drive #\F))
(#\g " G: CD-ROM " (go-drive #\G)))))
(defun go-from-list ()
(selector "Change directory:"
'((#\a " Archives E:/arc " (go "E:/arc"))
(#\b " Binaries E:/usr/local/bin " (go "E:/usr/local/bin"))
(#\c " cond work E:/home/kent/p/cond " (go "E:/home/kent/p/cond"))
(#\d " Downloaded E:/down " (go "E:/down"))
(#\h " Home " (go (delete-last-sep (getenv "HOME"))))
(#\j " j work E:/home/kent/p/win " (go "E:/home/kent/p/win"))
(#\m " Music data E:/mud " (go "E:/mud"))
(#\p " Programs E:/home/kent/p " (go "E:/home/kent/p"))
(#\t " Temporary E:/tmp " (go "E:/tmp"))
(#\z " zsh work E:/home/kent/zsh " (go "E:/home/kent/zsh")))))
(defun execute ()
(cond ((or (directoryp-on-cursor) (archive-p (get-v-name-on-cursor)))
(go (get-v-name-on-cursor)))
(t (let ((n (get-name-on-cursor)) cl)
(cond ((string-tail= n ".exe" ".com")
(setq cl (edit-command-line 0))
(if cl (progn (system cl)
(redraw-all))))
((string-tail= n ".cmd")
(setq cl (edit-command-line 0))
(if cl (progn (spawn P_WAIT (list "cmd" "/c" cl))
(redraw-all))))
((string-tail= n ".jpg" ".gif" ".pi" ".pic" ".p2" ".mag")
(spawn P_DETACH (list "ib" n)))
((string-tail= n ".mid" ".rcp" ".r36" ".mid.gz" ".rcp.gz" ".r36.gz")
(spawn P_DETACH (list "cond" "-r" "-gsreset" n)))
((string-tail= n ".htm" ".html")
(spawn P_DETACH (list "explore" n)))
(t (spawn P_WAIT (list "less" n)) (redraw-all)))
(next-line)))))
(defun execute2 ()
(let ((n (get-name-on-cursor)))
(cond ((string-tail= n ".lzh")
(spawn P_WAIT (list "lha" "x" n (add-last-sep (get-that-path))))
(reload-redraw))
((string-tail= n ".zip")
(spawn P_WAIT (list "unzip" n "-d" (add-last-sep (get-that-path))))
(reload-redraw))
((string-tail= n ".gz")
(setq n (basename n))
(setq n (concat (add-last-sep (get-that-path)) (subseq n 0 (- (length n) 3))))
(system "gzip -dc " (get-name-on-cursor) " > " n)
(copy-time (get-name-on-cursor) n)
(reload-redraw))
(t (spawn P_WAIT (list "less" n)) (redraw-all)))
(next-line)))
;
; Key bindings
; ============
;
(global-set-key 0 K_TAB '(other-window))
(global-set-key 0 #\. '(go-parent))
(global-set-key 0 #\/ '(go-root))
(global-set-key 0 #\o '(go (get-that-path)))
(global-set-key 0 #\O '(progn (other-window) (go (get-that-path)) (other-window)))
(global-set-key 0 K_RIGHT '(mint-arrow-right))
(global-set-key 0 K_CTRL_F '(mint-arrow-right))
(global-set-key 0 K_LEFT '(mint-arrow-left))
(global-set-key 0 K_CTRL_B '(mint-arrow-left))
(global-set-key 0 #\c '(copy-to (get-that-path)))
(global-set-key 0 #\m '(move-to (get-that-path)))
(global-set-key 0 #\k '(remove-dialog))
(global-set-key 0 #\d '(change-drive))
(global-set-key 0 #\z '(go-from-list))
(global-set-key 0 K_CTRL_L '(redraw-all))
(global-set-key 0 K_RETURN '(execute))
(global-set-key 0 K_ALT_RETURN '(execute2))
(global-set-key 0 #\e '(progn (spawn P_WAIT (list "vi" (get-name-on-cursor))) (reload-redraw)))
(global-set-key 0 #\E '(let ((cl (edit-command-line 1))) (if cl (system cl))))
(global-set-key 0 #\l '(progn (spawn P_WAIT (list "less" (get-name-on-cursor))) (redraw-all)))
(global-set-key 0 #\ '(progn (select) (next-line)))
(global-set-key 0 K_CTRL_SPACE '(clear-select))
(global-set-key 0 #\a '(select-all-files))
(global-set-key 0 #\A '(select-all))
(global-set-key 0 K_CTRL_A '(chmod-dialog))
(global-set-key 0 #\s '(sort-dialog))
(global-set-key 0 #\n '(make-directory-dialog))
(global-set-key 0 #\r '(rename-dialog))
(global-set-key 0 #\D '(duplicate-dialog))
(global-set-key 0 K_ALT_A '(toggle-display-all-files))
(global-set-key 0 K_INS '(progn (reload) (redraw)))
(global-set-key 0 K_CTRL_N '(next-line))
(global-set-key 0 K_DOWN '(next-line))
(global-set-key 0 K_CTRL_P '(previous-line))
(global-set-key 0 K_UP '(previous-line))
(global-set-key 0 #\< '(beginning-of-buffer))
(global-set-key 0 #\> '(end-of-buffer))
(global-set-key 0 K_CTRL_V '(scroll-up))
(global-set-key 0 K_PAGEDOWN '(scroll-up))
(global-set-key 0 K_CTRL_Z '(scroll-down))
(global-set-key 0 K_PAGEUP '(scroll-down))
(global-set-key 0 K_ESC '(progn (set-prefix 2) (message " ESC ")))
(global-set-key 0 K_CTRL_X '(progn (set-prefix 1) (message " C-x ")))
(global-set-key 1 #\o '(other-window)) ;C-x o
(global-set-key 1 K_CTRL_C '(kill-j)) ;C-x C-c
(global-set-key 2 K_ESC '(eval-expression)) ;ESC ESC
; ------------------- end