#!/usr/local/bin/perl
require 'codeconv.pl';
require 'getopts.pl';
sub usage {
print STDERR "rklist2rkel - convert Roma-Kana table to Emacs lisp program\n";
print STDERR " % rklist2rkel -h -s rktable > rk.el\n";
print STDERR " -h: Hiragana \n";
print STDERR " -s: Shift JIS \n";
exit;
}
$options = join(' ',@ARGV);
&usage unless &Getopts('hs');
&usage unless $rktable = shift;
&usage unless -f $rktable;
open(table, "nkf -e $rktable |") || die "Can't invoke NKF";
while(
){
chop;
next if /^#/;
$r = $k = '';
($r,$k) = split(/\s+/);
next if $r eq '' || $k eq '';
next if $r eq 'nn';
$rk{$r} = $k;
@kr = split(/,/,$kr{$k});
push(@kr,$r);
$kr{$k} = join(',',@kr);
$nentries++;
}
# $str_n = &hexdump(&strconv('ン'));
# $str_tsu = &hexdump(&strconv('ッ'));
print < (setq len (length roma)) 0)
(let ((i (if (> len 4) 4 len)) p)
(while (and (not p) (> i 0))
(setq xass (substring roma 0 i))
(setq p (assoc (substring roma 0 i) rk-rktable))
(setq i (1- i))
)
(setq y p)
(cond
(p
(setq r (concat r (cdr p)))
(setq z r)
(setq roma (substring roma (1+ i)))
)
((string-match "^n[bcdfghjklmnpqrstvwxz]" roma)
(setq roma (substring roma 1))
(setq r (concat r "ン"))
)
((string-match "^\\\\([bcdfghjklmpqrstvwxyz]\\\\)\\\\1" roma)
(setq roma (substring roma 1))
(setq r (concat r "ッ"))
)
((string= roma "n")
(setq roma (substring roma 1))
(setq r (concat r "ン"))
)
(t
(setq roma (substring roma 1))
)
)
))
r
))
(defun kata2hira (str)
(rk-kana-conv str rk-hiragana-str rk-katakana-str)
)
(defun rk-kana-conv (str to from)
(let ((i 0) (res "") idx s c)
(while (> (length str) 0)
(setq c (sref str 0))
(setq s (char-to-string c))
(setq idx (string-match s from))
(setq res (concat res (if idx (char-to-string (sref to idx)) s)))
(setq str (substring str (char-bytes c)))
)
res
))
EOF