Replace more nested ifs with cond

This is a continuation of d526047 "Replace more nested ifs with cond".
* lisp/play/dunnet.el (dun-firstword, dun-firstwordl, dun-cat): Use
when and cond where appropriate.
This commit is contained in:
Mark Oteiza 2017-04-08 11:34:17 -04:00
parent fd4b83ca7c
commit c5f319eb3a

View file

@ -2199,16 +2199,14 @@ for a moment, then straighten yourself up.\n")
;;; Get the first non-ignored word from a list.
(defun dun-firstword (list)
(if (not (car list))
nil
(while (and list (member (intern (car list)) dun-ignore))
(when (car list)
(while (and list (memq (intern (car list)) dun-ignore))
(setq list (cdr list)))
(car list)))
(defun dun-firstwordl (list)
(if (not (car list))
nil
(while (and list (member (intern (car list)) dun-ignore))
(when (car list)
(while (and list (memq (intern (car list)) dun-ignore))
(setq list (cdr list)))
list))
@ -2820,28 +2818,25 @@ drwxr-xr-x 3 root staff 2048 Jan 1 1970 ..")
(setq dun-badcd t))
(defun dun-cat (args)
(let (doto checklist)
(if (not (setq args (car args)))
(dun-mprincl "Usage: cat <ascii-file-name>")
(if (string-match "/" args)
(dun-mprincl "cat: only files in current directory allowed.")
(if (and (> dun-cdroom 0) (string= args "description"))
(dun-mprincl (car (nth dun-cdroom dun-rooms)))
(if (setq doto (string-match "\\.o" args))
(progn
(if (= dun-cdroom -10)
(setq checklist dun-inventory)
(setq checklist (nth dun-cdroom dun-room-objects)))
(if (not (member (cdr
(assq (intern
(substring args 0 doto))
dun-objnames))
checklist))
(dun-mprincl "File not found.")
(dun-mprincl "Ascii files only.")))
(if (assq (intern args) dun-unix-verbs)
(dun-mprincl "Ascii files only.")
(dun-mprincl "File not found."))))))))
(cond
((null (setq args (car args)))
(dun-mprincl "Usage: cat <ascii-file-name>"))
((string-match-p "/" args)
(dun-mprincl "cat: only files in current directory allowed."))
((and (> dun-cdroom 0) (string= args "description"))
(dun-mprincl (car (nth dun-cdroom dun-rooms))))
((string-match "\\.o" args)
(let ((doto (match-beginning 0)) checklist)
(if (= dun-cdroom -10)
(setq checklist dun-inventory)
(setq checklist (nth dun-cdroom dun-room-objects)))
(if (member (cdr (assq (intern (substring args 0 doto)) dun-objnames))
checklist)
(dun-mprincl "Ascii files only.")
(dun-mprincl "File not found."))))
((assq (intern args) dun-unix-verbs)
(dun-mprincl "Ascii files only."))
(t (dun-mprincl "File not found."))))
(defun dun-rlogin-endgame ()
(if (not (= (dun-score nil) 90))