diff options
author | Eric S. Raymond <esr@snark.thyrsus.com> | 1993-03-27 01:58:33 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@snark.thyrsus.com> | 1993-03-27 01:58:33 +0000 |
commit | 45b44a5a6543d27c775db764a70cd55ba0496e2d (patch) | |
tree | 0995252caa0e758e369ffe67674254f5e4ba6103 /lisp/play/cookie1.el | |
parent | 131ca136d1e3912684c8acba26423736712f0abb (diff) | |
download | emacs-45b44a5a6543d27c775db764a70cd55ba0496e2d.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.el | 27 |
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) |