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