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