aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond1993-03-27 01:58:33 +0000
committerEric S. Raymond1993-03-27 01:58:33 +0000
commit45b44a5a6543d27c775db764a70cd55ba0496e2d (patch)
tree0995252caa0e758e369ffe67674254f5e4ba6103
parent131ca136d1e3912684c8acba26423736712f0abb (diff)
downloademacs-45b44a5a6543d27c775db764a70cd55ba0496e2d.tar.gz
emacs-45b44a5a6543d27c775db764a70cd55ba0496e2d.zip
(cookie) Enhanced it to handle both LINS files and UNIX fortune files.
-rw-r--r--lisp/play/cookie1.el27
1 files changed, 16 insertions, 11 deletions
diff --git a/lisp/play/cookie1.el b/lisp/play/cookie1.el
index 61eaaddce33..6cdd397e0c8 100644
--- a/lisp/play/cookie1.el
+++ b/lisp/play/cookie1.el
@@ -33,16 +33,21 @@
33;; functions `pick-random' and `shuffle-vector' may be of interest to 33;; functions `pick-random' and `shuffle-vector' may be of interest to
34;; programmers. 34;; programmers.
35;; 35;;
36;; The code expects phrase files to be in ITS-style LINS format 36;; The code expects phrase files to be in one of two formats:
37;; (strings terminated by ASCII 0 characters, leading whitespace 37;;
38;; ignored). Everything up to the first delimiter is treated as a 38;; * ITS-style LINS format (strings terminated by ASCII 0 characters,
39;; comment. Other formats (notably UNIX fortune-file format) could 39;; leading whitespace ignored).
40;; easily be supported by changing the `cookie-delimiter' constant. 40;;
41;; * UNIX fortune file format (quotes terminated by %% on a line by itself).
42;;
43;; Everything up to the first delimiter is treated as a comment. Other
44;; formats could be supported by adding alternates to the regexp
45;; `cookie-delimiter'.
41;; 46;;
42;; This code derives from Steve Strassman's 1987 spook.el package, but 47;; This code derives from Steve Strassman's 1987 spook.el package, but
43;; has been generalized so that it supports multiple simultaneous cookie 48;; has been generalized so that it supports multiple simultaneous
44;; databases. It is intended to be called from other packages such as 49;; cookie databases and fortune files. It is intended to be called
45;; yow.el and spook.el. 50;; from other packages such as yow.el and spook.el.
46;; 51;;
47;; TO DO: teach cookie-snarf to auto-detect ITS PINS or UNIX fortune(6) 52;; TO DO: teach cookie-snarf to auto-detect ITS PINS or UNIX fortune(6)
48;; format and do the right thing. 53;; format and do the right thing.
@@ -52,7 +57,7 @@
52; Randomize the seed in the random number generator. 57; Randomize the seed in the random number generator.
53(random t) 58(random t)
54 59
55(defconst cookie-delimiter "\0" 60(defconst cookie-delimiter "\n%%\n\\|\0"
56 "Delimiter used to separate cookie file entries.") 61 "Delimiter used to separate cookie file entries.")
57 62
58(defun cookie (phrase-file startmsg endmsg) 63(defun cookie (phrase-file startmsg endmsg)
@@ -92,10 +97,10 @@ subsequent calls on the same file won't go to disk."
92 (result nil)) 97 (result nil))
93 (set-buffer buf) 98 (set-buffer buf)
94 (insert-file-contents (expand-file-name phrase-file)) 99 (insert-file-contents (expand-file-name phrase-file))
95 (search-forward cookie-delimiter) 100 (re-search-forward cookie-delimiter)
96 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp))) 101 (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
97 (let ((beg (point))) 102 (let ((beg (point)))
98 (search-forward "\0") 103 (re-search-forward cookie-delimiter)
99 (setq result (cons (buffer-substring beg (1- (point))) 104 (setq result (cons (buffer-substring beg (1- (point)))
100 result)))) 105 result))))
101 (kill-buffer buf) 106 (kill-buffer buf)