1 ;;; zenirc-format.el --- format nick!user@host for zenirc
3 ;; Copyright (C) 1993, 1994 Ben A. Mesander
4 ;; Copyright (C) 1995 Noah S. Friedman
6 ;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
7 ;; Charles Hannum <mycroft@gnu.ai.mit.edu>
8 ;; Richard Todd <rmtodd@essex.ecn.uoknor.edu>
9 ;; Noah Friedman <friedman@prep.ai.mit.edu>
10 ;; Maintainer: friedman@prep.ai.mit.edu
11 ;; Keywords: zenirc, extensions
12 ;; Created: 1993/06/03
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; if not, you can either send email to this
26 ;; program's maintainer or write to: The Free Software Foundation,
27 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
31 ;; Format nick!user@host info the first time you see someone as
32 ;; nick!user@host and thereafter as just nick. Nick changes are detected
33 ;; and handled correctly.
35 ;; This was rewritten 1995-03-18 by friedman to use a hash table instead of
42 ;; 101 buckets should be a reasonable size for most people (remember to use
43 ;; a prime number to get good hashing characteristics).
44 ;; This is not the total number of nicks you can cache, but just the number
45 ;; of "buckets" in which nicks can be stored. If you talk to thousands
46 ;; and thousands of people it might help to increase the size of this
47 ;; table, but even then it isn't necessary.
48 (defvar zenirc-nickuserhost-table (make-vector 101 0)
49 "Table used to store nicknames and corresponding nick!user@host.")
51 (defun zenirc-format-nickuserhost-fancy (nickuserhost)
52 (let ((nick (zenirc-extract-nick nickuserhost)))
54 (let* ((nicksym (intern (zenirc-downcase-name nick)
55 zenirc-nickuserhost-table))
56 (cached (and (boundp nicksym)
57 (symbol-value nicksym))))
59 (setq zenirc-run-next-hook nil)
60 (set nicksym nickuserhost)
62 (string= cached nickuserhost)
63 (setq nickuserhost nick)))))
66 (zenirc-add-hook 'zenirc-format-nickuserhost-hook
67 'zenirc-format-nickuserhost-fancy)
69 (defun zenirc-fancy-NICK (proc parsedmsg)
70 (let* ((userhost (zenirc-extract-userhost (aref parsedmsg 1)))
71 (to (aref parsedmsg 2)))
72 (set (intern (zenirc-downcase-name to) zenirc-nickuserhost-table)
73 (concat to "!" userhost))))
75 (zenirc-add-hook 'zenirc-server-NICK-hook 'zenirc-fancy-NICK)
77 ;; Also hook into the /who display.
78 ;; (added by rmtodd, rewritten by friedman)
79 (defun zenirc-fancy-352 (proc parsedmsg)
80 ;; If the 3 arg is "Channel", this is the header.
81 ;; One wonders why the header isn't a different numeric.
82 (or (string= (aref parsedmsg 3) "Channel")
83 (let* ((nick (aref parsedmsg 7))
84 (nickuserhost (concat nick "!" (aref parsedmsg 4) "@"
86 (nicksym (intern (zenirc-downcase-name nick)
87 zenirc-nickuserhost-table)))
88 (set nicksym nickuserhost))))
91 (zenirc-add-hook 'zenirc-server-352-hook 'zenirc-fancy-352)
93 (provide 'zenirc-format)
95 ;; zenirc-format.el ends here