home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
irchat-pj
/
2.5
/
irchat-pj-2.5.6p.tar.gz
/
irchat-pj-2.5.6p.tar
/
irchat-pj-2.5.6p
/
irchat-filter.el
< prev
next >
Wrap
Lisp/Scheme
|
2001-09-16
|
6KB
|
150 lines
;;;
;;; $Id: irchat-filter.el,v 1.11 2001/09/01 14:06:20 simm Exp $
;;;
;;; see file irchat-copyright.el for change log and copyright info
(require 'pure-generic)
(require 'pure-cs)
(require 'pure-pr-filter)
;;;
;;; These are defsubst just for speed, as it is expensive to call funtions at
;;; emacs lisp (also evals are expensive)
;;;
(defsubst irchat-current-minute ()
(string-to-int (substring (current-time-string) 14 16)))
(defvar irchat-minute 0)
(defun irchat-pj-apply (func &rest args)
"Apply with error handling"
(if (fboundp func)
(condition-case nil
(apply 'apply func args)
(error
(message "irchat-pj: ERROR: function %s:" func)
(let ((i 0) (rest args))
(while rest
(message "\targs[%d]: \"%s\"" i (car rest))
(setq i (1+ i) rest (cdr rest))))
(ding)))
(message "irchat-pj: ERROR: No such function: %s" func)))
(defun irchat-handle (line)
"Called when we have at least one line of output from the IRC server."
(let ((obuf (current-buffer))
prefix userhost (cmd "") arg)
(while (string-match "^\\([^\r]*\\)\r+\\(.*\\)" line)
(setq line (concat (match-string 1 line)
(match-string 2 line))))
(if (string-match "^:\\([^ ]+\\) *\\(.*\\)" line)
(setq prefix (match-string 1 line)
line (match-string 2 line)))
(if (and prefix (string-match "^\\([^!]*\\)!\\(.*\\)" prefix))
(setq userhost (match-string 2 prefix)
prefix (match-string 1 prefix)))
(if (string-match "^ *\\([^ ]+\\) *\\(.*\\)" line)
(setq arg (list (match-string 1 line))
line (match-string 2 line)))
(while (string-match "^\\([^:][^ ]*\\) +\\(.*\\)" line)
(nconc arg (list (match-string 1 line)))
(setq line (match-string 2 line)))
(if (not (string= line ""))
(if (string-match "^:\\(.*\\)" line)
(nconc arg (list (match-string 1 line)))
(nconc arg (list line))))
(if (and prefix userhost
(not (string= (get (intern prefix) 'userhost) userhost)))
(put (intern prefix) 'userhost userhost))
(if (car arg)
(setq cmd (downcase (car arg))
arg (cdr arg)))
(if (and (boundp (setq hook
(intern (concat "irchat-handle-" cmd "-hook"))))
(eval hook)
(eval (list (eval hook) (cons prefix arg))))
nil
(setq fun (intern (concat "irchat-handle-" cmd)))
;; modified by simm@irc.fan.gr.jp, Thu, 10 Jun 1999
(if (or (eq fun 'irchat-handle-join)
(eq fun 'irchat-handle-nick)
(eq fun 'irchat-handle-part)
(eq fun 'irchat-handle-quit))
(irchat-pj-apply fun prefix userhost arg)
(if (fboundp fun)
(irchat-pj-apply fun prefix arg)
(if irchat-debugging
(irchat-insert-special (format "No handle-%s (%s) %s\n" cmd prefix
(prin1-to-string arg))))
(let* ((cmd-number (string-to-int cmd))
(default-number (/ cmd-number 100)) tmp)
(setq fun (intern (concat "irchat-handle-"
(format "%d00s" default-number))))
(if (and (> cmd-number 0)
(fboundp fun))
(irchat-pj-apply fun cmd-number prefix arg)
(setq tmp (format "Unknown MESSAGE: [%s] [%s] [%s]\n"
prefix cmd (prin1-to-string arg)))
(message tmp)
(irchat-insert0 tmp))))))
(set-buffer obuf)))
(defun irchat-pj-parser (proc)
"Parser function for IRC connection."
(let* ((str (buffer-substring (point-min) (point-max)))
(cs (pure-cs-detect-string
str irchat-pj-cs-8bit-coding-system irchat-pj-cs-detect-function)))
(save-excursion
(set-buffer irchat-pj-debug-buffer)
(goto-char (point-max))
(insert str "\n"))
(if (eq cs pure-cs-default-coding-system)
(setq str (pure-cs-decode-string str cs))
(pure-cs-hide-region (point-min) (point-max))
(pure-cs-unhide-region (point-min) (point-max) cs)
(pure-cs-buffer-multibyte)
(setq str (buffer-substring (point-min) (point-max)))
(pure-cs-buffer-unibyte))
(irchat-handle str)))
(defun irchat-sentinel (proc status)
"Sentinel function for IRC server process."
(and irchat-server-process
(not (irchat-server-opened))
(cond ((or irchat-reconnect-automagic irchat-reconnect-with-password)
(or (and irchat-grow-tail
(not irchat-reconnect-with-password)
(setq irchat-nickname (concat irchat-nickname irchat-grow-tail))
(irchat 'always))
(irchat)))
(irchat-fatal-error-message
(error (format "IRC ERROR: %s" irchat-fatal-error-message)))
((process-id proc)
(irchat-sentinel2 proc status))
(t
(error (format "IRC ERROR: Connection closed. (%s)"
(substring status 0 (1- (length status)))))))))
(defun irchat-sentinel2 (proc status)
(if (string-match "^exited abnormally with code \\([0-9]+\\)" status)
(let ((status (string-to-int (match-string 1 status))))
(cond
((= 99 status);; unsupported command
(error (format "IRC ERROR: Please use a newer \"%s\"."
irchat-pj-dcc-program)))
((= 98 status);; bad argment number
(error (format "IRC ERROR: Please use a newer \"%s\"."
irchat-pj-dcc-program)))
((= 97 status)
(error (format "IRC ERROR: Cannot connect to IRC server.")))
(t
(error (format "IRC ERROR: Server connection closed.")))))
(error (format "IRC ERROR: Connection closed. (%s)"
(substring status 0 (1- (length status)))))))
;; That's all
(provide 'irchat-filter)
;;;
;;; eof
;;;