;;;
;;; irchat-pj-jisx0201.el
;;;
;;; This file is based on jisx0201.el (Mule 2.3)
;;; I referred mew-lang-jp.el (Mew 1.93) when editting.
;;; Thanks to Mule Project and Mew Project
;;;
;;; last modify : Sun, 27 Jun 1999 by simm@irc.fan.gr.jp / irchat-PJ Project
;;; (date format modification by simm@irc.fan.gr.jp, Sun, 27 Jun 1999)
;;;
;;; see file irchat-copyright.el for change log and copyright info

(provide 'irchat-pj-jisx0201)

(defvar irchat-pj-katakana-alist
  '(( 161 . "ｧ" )
    ( 162 . "ｱ" )
    ( 163 . "ｨ" )
    ( 164 . "ｲ" )
    ( 165 . "ｩ" )
    ( 166 . "ｳ" )
    ( 167 . "ｪ" )
    ( 168 . "ｴ" )
    ( 169 . "ｫ" )
    ( 170 . "ｵ" )
    ( 171 . "ｶ" )
    ( 172 . "ｶﾞ" )
    ( 173 . "ｷ" )
    ( 174 . "ｷﾞ" )
    ( 175 . "ｸ" )
    ( 176 . "ｸﾞ" )
    ( 177 . "ｹ" )
    ( 178 . "ｹﾞ" )
    ( 179 . "ｺ" )
    ( 180 . "ｺﾞ" )
    ( 181 . "ｻ" )
    ( 182 . "ｻﾞ" )
    ( 183 . "ｼ" )
    ( 184 . "ｼﾞ" )
    ( 185 . "ｽ" )
    ( 186 . "ｽﾞ" )
    ( 187 . "ｾ" )
    ( 188 . "ｾﾞ" )
    ( 189 . "ｿ" )
    ( 190 . "ｿﾞ" )
    ( 191 . "ﾀ" )
    ( 192 . "ﾀﾞ" )
    ( 193 . "ﾁ" )
    ( 194 . "ﾁﾞ" )
    ( 195 . "ｯ" )
    ( 196 . "ﾂ" )
    ( 197 . "ﾂﾞ" )
    ( 198 . "ﾃ" )
    ( 199 . "ﾃﾞ" )
    ( 200 . "ﾄ" )
    ( 201 . "ﾄﾞ" )
    ( 202 . "ﾅ" )
    ( 203 . "ﾆ" )
    ( 204 . "ﾇ" )
    ( 205 . "ﾈ" )
    ( 206 . "ﾉ" )
    ( 207 . "ﾊ" )
    ( 208 . "ﾊﾞ" )
    ( 209 . "ﾊﾟ" )
    ( 210 . "ﾋ" )
    ( 211 . "ﾋﾞ" )
    ( 212 . "ﾋﾟ" )
    ( 213 . "ﾌ" )
    ( 214 . "ﾌﾞ" )
    ( 215 . "ﾌﾟ" )
    ( 216 . "ﾍ" )
    ( 217 . "ﾍﾞ" )
    ( 218 . "ﾍﾟ" )
    ( 219 . "ﾎ" )
    ( 220 . "ﾎﾞ" )
    ( 221 . "ﾎﾟ" )
    ( 222 . "ﾏ" )
    ( 223 . "ﾐ" )
    ( 224 . "ﾑ" )
    ( 225 . "ﾒ" )
    ( 226 . "ﾓ" )
    ( 227 . "ｬ" )
    ( 228 . "ﾔ" )
    ( 229 . "ｭ" )
    ( 230 . "ﾕ" )
    ( 231 . "ｮ" )
    ( 232 . "ﾖ" )
    ( 233 . "ﾗ" )
    ( 234 . "ﾘ" )
    ( 235 . "ﾙ" )
    ( 236 . "ﾚ" )
    ( 237 . "ﾛ" )
    ( 239 . "ﾜ" ) ; ﾜ -> ワ に変換するように
    ( 238 . "ﾜ" ) ; ワとヮの順番が交換してある。
    ( 240 . "ｨ" )
    ( 241 . "ｪ" )
    ( 242 . "ｦ" )
    ( 243 . "ﾝ" )
    ( 244 . "ｳﾞ" )
    ( 245 . "ｶ" )
    ( 246 . "ｹ" )))

(defvar irchat-pj-katakana-kigou-alist
  '(( 162 . "､" )
    ( 163 . "｡" )
    ( 166 . "･" )
    ( 171 . "ﾞ" )
    ( 172 . "ﾟ" )
    ( 188 . "ｰ" )
    ( 214 . "｢" )
    ( 215 . "｣" )))

(defvar irchat-pj-dakuon-list
  '( ?カ ?キ ?ク ?ケ ?コ
     ?サ ?シ ?ス ?セ ?ソ
     ?タ ?チ ?ツ ?テ ?ト
     ?ハ ?ヒ ?フ ?ヘ ?ホ))

;;(defvar irchat-pj-handakuon-list (memq ?ハ 'irchat-pj-dakuon-list))
(defvar irchat-pj-handakuon-list 
  '( ?ハ ?ヒ ?フ ?ヘ ?ホ))

(defun irchat-pj-search-henkan-alist (ch list)
  (let ((ptr list)
	(result nil))
    (while ptr
      (if (string= ch (cdr (car ptr)))
	  (progn
	    (setq result (car (car ptr)))
	    (setq ptr nil))
	(setq ptr (cdr ptr))))
    result))

(defun irchat-pj-make-jisx0208-katakana (ch)
  (cond ((featurep 'xemacs)
	 (message "XEmacs")
	 (make-char 'japanese-jisx0208 37 (- ch 128)))
	((>= (string-to-int (substring emacs-version 0 2)) 20)
	 (message "Emacs20")
	 (make-char 'japanese-jisx0208 ?\245 ch))
	(t
	 (message "Other")
	 (make-character lc-jp ?\245 ch))))

(defun irchat-pj-make-jisx0208-kigou (ch)
  (cond ((featurep 'xemacs)
	 (message "XEmacs")
	 (make-char 'japanese-jisx0208 33 (- ch 128)))
	((>= (string-to-int (substring emacs-version 0 2)) 20)
	 (message "Emacs20")
	 (make-char 'japanese-jisx0208 ?\241 ch))
	(t
	 (message "Other")
	 (make-character lc-jp ?\241 ch))))

(defun irchat-pj-zenkaku-katakana-string (string)
  "Convert jisx0201 katakana to jisx0208."
  (let ((return "")
	(ch nil)
	(wk nil)
	(point 0))
    (if (null (string-match "\\ck" string))
	(setq return string)
      (while (< point (length string))
	(setq ch (elt string point))
	(setq wk (char-to-string ch))
	(if (null (string-match "\\ck" wk))
	    (setq return (concat return wk))
	  (cond ((= ch ?ﾞ)
		 (if (= 0 point)
		     (setq return (concat return "゛"))
		   (setq wk (elt return (1- (length return))))
		   (cond ((= wk ?ウ)
			  (setq return (substring return 0 (1- (length return))))
			  (setq return (concat return "ヴ")))
			 ((setq wk (memq wk irchat-pj-dakuon-list))
			  (setq return (substring return 0 (1- (length return))))
			  (setq return (concat return (char-to-string (1+ (car wk))))))
			 (t
			  (setq return (concat return "゛"))))))
		((= ch ?ﾟ)
		 (if (= 0 point)
		     (setq return (concat return "゜"))
		   (setq wk (elt return (1- (length return))))
		   (cond ((setq wk (memq wk irchat-pj-handakuon-list))
			  (setq return (substring return 0 (1- (length return))))
			  (setq return (concat return (char-to-string (+ 2 (car wk))))))
			 (t
			  (setq return (concat return "゜"))))))
		((setq wk (irchat-pj-search-henkan-alist
			   (char-to-string ch) irchat-pj-katakana-alist))
		 (setq return
		       (concat return
			       (char-to-string (irchat-pj-make-jisx0208-katakana wk)))))
		((setq wk (irchat-pj-search-henkan-alist
			   (char-to-string ch) irchat-pj-katakana-kigou-alist))
		 (setq return
		       (concat return
			       (char-to-string (irchat-pj-make-jisx0208-kigou wk)))))))
	(setq point (1+ point))))
    return))

;;;
;;; eof
;;;
