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