6ba85fdc47427d94e7f2bebf1dbf6080663c49cc
[elisp/wanderlust.git] / wl / wl-version.el
1 ;;; wl-version.el -- Version information for Wanderlust.
2
3 ;; Copyright (C) 2000-2001 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 2000-2001 TAKAHASHI Kaoru <kaoru@kaisei.org>
5
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;;      TAKAHASHI Kaoru <kaoru@kaisei.org>
8 ;; Keywords: mail, net news
9
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
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 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.
26 ;;
27
28 ;;; Commentary:
29 ;;
30 ;; Put the following lines to each file of Wanderlust package.
31 ;;
32 ;; (require 'product)
33 ;; (product-provide (provide FEATURE) (require 'wl-version))
34
35 ;;; Code:
36 ;;
37 (require 'product)
38 (require 'elmo-version)                 ; product-version-as-string
39 (eval-when-compile
40   (require 'elmo-util))                 ; elmo-match-string
41 (provide 'wl-version)                   ; before product-provide
42
43 ;; product-define in the first place
44 (product-provide 'wl-version
45   (product-define
46    "Wanderlust" nil
47    (eval-when-compile
48      (product-version (product-find 'elmo-version))) ; equals to ELMO version.
49    "Upside Down"))
50
51 ;; set version-string
52 (product-version-as-string 'wl-version)
53
54 ;; Don't support insert string at-point (C-u M-x wl-version).
55 ;; For bug report, use `wl-generate-user-agent-string-1' instead.
56 ;; When non-interactive, use `product-string-1' instead.
57 (defun wl-version ()
58   "Print Wanderlust version."
59   (interactive)
60   (let ((product-info (product-string-1 'wl-version t)))
61     (if (interactive-p)
62         (message "%s" product-info)
63       product-info)))
64
65 (defvar wl-version-status-alist
66   '(((zerop (% (nth 1 (product-version (product-find 'wl-version))) 2))
67      . "stable")
68     (t . "beta"))
69   "An alist to define the version status.")
70
71 (defun wl-version-status ()
72   "Return version status (\"stable\" or \"beta\")."
73   (let ((salist wl-version-status-alist)
74         status)
75     (while salist
76       (when (eval (car (car salist)))
77         (setq status (cdr (car salist)))
78         (setq salist nil))
79       (setq salist (cdr salist)))
80     status))
81
82 ;; avoid compile warnings
83 (defvar mule-version)
84 (defvar nemacs-version)
85 (defvar emacs-beta-version)
86 (defvar xemacs-codename)
87 (defvar mime-edit-insert-user-agent-field)
88 (defvar mime-edit-user-agent-value)
89 (defvar mime-editor/version)
90 (defvar mime-editor/codename)
91
92 (defun wl-generate-user-agent-string ()
93   "A candidate of `wl-generate-mailer-string-func'.
94 Insert User-Agent field instead of X-Mailer field."
95   (concat "User-Agent: "
96           (wl-generate-user-agent-string-1
97            ;; for backward compatibility
98            (or (and (boundp 'mime-edit-insert-user-agent-field)
99                     mime-edit-insert-user-agent-field) ; SEMI
100                (and (boundp 'mime-editor/version)
101                     mime-editor/version))))) ; verbose User-Agent when tm
102
103 (defun wl-generate-user-agent-string-1 (&optional verbose)
104   "Return User-Agent field value.
105 If VERBOSE return with SEMI, FLIM and APEL version."
106   (cond
107    ;; Don't use `product-string-verbose' for short User-Agent field value.
108    ((not verbose)
109     (concat (product-string-1 'wl-version t) " "
110             (wl-extended-emacs-version3 "/" t)))
111    ;; SEMI (verbose)
112    ((and (boundp 'mime-edit-user-agent-value) mime-edit-user-agent-value)
113     (concat (product-string-verbose 'wl-version) " "
114             mime-edit-user-agent-value))
115    ;; tm (verbose)
116    ((and (boundp 'mime-editor/version) mime-editor/version)
117     (concat (product-string-verbose 'wl-version) " "
118             "tm/" mime-editor/version
119             (when (and (boundp 'mime-editor/codename) mime-editor/codename)
120               (concat " (" mime-editor/codename ")"))
121             (when (and (boundp 'mime-library-product) mime-library-product)
122               (concat " " (aref mime-library-product 0)
123                       "/" (mapconcat 'int-to-string
124                                      (aref mime-library-product 1)
125                                      ".")
126                       " (" (aref mime-library-product 2) ")"))
127             (condition-case nil
128                 (progn
129                   (require 'apel-ver)
130                   (concat " " (apel-version)))
131               (file-error nil))
132             " " (wl-extended-emacs-version3 "/" t)))
133    ;; error case
134    (t
135     (product-string-1 'wl-version nil))))
136
137 ;; from gnus
138 (defun wl-extended-emacs-version (&optional with-codename)
139   "Stringified Emacs version.
140 If WITH-CODENAME add XEmacs codename."
141   (cond
142    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
143     (concat "Emacs " (elmo-match-string 1 emacs-version)
144             (when (boundp 'mule-version) (concat "/Mule " mule-version))))
145    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
146                   emacs-version)
147     (concat (elmo-match-string 1 emacs-version)
148             (format " %d.%d" emacs-major-version emacs-minor-version)
149             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
150               (format "b%d" emacs-beta-version))
151             (when (and with-codename
152                        (boundp 'xemacs-codename) xemacs-codename)
153               (concat " - \"" xemacs-codename "\""))))
154    (t emacs-version)))
155
156 (defun wl-extended-emacs-version2 (&optional delimiter with-codename)
157   "Stringified Emacs version.
158 Separate DELIMITER (default is \" \").  If WITH-CODENAME add XEmacs codename."
159   (cond
160    ((and (boundp 'mule-version) mule-version
161          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
162     (format "Mule%s%s@%d.%d%s"
163             (or delimiter " ")
164             (elmo-match-string 1 mule-version)
165             emacs-major-version
166             emacs-minor-version
167             (if with-codename
168                 (elmo-match-string 2 mule-version)
169               "")))
170    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
171     (if (boundp 'nemacs-version)
172         (concat "Nemacs" (or delimiter " ")
173                 nemacs-version
174                 "@"
175                 (substring emacs-version
176                            (match-beginning 1)
177                            (match-end 1)))
178       (concat "Emacs" (or delimiter " ")
179               (elmo-match-string 1 emacs-version))))
180    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
181                   emacs-version)
182     (concat (elmo-match-string 1 emacs-version)
183             (or delimiter " ")
184             (format "%d.%d" emacs-major-version emacs-minor-version)
185             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
186               (format "b%d" emacs-beta-version))
187             (when (and with-codename
188                        (boundp 'xemacs-codename) xemacs-codename)
189               (format " (%s)" xemacs-codename))))
190    (t emacs-version)))
191
192 (defun wl-extended-emacs-version3 (&optional delimiter with-codename)
193   "Stringified Emacs version.
194 Separate DELIMITER (default is \" \").  If WITH-CODENAME add XEmacs codename."
195   (cond
196    ((and (boundp 'mule-version) mule-version
197          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
198     (format "Emacs%s%d.%d Mule%s%s%s"
199             (or delimiter " ")
200             emacs-major-version
201             emacs-minor-version
202             (or delimiter " ")
203             (elmo-match-string 1 mule-version)
204             (if with-codename
205                 (elmo-match-string 2 mule-version)
206               "")))
207    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
208     (if (boundp 'nemacs-version)
209         (let ((nemacs-codename-assoc '(("3.3.2" . " (FUJIMUSUME)")
210                                        ("3.3.1" . " (HINAMATSURI)")
211                                        ("3.2.3" . " (YUMENO-AWAYUKI)"))))
212           (format "Emacs%s%s Nemacs%s%s%s"
213                   (or delimiter " ")
214                   (elmo-match-string 1 emacs-version)
215                   (or delimiter " ")
216                   nemacs-version
217                   (or (and with-codename
218                            (cdr (assoc nemacs-version
219                                        nemacs-codename-assoc)))
220                       "")))
221       (concat "Emacs" (or delimiter " ")
222               (elmo-match-string 1 emacs-version))))
223    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
224                   emacs-version)
225     (concat (elmo-match-string 1 emacs-version)
226             (or delimiter " ")
227             (format "%d.%d" emacs-major-version emacs-minor-version)
228             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
229               (format "b%d" emacs-beta-version))
230             (when (and with-codename
231                        (boundp 'xemacs-codename) xemacs-codename)
232               (format " (%s)" xemacs-codename))))
233    (t emacs-version)))
234
235
236 ;; for backward compatibility
237 (defconst wl-appname (product-name (product-find 'wl-version)))
238 (make-obsolete-variable
239  'wl-appname
240  "use (product-name (product-find 'wl-version)) insteaed.")
241
242 (defconst wl-version (product-version-string (product-find 'wl-version)))
243 (make-obsolete-variable
244  'wl-version
245  "use (product-version-string (product-find 'wl-version)) instead.")
246
247 (defconst wl-codename (product-code-name (product-find 'wl-version)))
248 (make-obsolete-variable
249  'wl-codename
250  "use (product-code-name (product-find 'wl-version)) instead.")
251
252 ;;; wl-version.el ends here