Update for new add-on API.
[riece] / lisp / riece-mode.el
1 ;;; riece-mode.el --- functions for manipulating channel/user modes
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (defun riece-parse-modes (string)
28   (let ((start 0)
29         result)
30     (while (and (string-match "[-+]\\([^ ]*\\) *" string start)
31                 (= (match-beginning 0) start))
32       (let ((toggle (eq (aref string 0) ?+))
33             (modes (string-to-list (match-string 1 string))))
34         (setq start (match-end 0))
35         (while modes
36           (if (and (string-match "\\([^-+][^ ]*\\) *" string start)
37                    (= (match-beginning 0) start))
38               (setq start (match-end 0)
39                     result (cons (list (riece-make-mode
40                                         (car modes) (match-string 1 string))
41                                        toggle)
42                                  result))
43             (setq result (cons (list (riece-make-mode (car modes))
44                                      toggle)
45                                result)))
46           (setq modes (cdr modes)))))
47     (nreverse result)))
48
49 (defun riece-mode-assoc (flag modes)
50   "Return a mode object matched with FLAG in MODES."
51   (catch 'found
52     (while modes
53       (if (eq flag (riece-mode-flag (car modes)))
54           (throw 'found (car modes)))
55       (setq modes (cdr modes)))))
56
57 (defun riece-make-mode (flag &optional parameter)
58   "Make an instance of mode object.
59 Arguments are appropriate to the flag and the parameter."
60   (vector flag parameter))
61
62 (defun riece-mode-flag (mode)
63   "Return the flag of MODE."
64   (aref mode 0))
65
66 (defun riece-mode-parameter (mode)
67   "Return the parameter of MODE."
68   (aref mode 1))
69
70 (provide 'riece-mode)
71
72 ;;; riece-mode.el ends here