Commits

Anonymous committed b7d07e4

Finally commit a version of the pgg-parse.el change that runs on non-mule

Comments (0)

Files changed (2)

+2011-03-12  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* pgg-parse.el (pgg-parse-crc24, pgg-parse-crc24-string):
+	Call #'define-ccl-program at compile time, if available, not at
+	runtime. Addresses Marcus Crestani's problem of
+	http://mid.gmane.org/vpdhcif81o9.fsf@informatik.uni-tuebingen.de .
+
 2009-02-02  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.07 released.
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl) (when (featurep 'mule) (require 'ccl)))
 
 (defgroup pgg-parse ()
   "OpenPGP packet parsing."
 (defmacro pgg-set-alist (alist key value)
   `(setq ,alist (nconc ,alist (list (cons ,key ,value)))))
 
-(when (fboundp 'define-ccl-program)
+(defconst pgg-parse-crc24 
+  (eval-when-compile
+    (let ((pre-existing
+	   [1 30 14 114744 114775 0 161 131127 1 148217 15 82167 1 1848
+	   131159 1 1595 5 256 114743 390 114775 19707 1467 16 7 183 1 -5628
+	   -7164 22]))
+      (when (fboundp 'ccl-compile)
+	(assert
+	 (equal
+	  pre-existing
+	  (ccl-compile 
+	   '(1
+	     ((loop
+		(read r0) (r1 ^= r0) (r2 ^= 0)
+		(r5 = 0)
+		(loop
+		  (r1 <<= 1)
+		  (r1 += ((r2 >> 15) & 1))
+		  (r2 <<= 1)
+		  (if (r1 & 256)
+		      ((r1 ^= 390) (r2 ^= 19707)))
+		  (if (r5 < 7)
+		      ((r5 += 1)
+		       (repeat))))
+		(repeat))))))
+	 nil
+	 "The pre-compiled CCL program appears broken, or the implementation
+of `ccl-compile' has changed compared to when this code was written.  "))
+      pre-existing))
+  "A CCL program to parse CRC 24 checksums.  See `define-ccl-program'.")
 
-  (define-ccl-program pgg-parse-crc24
-    '(1
-      ((loop
-	(read r0) (r1 ^= r0) (r2 ^= 0)
-	(r5 = 0)
-	(loop
-	 (r1 <<= 1)
-	 (r1 += ((r2 >> 15) & 1))
-	 (r2 <<= 1)
-	 (if (r1 & 256)
-	     ((r1 ^= 390) (r2 ^= 19707)))
-	 (if (r5 < 7)
-	     ((r5 += 1)
-	      (repeat))))
-	(repeat)))))
+(if (fboundp 'register-ccl-program)
+    (put 'pgg-parse-crc24 'ccl-program-idx
+         (register-ccl-program 'pgg-parse-crc24 pgg-parse-crc24)))
 
-  (defun pgg-parse-crc24-string (string)
+(defun pgg-parse-crc24-string (string)
+  (when (fboundp 'ccl-execute-on-string)
     (let ((h (vector nil 183 1230 nil nil nil nil nil nil)))
       (ccl-execute-on-string pgg-parse-crc24 h string)
       (format "%c%c%c"