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