Initial Commit
[packages] / xemacs-packages / zenirc / src / zenirc-yow-filter.el
1 ;;; zenirc-yow-filter.el --- neutralize yowage
2
3 ;; Copyright (C) 1997 Noah S. Friedman
4
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
6 ;; Maintainer: friedman@prep.ai.mit.edu
7 ;; Keywords: zenirc, extensions, oink, yow
8 ;; Created: 1997-02-10
9
10 ;; $Id: zenirc-yow-filter.el,v 1.1.1.1 1998-10-07 11:21:31 jareth Exp $
11
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16 ;;
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21 ;;
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; if not, you can either send email to this
24 ;; program's maintainer or write to: The Free Software Foundation,
25 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; I estimate that loading this file grows emacs' permanent
30 ;; heap by about 650K.
31
32 ;;; Code:
33
34 (require 'zenirc)
35
36 (or (boundp 'yow-vector)
37     (boundp 'yow-file)
38     (load "yow"))
39
40 (defconst zenirc-yow-filter-table nil)
41
42 (defun zenirc-yow-filter-table-snarf (&optional file)
43   (let ((table (make-vector 509 0))
44         (yowfile (or file
45                      (and (boundp 'yow-file)
46                           yow-file)
47                      (concat data-directory "yow.lines")))
48         (buf (generate-new-buffer " *Yow!*"))
49         (snarf-buf (function
50                     (lambda ()
51                       (goto-char (point-min))
52                       (while (progn
53                                (skip-chars-forward " \t\n\r\f")
54                                (not (eobp)))
55                         (intern (buffer-substring (prog1
56                                                       (point)
57                                                     (search-forward "\0"))
58                                                   (1- (point)))
59                                 table))))))
60     (save-excursion
61       (save-match-data
62         (set-buffer buf)
63         (setq buffer-undo-list t)
64         (insert-file-contents yowfile)
65         (search-forward "\0")
66         (delete-region (point-min) (point))
67         (while (re-search-forward "\n" nil t)
68           (delete-char -1))
69         (funcall snarf-buf)
70         (goto-char (point-min))
71         (while (re-search-forward "[ \t\n\r\f]+" nil t)
72           (replace-match " "))
73         (funcall snarf-buf)))
74     (kill-buffer buf)
75     table))
76
77 (defun zenirc-yow-filter (proc parsedmsg)
78   (or zenirc-yow-filter-table
79       (setq zenirc-yow-filter-table (zenirc-yow-filter-table-snarf)))
80   (cond ((intern-soft (aref parsedmsg 3) zenirc-yow-filter-table)
81          (and zenirc-debug-ignore
82               (zenirc-message proc 'debug (format "Ignored: %s" parsedmsg)))
83          (setq zenirc-run-next-hook nil))))
84
85 (zenirc-add-hook 'zenirc-server-PRIVMSG-hook 'zenirc-yow-filter)
86 (zenirc-add-hook 'zenirc-server-NOTICE-hook  'zenirc-yow-filter)
87
88 (provide 'zenirc-yow-filter)
89
90 ;;; zenirc-yow-filter.el ends here.