;;; pure-vs.el --- Generic function and loader for PURE version-string module

;; Copyright (C) 2000 by Project Pure.

;; Author: SHIMADA Mitsunobu <simm@pure.fan.gr.jp>
;; Keywords: PURE, version-string

;; $Id: pure-vs.el,v 1.7.2.3 2001/12/12 16:34:15 simm Exp $

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; PURE means "Primitive Universal Relay-chat Environment."
;; VS means version-string

;;; Code:

;;
;; PURE version string
;;

(defconst pure-version-major 0
  "Major version number of PURE current version")
;(defconst pure-version-minor 0
;  "Minor version number of PURE current version")
(defconst pure-version-branch 6
  "Branch number of PURE current version")
(defconst pure-version-number
  (if (boundp 'pure-version-minor)
      (format "%d.%d.%d" pure-version-major pure-version-minor pure-version-branch)
    (format "%d.%d" pure-version-major pure-version-branch))
  "Version number string of PURE")

(defconst pure-version-suffix 2
  "PURE version name suffix.
  NIL   : Package release version
  Number: Patch level to the release version
  String: CVS version
    \"c\": main trunk of CVS version
    \"m\": minesweepers' version (simm's working branch)")
(defconst pure-version-string
  (cond
   ((null pure-version-suffix)
    (concat pure-version-number "p"))
   ((numberp pure-version-suffix)
    (concat pure-version-number "pl" (number-to-string pure-version-suffix)))
   ((stringp pure-version-suffix)
    (concat pure-version-number pure-version-suffix)))
  "Version string of PURE current version")

;;
;; Emacs version string
;;

(defvar pure-vs-fsf-string
  (cond ((string-match "^\\([0-9]+\\.[0-9]+\\.[0-9]+\\)\\.[0-9]+" emacs-version)
	 (substring emacs-version (match-beginning 1) (match-end 1)))
	((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[0-9]+" emacs-version)
	 (substring emacs-version (match-beginning 1) (match-end 1)))
	(t emacs-version))
  "FSF Emacs version string")

(defconst pure-vs-xmas
  (if (featurep 'xemacs)
      (let* ((vs-emacs
	      (if (string-match " " emacs-version)
		  (substring emacs-version 0 (match-beginning 0))
		emacs-version))
	     (vs-beta
	      (and (stringp xemacs-betaname)
		   (concat vs-emacs "-"
			   (substring xemacs-betaname 1 (1- (length xemacs-betaname))))))
	     (vs-patch
	      (and (numberp emacs-patch-level)
		   (format "%s-patch%d" vs-emacs emacs-patch-level)))
	     (vs-mule (featurep 'mule))
	     (vs-utf2000
	      (and (featurep 'utf-2000)
		   (or (and (boundp 'utf-2000-version)
			    (string-match " " utf-2000-version)
			    (substring utf-2000-version 0 (match-beginning 0)))
		       utf-2000-version)))
	     (vs-addition
	      (if (boundp 'xemacs-codename)
		  (format "\"%s\" (%s)" xemacs-codename system-configuration)
		(concat "(" system-configuration ")"))))
	(cond (vs-utf2000
	       (format "UTF-200-Mule/%s (%s) [XEmacs/%s \"%s\"]"
		       vs-utf2000
		       system-configuration
		       (or vs-beta vs-patch vs-emacs)
		       xemacs-codename))
	      (vs-mule
	       (format "XEmacs-MULE/%s %s" (or vs-beta vs-patch vs-emacs) vs-addition))
	      (t (format "XEmacs/%s %s" (or vs-beta vs-patch vs-emacs) vs-addition)))))
  "XEmacs version string for PURE")

(defconst pure-vs-emacs
  (cond ((featurep 'xemacs)
	 pure-vs-xmas)
	((featurep 'meadow)
	 (let ((vs-meadow
		(if (featurep 'meadow)
		    (let ((meadow-version (Meadow-version)))
		      (if (string-match "^Meadow-" meadow-version)
			  (substring meadow-version (match-end 0))
			meadow-version))
		  nil)))
	   (format "Meadow/%s (%s) [Emacs/%s,Mule/%s]"
		   vs-meadow system-configuration pure-vs-fsf-string mule-version)))
	((and (boundp 'emacs-major-version) (<= 20 emacs-major-version))
	 (let ((vs-mule (and (boundp 'mule-version)
			     (boundp 'enable-multibyte-characters)
			     enable-multibyte-characters
			     mule-version)))
	   (if vs-mule
	       (format "Emacs/%s (%s) Mule/%s"
		       pure-vs-fsf-string system-configuration vs-mule)
	     (if (boundp 'system-configuration)
		 (format "Emacs/%s (%s)" pure-vs-fsf-string system-configuration)
	       (concat "Emacs/" pure-vs-fsf-string)))))
	((featurep 'mule)
	 (let ((vs-mule (and (boundp 'mc-flag) mc-flag mule-version)))
	   (if vs-mule
	       (format "Emacs/%s (%s) Mule/%s" pure-vs-fsf-string system-configuration vs-mule)
	     (if (boundp 'system-configuration)
		 (format "Emacs/%s (%s)" pure-vs-fsf-string system-configuration)
	       (concat "Emacs/" pure-vs-fsf-string)))))
	((boundp 'NEMACS)
	 (format "NEmacs %s [Emacs %s]" nemacs-version emacs-version))
	(t (or (and (boundp 'system-configuration)
		    (stringp system-configuration)
		    (format "Emacs %s (%s)" emacs-version system-configuration))
	       (format "Emacs %s" emacs-version))))
  "Emacs version string for PURE")

;;
;; Make version string
;;

(defvar pure-vs-make-hook nil
  "Hook for pure-vs-make. This is used in Rail library.")

(defun pure-vs-make-emacs ()
  "Make Emacs version string (internal)"
  (run-hooks 'pure-vs-make-hook)
  pure-vs-emacs)

(defun pure-vs-make (&optional client)
  "Make version string (internal)"
  (run-hooks 'pure-vs-make-hook)
  (format "%sPure/%s on %s"
	  (if (stringp client) (concat client " ") "")
	  pure-version-string pure-vs-emacs))

;; That's all
(provide 'pure-vs)

;;; pure-vs.el ends here