$NetBSD$ --- egg-com.el.orig 2001-01-28 03:53:13.000000000 +0900 +++ egg-com.el 2010-11-19 22:37:28.000000000 +0900 @@ -44,6 +44,8 @@ ;; Japanese +(if (not (fboundp 'define-coding-system)) ; emacs-22 or earlier +(progn (eval-and-compile (define-ccl-program ccl-decode-fixed-euc-jp `(2 @@ -101,6 +103,72 @@ (make-coding-system 'fixed-euc-jp 4 ?W "Coding System for fixed EUC Japanese" (cons ccl-decode-fixed-euc-jp ccl-encode-fixed-euc-jp)) +) ; (if (not (fboundp 'define-coding-system)) ; emacs-22 or earlier +(progn +;; http://www.m17n.org/mlarchive/mule-ja/200703/msg00018.html +(defun fixed-euc-jp-pre-write-conversion (from to) + (let ((work-buf (generate-new-buffer " *temp*")) + ch) + (if (stringp from) + (encode-coding-string from 'euc-japan nil work-buf) + (encode-coding-region from to 'euc-japan work-buf)) + (set-buffer work-buf) + (set-buffer-multibyte nil) + (goto-char (point-min)) + (while (not (eobp)) + (setq ch (following-char)) + (cond ((= ch #x8E) ; SS2 for JISX0201-kana + (delete-char 1) ; SS2 BYTE -> 0 BYTE&0x7F + (insert 0) + (forward-char 1)) + ((= ch #x8F) ; SS3 for JISX0212 + (delete-char 1) ; SS3 BYTE1 BYTE2 -> BYTE1 BYTE2&0x7F + (forward-char 1) + (setq ch (following-char)) + (delete-char 1) + (insert (logand ch #x7F))) + ((>= ch #xA0) ; JISX0208 + (forward-char 2)) + (t ; ASCII + (insert 0) ; BYTE -> 0 BYTE + (forward-char 1)))))) + +(defun fixed-euc-jp-post-read-conversion (len) + (let ((str (string-as-unibyte (buffer-substring (point) (+ (point) len)))) + (pos (point)) + i ch1 ch2) + (delete-region (point) (+ (point) len)) + (setq i 0) + (while (< i len) + (setq ch1 (aref str i)) + (setq ch2 (aref str (1+ i))) + (cond ((>= ch1 #x80) + (if (>= ch2 #x80) + (setq ch1 ; JISX0208 + (decode-char 'japanese-jisx0208 + (logior (lsh (logand ch1 #x7F) 8) + (logand ch2 #x7F)))) + (setq ch1 ; JISX0212 + (decode-char 'japanese-jisx0212 + (logior (lsh (logand ch1 #x7F) 8) ch2))))) + (t + (if (>= ch2 #x80) + (setq ch1 ; JISX0201-kana + (decode-char 'katakana-jisx0201 (logand ch2 #x7F))) + (setq ch1 ch2)))) + (insert ch1) + (setq i (+ i 2))) + (prog1 (- (point) pos) + (goto-char pos)))) + +(define-coding-system 'fixed-euc-jp "Coding System for fixed EUC Japanese" + :mnemonic ?W + :coding-type 'raw-text + :charset-list '(ascii japanese-jisx0208 katakana-jisx0201 japanese-jisx0212) + :pre-write-conversion 'fixed-euc-jp-pre-write-conversion + :post-read-conversion 'fixed-euc-jp-post-read-conversion) +)) + ;; Korean (eval-and-compile