From: yamaoka Date: Sat, 13 Mar 2010 11:20:44 +0000 (+0000) Subject: 2010-03-10 Kazuhiro Ito X-Git-Tag: flim-1_14-wl-root~2 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4654556258fc0fef496ff895d116363366e62fd6;p=elisp%2Fflim.git 2010-03-10 Kazuhiro Ito * mel-q-ccl.el (quoted-printable-ccl-decode-string) (q-encoding-ccl-decode-string): Use ccl-execute-on-string() on Emacs 23.1. (quoted-printable-ccl-decode-region) (quoted-printable-ccl-write-decoded-region): Use quoted-printable-ccl-decode-string on Emacs 23.1. * mel-q.el (quoted-printable-num-to-raw-byte-char): New inline function. (quoted-printable-internal-decode-region) (q-encoding-decode-string): Use it. --- diff --git a/ChangeLog b/ChangeLog index 827ad73..140b85a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-03-10 Kazuhiro Ito + + * mel-q-ccl.el (quoted-printable-ccl-decode-string) + (q-encoding-ccl-decode-string): Use ccl-execute-on-string() on + Emacs 23.1. + (quoted-printable-ccl-decode-region) + (quoted-printable-ccl-write-decoded-region): Use + quoted-printable-ccl-decode-string on Emacs 23.1. + + * mel-q.el (quoted-printable-num-to-raw-byte-char): New inline + function. + (quoted-printable-internal-decode-region) + (q-encoding-decode-string): Use it. + 2010-02-18 Kazuhiro Ito * mel-q-ccl.el (quoted-printable-ccl-encode-string) diff --git a/mel-q-ccl.el b/mel-q-ccl.el index e44eea7..b121c75 100644 --- a/mel-q-ccl.el +++ b/mel-q-ccl.el @@ -949,27 +949,56 @@ abcdefghijklmnopqrstuvwxyz\ 'quoted-printable-ccl-insert-encoded-file) ) -(defun quoted-printable-ccl-decode-string (string) - "Decode quoted-printable encoded STRING." - (encode-coding-string - string - 'mel-ccl-quoted-printable-lf-lf-rev)) - -(defun quoted-printable-ccl-decode-region (start end) - "Decode the region from START to END with quoted-printable + (cond + ((eval-when-compile + (and (eq emacs-major-version 23) + (eq emacs-minor-version 1))) + (defun quoted-printable-ccl-decode-string (string) + "Decode quoted-printable encoded STRING." + (ccl-execute-on-string 'mel-ccl-decode-quoted-printable-lf-lf + (make-vector 9 0) string nil t)) + + (defun quoted-printable-ccl-decode-region (start end) + "Decode the region from START to END with quoted-printable +encoding." + (interactive "*r") + (save-excursion + (goto-char start) + (insert (prog1 (quoted-printable-ccl-decode-string + (buffer-substring start end)) + (delete-region start end))))) + + (defun quoted-printable-ccl-write-decoded-region (start end filename) + "Decode quoted-printable encoded current region and write out to FILENAME." + (interactive "*r\nFWrite decoded region to file: ") + (let ((string (quoted-printable-ccl-decode-string + (buffer-substring start end))) + (coding-system-for-write 'binary) + jka-compr-compression-info-list jam-zcat-filename-list) + (with-temp-file filename + (insert string))))) + (t + (defun quoted-printable-ccl-decode-string (string) + "Decode quoted-printable encoded STRING." + (encode-coding-string + string + 'mel-ccl-quoted-printable-lf-lf-rev)) + + (defun quoted-printable-ccl-decode-region (start end) + "Decode the region from START to END with quoted-printable encoding." - (interactive "*r") - (encode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev)) - -(defun quoted-printable-ccl-write-decoded-region (start end filename) - "Decode quoted-printable encoded current region and write out to FILENAME." - (interactive "*r\nFWrite decoded region to file: ") - (let ((coding-system-for-write - (if (coding-system-p 'mel-ccl-quoted-printable-lf-lf-rev-unix) - 'mel-ccl-quoted-printable-lf-lf-rev-unix - 'mel-ccl-quoted-printable-lf-lf-rev)) - jka-compr-compression-info-list jam-zcat-filename-list) - (write-region start end filename))) + (interactive "*r") + (encode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev)) + + (defun quoted-printable-ccl-write-decoded-region (start end filename) + "Decode quoted-printable encoded current region and write out to FILENAME." + (interactive "*r\nFWrite decoded region to file: ") + (let ((coding-system-for-write + (if (coding-system-p 'mel-ccl-quoted-printable-lf-lf-rev-unix) + 'mel-ccl-quoted-printable-lf-lf-rev-unix + 'mel-ccl-quoted-printable-lf-lf-rev)) + jka-compr-compression-info-list jam-zcat-filename-list) + (write-region start end filename))))) (mel-define-method-function (mime-decode-string string (nil "quoted-printable")) @@ -998,7 +1027,12 @@ MODE allows `text', `comment', `phrase' or nil. Default value is ((eq mode 'text) 'mel-ccl-encode-uq) ((eq mode 'comment) 'mel-ccl-encode-cq) (t 'mel-ccl-encode-pq)) - (make-vector 9 0) string nil t))) + (make-vector 9 0) string nil t)) + + (defun q-encoding-ccl-decode-string (string) + "Decode Q encoded STRING and return the result." + (ccl-execute-on-string 'mel-ccl-decode-q + (make-vector 9 0) string nil t))) (t (defun q-encoding-ccl-encode-string (string &optional mode) "Encode STRING to Q-encoding of encoded-word, and return the result. @@ -1009,13 +1043,13 @@ MODE allows `text', `comment', `phrase' or nil. Default value is (cond ((eq mode 'text) 'mel-ccl-uq-rev) ((eq mode 'comment) 'mel-ccl-cq-rev) - (t 'mel-ccl-pq-rev)))))) + (t 'mel-ccl-pq-rev)))) -(defun q-encoding-ccl-decode-string (string) - "Decode Q encoded STRING and return the result." - (encode-coding-string - string - 'mel-ccl-uq-rev)) + (defun q-encoding-ccl-decode-string (string) + "Decode Q encoded STRING and return the result." + (encode-coding-string + string + 'mel-ccl-uq-rev)))) (unless (featurep 'xemacs) (defun q-encoding-ccl-encoded-length (string &optional mode) diff --git a/mel-q.el b/mel-q.el index e527f9e..4ce3df1 100644 --- a/mel-q.el +++ b/mel-q.el @@ -177,6 +177,18 @@ It calls external quoted-printable encoder specified by ((<= ?0 chr) (- chr ?0)) )) +(if (eval-when-compile + (> (string-to-char (string-as-multibyte "\200")) 128)) + (defsubst quoted-printable-num-to-raw-byte-char (chr) + (if (and chr + (> chr 127)) + (logior chr + (eval-when-compile + (- (string-to-char (string-as-multibyte "\200")) 128))) + chr)) + (defsubst quoted-printable-num-to-raw-byte-char (chr) + chr)) + (defun quoted-printable-internal-decode-region (start end) (save-excursion (save-restriction @@ -198,9 +210,10 @@ It calls external quoted-printable encoder specified by ;; encoded char. (insert (prog1 - (logior - (ash (quoted-printable-hex-char-to-num (char-after (point))) 4) - (quoted-printable-hex-char-to-num (char-after (1+ (point))))) + (quoted-printable-num-to-raw-byte-char + (logior + (ash (quoted-printable-hex-char-to-num (char-after (point))) 4) + (quoted-printable-hex-char-to-num (char-after (1+ (point)))))) (delete-region (1- (point))(+ 2 (point)))))) (t ;; invalid encoding. @@ -320,7 +333,9 @@ MODE allows `text', `comment', `phrase' or nil. Default value is "") (h (setq l (quoted-printable-hex-char-to-num chr)) (prog1 - (char-to-string (logior (ash h 4) l)) + (char-to-string + (quoted-printable-num-to-raw-byte-char + (logior (ash h 4) l))) (setq h nil))) (t (char-to-string chr))))) string "")))