1 ;;; mailcap.el --- mailcap parser
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Version: $Id: mailcap.el,v 0.0 1997-06-27 10:15:46 morioka Exp $
8 ;; Keywords: mailcap, setting, configuration, MIME, multimedia
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
32 (defsubst mailcap-skip-comment ()
33 (let ((chr (char-after (point))))
43 (defsubst mailcap-look-at-token ()
44 (if (looking-at mime/token-regexp)
45 (let ((beg (match-beginning 0))
48 (buffer-substring beg end)
55 (defsubst mailcap-look-at-type-field ()
56 (let ((type (mailcap-look-at-token)))
58 (eq (char-after (point)) ?/)
62 (let ((subtype (mailcap-look-at-token)))
64 (cons (cons 'type type)
65 (unless (string= subtype "*")
66 (list (cons 'subtype subtype))
73 (defsubst mailcap-skip-field-separator ()
74 (let ((ret (looking-at "\\([ \t]\\|\\\\\n\\)*;\\([ \t]\\|\\\\\n\\)*")))
76 (goto-char (match-end 0))
83 (defsubst mailcap-look-at-schar ()
84 (let ((chr (char-after (point))))
93 (defsubst mailcap-look-at-qchar ()
94 (let ((chr (char-after (point))))
100 (defsubst mailcap-look-at-mtext ()
102 (while (or (mailcap-look-at-schar)
103 (mailcap-look-at-schar)))
104 (buffer-substring beg (point))
111 (defsubst mailcap-look-at-field ()
112 (let ((token (mailcap-look-at-token)))
114 (if (eq (char-after (point)) ?=)
117 (mailcap-look-at-mtext))))
128 (defun mailcap-look-at-entry ()
129 (let ((type (mailcap-look-at-type-field)))
130 (if (and type (mailcap-skip-field-separator))
131 (let ((view (mailcap-look-at-mtext))
134 (while (and (mailcap-skip-field-separator)
135 (setq field (mailcap-look-at-field))
137 (setq fields (cons field fields))
140 (list (cons 'view view))
147 (defun mailcap-parse-buffer (&optional buffer order)
148 "Parse BUFFER as a mailcap, and return the result.
149 If optional argument ORDER is a function, result is sorted by it.
150 If optional argument ORDER is not specified, result is sorted original
151 order. Otherwise result is not sorted."
155 (goto-char (point-min))
158 (while (mailcap-skip-comment))
159 (setq entry (mailcap-look-at-entry))
161 (setq entries (cons entry entries))
164 (cond ((functionp order) (sort entries order))
165 ((null order) (nreverse entries))
175 ;;; mailcap.el ends here