From 214e5ad332002559546cf83e950255ebf420d7a9 Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 4 Sep 2006 02:50:29 +0000 Subject: [PATCH] * epg-config.el (epg-gpg-minimum-version): New constant. (epg-config--parse-version): New function. (epg-config--compare-version): New function. --- ChangeLog | 6 ++++++ epg-config.el | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 356eb01..359cecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-09-04 Daiki Ueno + + * epg-config.el (epg-gpg-minimum-version): New constant. + (epg-config--parse-version): New function. + (epg-config--compare-version): New function. + 2006-09-03 Daiki Ueno * epg-config.el: New file; moved GnuPG configuration check from diff --git a/epg-config.el b/epg-config.el index 0da6ea1..c3b31e3 100644 --- a/epg-config.el +++ b/epg-config.el @@ -44,6 +44,8 @@ (defconst epg-version-number "0.0.4") +(defconst epg-gpg-minimum-version "1.4.3") + ;;;###autoload (defun epg-configuration () "Return a list of internal configuration parameters of `epg-gpg-program'." @@ -65,24 +67,36 @@ config)))) config)) +(defun epg-config--parse-version (string) + (let ((index 0) + version) + (while (eq index (string-match "\\([0-9]+\\)\\.?" string index)) + (setq version (cons (string-to-number (match-string 1 string)) + version) + index (match-end 0))) + (nreverse version))) + +(defun epg-config--compare-version (v1 v2) + (while (and v1 v2 (= (car v1) (car v2))) + (setq v1 (cdr v1) + v2 (cdr v2))) + (setq v1 (or (car v1) 0) + v2 (or (car v2) 0)) + (if (> v1 v2) 1 (if (= v1 v2) 0 -1))) + ;;;###autoload -(defun epg-check-configuration (config) - "Verify that CONFIGURATION is sufficient." +(defun epg-check-configuration (config &optional minimum-version) + "Verify that a sufficient version of GnuPG is installed." (let ((entry (assq 'version config)) - major minor teeny) + version) (unless (and entry - (stringp (cdr entry)) - (string-match "\\`\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)" - (cdr entry))) + (stringp (cdr entry))) (error "Undetermined version: %S" entry)) - (setq major (string-to-number (match-string 1 (cdr entry))) - minor (string-to-number (match-string 2 (cdr entry))) - teeny (string-to-number (match-string 3 (cdr entry)))) - (unless (or (> major 1) - (and (= major 1) - (or (> minor 4) - (and (= minor 4) - (>= teeny 3))))) + (setq version (epg-config--parse-version (cdr entry)) + minimum-version (epg-config--parse-version + (or minimum-version + epg-gpg-minimum-version))) + (unless (>= (epg-config--compare-version version minimum-version) 0) (error "Unsupported version: %s" (cdr entry))))) (provide 'epg-config) -- 1.7.10.4