summaryrefslogtreecommitdiff
path: root/lisp/play/cookie1.el
diff options
context:
space:
mode:
authorEric S. Raymond <esr@snark.thyrsus.com>1993-03-27 01:58:33 +0000
committerEric S. Raymond <esr@snark.thyrsus.com>1993-03-27 01:58:33 +0000
commit0befdbedd9cd324d56d7996b6168e321e0ce8a24 (patch)
treee8d8b1d7b758d7a17a658c341872bdd54671b195 /lisp/play/cookie1.el
parent0c1b24b6921e4c8177d0990ea01e746291028d7a (diff)
downloademacs-0befdbedd9cd324d56d7996b6168e321e0ce8a24.tar.gz
(cookie) Enhanced it to handle both LINS files and UNIX fortune files.
Diffstat (limited to 'lisp/play/cookie1.el')
-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 @@
;; functions `pick-random' and `shuffle-vector' may be of interest to
;; programmers.
;;
-;; The code expects phrase files to be in ITS-style LINS format
-;; (strings terminated by ASCII 0 characters, leading whitespace
-;; ignored). Everything up to the first delimiter is treated as a
-;; comment. Other formats (notably UNIX fortune-file format) could
-;; easily be supported by changing the `cookie-delimiter' constant.
+;; The code expects phrase files to be in one of two formats:
+;;
+;; * ITS-style LINS format (strings terminated by ASCII 0 characters,
+;; leading whitespace ignored).
+;;
+;; * UNIX fortune file format (quotes terminated by %% on a line by itself).
+;;
+;; Everything up to the first delimiter is treated as a comment. Other
+;; formats could be supported by adding alternates to the regexp
+;; `cookie-delimiter'.
;;
;; This code derives from Steve Strassman's 1987 spook.el package, but
-;; has been generalized so that it supports multiple simultaneous cookie
-;; databases. It is intended to be called from other packages such as
-;; yow.el and spook.el.
+;; has been generalized so that it supports multiple simultaneous
+;; cookie databases and fortune files. It is intended to be called
+;; from other packages such as yow.el and spook.el.
;;
;; TO DO: teach cookie-snarf to auto-detect ITS PINS or UNIX fortune(6)
;; format and do the right thing.
@@ -52,7 +57,7 @@
; Randomize the seed in the random number generator.
(random t)
-(defconst cookie-delimiter "\0"
+(defconst cookie-delimiter "\n%%\n\\|\0"
"Delimiter used to separate cookie file entries.")
(defun cookie (phrase-file startmsg endmsg)
@@ -92,10 +97,10 @@ subsequent calls on the same file won't go to disk."
(result nil))
(set-buffer buf)
(insert-file-contents (expand-file-name phrase-file))
- (search-forward cookie-delimiter)
+ (re-search-forward cookie-delimiter)
(while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
(let ((beg (point)))
- (search-forward "\0")
+ (re-search-forward cookie-delimiter)
(setq result (cons (buffer-substring beg (1- (point)))
result))))
(kill-buffer buf)