Applied patch from Tsuyoshi Kitamoto <tsuyoshi.kitamoto@city.sapporo.jp>.
[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    "Too Funky"))
50
51 (defconst wl-version-status nil
52   "Wanderlust verstion status.  For override default rule.
53 If nil, use default rule.")
54
55 \f
56 ;; set version-string
57 (product-version-as-string 'wl-version)
58
59 ;; Don't support insert string at-point (C-u M-x wl-version).
60 ;; For bug report, use `wl-generate-user-agent-string-1' instead.
61 ;; When non-interactive, use `product-string-1' instead.
62 (defun wl-version ()
63   "Print Wanderlust version."
64   (interactive)
65   (let ((product-info (product-string-1 'wl-version t)))
66     (if (interactive-p)
67         (message "%s" product-info)
68       product-info)))
69
70 (defun wl-version-status ()
71   "Return version status string."
72   (or wl-version-status
73       (if (zerop (% (nth 1 (product-version (product-find 'wl-version))) 2))
74           "stable"
75         "beta")))
76
77 ;; avoid compile warnings
78 (defvar mule-version)
79 (defvar nemacs-version)
80 (defvar emacs-beta-version)
81 (defvar xemacs-codename)
82 (defvar mime-edit-insert-user-agent-field)
83 (defvar mime-edit-user-agent-value)
84 (defvar mime-editor/version)
85 (defvar mime-editor/codename)
86
87 (defun wl-generate-user-agent-string ()
88   "A candidate of `wl-generate-mailer-string-function'.
89 Insert User-Agent field instead of X-Mailer field."
90   (concat "User-Agent: "
91           (wl-generate-user-agent-string-1
92            ;; for backward compatibility
93            (or (and (boundp 'mime-edit-insert-user-agent-field)
94                     mime-edit-insert-user-agent-field) ; SEMI
95                (and (boundp 'mime-editor/version)
96                     mime-editor/version))))) ; verbose User-Agent when tm
97
98 (defun wl-generate-user-agent-string-1 (&optional verbose)
99   "Return User-Agent field value.
100 If VERBOSE return with SEMI, FLIM and APEL version."
101   (cond
102    ;; Don't use `product-string-verbose' for short User-Agent field value.
103    ((not verbose)
104     (concat (product-string-1 'wl-version t) " "
105             (wl-extended-emacs-version3 "/" t)))
106    ;; SEMI (verbose)
107    ((and (boundp 'mime-edit-user-agent-value) mime-edit-user-agent-value)
108     (concat (product-string-verbose 'wl-version) " "
109             mime-edit-user-agent-value))
110    ;; tm (verbose)
111    ((and (boundp 'mime-editor/version) mime-editor/version)
112     (concat (product-string-verbose 'wl-version) " "
113             "tm/" mime-editor/version
114             (when (and (boundp 'mime-editor/codename) mime-editor/codename)
115               (concat " (" mime-editor/codename ")"))
116             (when (and (boundp 'mime-library-product) mime-library-product)
117               (concat " " (aref mime-library-product 0)
118                       "/" (mapconcat 'int-to-string
119                                      (aref mime-library-product 1)
120                                      ".")
121                       " (" (aref mime-library-product 2) ")"))
122             (condition-case nil
123                 (progn
124                   (require 'apel-ver)
125                   (concat " " (apel-version)))
126               (file-error nil))
127             " " (wl-extended-emacs-version3 "/" t)))
128    ;; error case
129    (t
130     (product-string-1 'wl-version nil))))
131
132 ;; from gnus
133 (defun wl-extended-emacs-version (&optional with-codename)
134   "Stringified Emacs version.
135 If WITH-CODENAME add XEmacs codename."
136   (cond
137    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
138     (concat "Emacs " (elmo-match-string 1 emacs-version)
139             (when (boundp 'mule-version) (concat "/Mule " mule-version))))
140    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
141                   emacs-version)
142     (concat (elmo-match-string 1 emacs-version)
143             (format " %d.%d" emacs-major-version emacs-minor-version)
144             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
145               (format "b%d" emacs-beta-version))
146             (when (and with-codename
147                        (boundp 'xemacs-codename) xemacs-codename)
148               (concat " - \"" xemacs-codename "\""))))
149    (t emacs-version)))
150
151 (defun wl-extended-emacs-version2 (&optional delimiter with-codename)
152   "Stringified Emacs version.
153 Separate DELIMITER (default is \" \").  If WITH-CODENAME add XEmacs codename."
154   (cond
155    ((and (boundp 'mule-version) mule-version
156          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
157     (format "Mule%s%s@%d.%d%s"
158             (or delimiter " ")
159             (elmo-match-string 1 mule-version)
160             emacs-major-version
161             emacs-minor-version
162             (if with-codename
163                 (elmo-match-string 2 mule-version)
164               "")))
165    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
166     (if (boundp 'nemacs-version)
167         (concat "Nemacs" (or delimiter " ")
168                 nemacs-version
169                 "@"
170                 (substring emacs-version
171                            (match-beginning 1)
172                            (match-end 1)))
173       (concat "Emacs" (or delimiter " ")
174               (elmo-match-string 1 emacs-version))))
175    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
176                   emacs-version)
177     (concat (elmo-match-string 1 emacs-version)
178             (or delimiter " ")
179             (format "%d.%d" emacs-major-version emacs-minor-version)
180             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
181               (format "b%d" emacs-beta-version))
182             (when (and with-codename
183                        (boundp 'xemacs-codename) xemacs-codename)
184               (format " (%s)" xemacs-codename))))
185    (t emacs-version)))
186
187 (defun wl-extended-emacs-version3 (&optional delimiter with-codename)
188   "Stringified Emacs version.
189 Separate DELIMITER (default is \" \").  If WITH-CODENAME add XEmacs codename."
190   (cond
191    ((and (boundp 'mule-version) mule-version
192          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
193     (format "Emacs%s%d.%d Mule%s%s%s"
194             (or delimiter " ")
195             emacs-major-version
196             emacs-minor-version
197             (or delimiter " ")
198             (elmo-match-string 1 mule-version)
199             (if with-codename
200                 (elmo-match-string 2 mule-version)
201               "")))
202    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
203     (if (boundp 'nemacs-version)
204         (let ((nemacs-codename-assoc '(("3.3.2" . " (FUJIMUSUME)")
205                                        ("3.3.1" . " (HINAMATSURI)")
206                                        ("3.2.3" . " (YUMENO-AWAYUKI)"))))
207           (format "Emacs%s%s Nemacs%s%s%s"
208                   (or delimiter " ")
209                   (elmo-match-string 1 emacs-version)
210                   (or delimiter " ")
211                   nemacs-version
212                   (or (and with-codename
213                            (cdr (assoc nemacs-version
214                                        nemacs-codename-assoc)))
215                       "")))
216       (concat "Emacs" (or delimiter " ")
217               (elmo-match-string 1 emacs-version))))
218    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
219                   emacs-version)
220     (concat (elmo-match-string 1 emacs-version)
221             (or delimiter " ")
222             (format "%d.%d" emacs-major-version emacs-minor-version)
223             (when (and (boundp 'emacs-beta-version) emacs-beta-version)
224               (format "b%d" emacs-beta-version))
225             (when (and with-codename
226                        (boundp 'xemacs-codename) xemacs-codename)
227               (format " (%s)" xemacs-codename))))
228    (t emacs-version)))
229
230
231 ;; for backward compatibility
232 (defconst wl-appname (product-name (product-find 'wl-version)))
233 (make-obsolete-variable
234  'wl-appname
235  "use (product-name (product-find 'wl-version)) insteaed.")
236
237 (defconst wl-version (product-version-string (product-find 'wl-version)))
238 (make-obsolete-variable
239  'wl-version
240  "use (product-version-string (product-find 'wl-version)) instead.")
241
242 (defconst wl-codename (product-code-name (product-find 'wl-version)))
243 (make-obsolete-variable
244  'wl-codename
245  "use (product-code-name (product-find 'wl-version)) instead.")
246
247 ;;; wl-version.el ends here