Fixed docstring.
[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: " (wl-generate-user-agent-string-1 t)))
94
95 (defun wl-generate-user-agent-string-1 (&optional verbose)
96   "Return User-Agent field value.
97 If VERBOSE return with SEMI, FLIM and APEL version"
98   (let ((mime-user-agent (and (boundp 'mime-edit-insert-user-agent-field)
99                               mime-edit-insert-user-agent-field
100                               mime-edit-user-agent-value)))
101     (if (and verbose mime-user-agent)
102         (concat (product-string-verbose 'wl-version) " "
103                 mime-user-agent)
104       (if (and verbose
105                (boundp 'mime-editor/version)
106                mime-editor/version)
107           (concat (product-string-verbose 'wl-version) " "
108                   "tm/" mime-editor/version
109                   (if (and (boundp 'mime-editor/codename)
110                            mime-editor/codename)
111                       (concat " (" mime-editor/codename ")"))
112                   (if (and (boundp 'mime-library-product)
113                            mime-library-product)
114                       (concat " " (aref mime-library-product 0)
115                               "/"
116                               (mapconcat 'int-to-string
117                                          (aref mime-library-product 1)
118                                          ".")
119                               " (" (aref mime-library-product 2) ")"))
120                   (condition-case nil
121                       (progn
122                         (require 'apel-ver)
123                         (concat " " (apel-version)))
124                     (file-error nil))
125                   " " (wl-extended-emacs-version3 "/" t))
126         ;; Don't use product-string-verbose for short User-Agent field.
127         (concat (product-string-1 'wl-version t) " "
128                 (wl-extended-emacs-version3 "/" t))))))
129
130 ;; from gnus
131 (defun wl-extended-emacs-version (&optional with-codename)
132   "Stringified Emacs version.
133 If WITH-CODENAME add XEmacs codename."
134   (cond
135    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
136     (concat "Emacs " (wl-match-string 1 emacs-version)
137             (and (boundp 'mule-version)(concat "/Mule " mule-version))))
138    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
139                   emacs-version)
140     (concat (wl-match-string 1 emacs-version)
141             (format " %d.%d" emacs-major-version emacs-minor-version)
142             (if (and (boundp 'emacs-beta-version)
143                      emacs-beta-version)
144                 (format "b%d" emacs-beta-version))
145             (if with-codename
146                 (if (boundp 'xemacs-codename)
147                     (concat " - \"" xemacs-codename "\"")))))
148    (t emacs-version)))
149
150 (defun wl-extended-emacs-version2 (&optional delimiter with-codename)
151   "Stringified Emacs version.
152 Separate DELIMITER (default it \" \").  If WITH-CODENAME add XEmacs codename."
153   (cond
154    ((and (boundp 'mule-version)
155          mule-version
156          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
157     (format "Mule%s%s@%d.%d%s"
158             (or delimiter " ")
159             (wl-match-string 1 mule-version)
160             emacs-major-version
161             emacs-minor-version
162             (if with-codename
163                 (wl-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               (wl-match-string 1 emacs-version))))
175    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
176                   emacs-version)
177     (concat (wl-match-string 1 emacs-version)
178             (or delimiter " ")
179             (format "%d.%d" emacs-major-version emacs-minor-version)
180             (if (and (boundp 'emacs-beta-version)
181                      emacs-beta-version)
182                 (format "b%d" emacs-beta-version))
183             (if (and with-codename
184                      (boundp 'xemacs-codename)
185                      xemacs-codename)
186                 (format " (%s)" xemacs-codename))))
187    (t emacs-version)))
188
189 (defun wl-extended-emacs-version3 (&optional delimiter with-codename)
190   "Stringified Emacs version.
191 Separate DELIMITER (default it \" \").  If WITH-CODENAME add XEmacs codename."
192   (cond
193    ((and (boundp 'mule-version)
194          mule-version
195          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
196     (format "Emacs%s%d.%d Mule%s%s%s"
197             (or delimiter " ")
198             emacs-major-version
199             emacs-minor-version
200             (or delimiter " ")
201             (wl-match-string 1 mule-version)
202             (if with-codename
203                 (wl-match-string 2 mule-version)
204               "")))
205    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
206     (if (boundp 'nemacs-version)
207         (let ((nemacs-codename-assoc '(("3.3.2" . " (FUJIMUSUME)")
208                                        ("3.3.1" . " (HINAMATSURI)")
209                                        ("3.2.3" . " (YUMENO-AWAYUKI)"))))
210           (format "Emacs%s%s Nemacs%s%s%s"
211                   (or delimiter " ")
212                   (wl-match-string 1 emacs-version)
213                   (or delimiter " ")
214                   nemacs-version
215                   (or (and with-codename
216                            (cdr (assoc nemacs-version
217                                        nemacs-codename-assoc)))
218                       "")))
219       (concat "Emacs" (or delimiter " ")
220               (wl-match-string 1 emacs-version))))
221    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
222                   emacs-version)
223     (concat (wl-match-string 1 emacs-version)
224             (or delimiter " ")
225             (format "%d.%d" emacs-major-version emacs-minor-version)
226             (if (and (boundp 'emacs-beta-version)
227                      emacs-beta-version)
228                 (format "b%d" emacs-beta-version))
229             (if (and with-codename
230                      (boundp 'xemacs-codename)
231                      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