Browse Source

init from postnix

front
henesy 7 months ago
commit
223ef85dc8
14 changed files with 10333 additions and 0 deletions
  1. +4
    -0
      Kanji
  2. +108
    -0
      README.kenji
  3. +126
    -0
      READMEJ.kenji
  4. +220
    -0
      jisho.c
  5. +41
    -0
      jisho.h
  6. +7586
    -0
      ktrans-jisho
  7. +465
    -0
      ktrans.h
  8. +92
    -0
      ktrans.man
  9. +622
    -0
      license
  10. +429
    -0
      main.c
  11. +467
    -0
      main.c.cinap
  12. +22
    -0
      mkfile
  13. +84
    -0
      pipefile.c
  14. +67
    -0
      pipekbd.c

+ 4
- 0
Kanji View File

@@ -0,0 +1,4 @@
#!/bin/rc

pipefile -r ktrans /dev/cons
rio -i $home/lib/windows </dev/cons

+ 108
- 0
README.kenji View File

@@ -0,0 +1,108 @@
This version of ktrans works with pipefile by Rob Pike, which replaces /dev/kbd of
2nd Edition Plan 9 by Dennis Ritchie. By this new idea, we can input Japanese
anytime onto any windows. I included his post to 9fans mailing-list here (pipefile
file).

This is a distribution as a derived work license of Plan 9, and I included the
Plan 9 License term here. Please refer to it on the details of this license.


Main features are as follows:

1) There is a "local" dictionary file for translation from kana to kanji, which can
easily be edited by the user. The default file name is $home/lib/ktrans-jisho.
If you want to use another dictionary file, set the KTJISHO environment
variable to point to that file. This dictionary comprises many lines of
edittable text strings.

2) Capital romaji input is used for words such as verbs or adjectives with okurigana,
which follows the idea of the SKK system by Masahiko Sato of Kyoto Univ.
(masahiko@kuis.kyoto-u.ac.jp). If you want to get the kanji string (runes)
"動かす", which is a verb, you may input "ugoKasu" from the keyboard.
Note here the Kasu's k is a capital (important). You will see hiragana
runes "うごかす", and then the kanji runes of "動かす", when you type
"Shift+Space".
If you are satisfied by that translation, continue to input the next word.
If you are not pleased with that candidate, hit 'Shift+Space' once more
to see more candiates for that hiragana input. When there are no more candidates
registered in your dictionary, you will see the initial hiragana input.

3) For Japanese "joshi", a post-positioned short word after a noun, you can use another
method that I developed for this work. If you want the kanji string (runes) "私は",
then type "watashiHA" from the keyboard. Note that the sound of "wa(ha)" is expressed
as capitalized "HA". You will see a hiragana string of "わたしは", and then "私は"
after `Shift+Space'.

4) A control sequence of 'ctl-l' is introduced to leave input hiragana runes unchanged.
This is occasionally neccessary.

5) A simple leaning mechanism has been implemented for the in-memory hashing
dictinary, in which the most recently used kanji runes (candidate) moves to the top
of the list of candidates. This is valid only during the session you called ktrans.
It is done this way intentionally, because the present learning method is ..well...
naive. ^_^ I know this; however, I believe you can solve it by making a good
dictionary best fitted to your purposes on your own.

6) 'ctl-x' re-reads the new kana-kanji translation dictionary when you have edited your
kana-kanji translation, and want to incorporate it into your current in-memory translation
dictionary. The kana-kanji translation dictionary is usually read only once, at the
beginning of the ktrans session. I believe this simplification is not a serious constraint,
because you can edit the dictionary anytime by co-working with acme and using this ctl-x
mechanism.

7) A mode change to kana-input is triggered by 'ctl-n', ctl-k for katakana mode,
ctl-g for Greek mode, and ctl-r for Russian mode.

8) As the starting $home/lib/ktrans-jisho, you may re-format the SKK-JISYO.S (66.9KB) of the
SKK system, which can be retrieved from ftp.kuis.kyoto-u.ac.jp. The next three lines
show the short sed filter to transform from an SKK type dictionary to Plan 9. Before
this, you should change the kanji code of the SKK dictionary from ujis(euc) to UTF-8 by
the tcs utility, of course.
s/\// /g
s/ / /g
s/ $//g
The header items are sorted in a strange order in the original SKK dictionary.
This implementation does not care about the order, therefore, you can change it on
your own.

9) SKK jisho, such as SKK-JISYO.S, is composed of two parts, okuri-ari and okuri-nashi
entries. This greatly depends on the Japanese grammer, and okuri-ari may represent
verb/adjective etc., i.e., not noun. These two parts work differently in the original
SKK system, however, I did not employ that method; rather, I took a simple approarch
as described in (2) and (3). Here, we make no difference between these two parts,
and the reason why I left the two-part structure is just to make it easier to read for
editting. Of course, you can change it without any side-effects.
10) The essence of this Japanese input method is to convert every one word by one key
triggering. This may cause some cumbersome feelings for Nihongo users who are accustomed
to, say, Windows. I know this. However, I intended to keep the codes as compact as
possible as a first step towards developing a Nihongo input system on Plan 9.
Furthermore, I've never seen the latter work perfectly. I think the conversion failed
essentially when we see more than, say, five/six candidates for one set of hiragana runes.
Finaly, I'd like to add that I have no problem to write long Japanese documents by
this version.

11) The translation trigger key has been changed from ^t to Shift+Space, because
we experienced butting of the trigger key sequence sometime. For this reason,
you have to edit the key-binding table, such as kbtabshift[0x39] in /sys/src/9/pc/kbd.c
or keymapshift[0x79] in /sys/src/9/ss/screen.c to assign Shift+Space to '^\'.
I use here '^\' as the trigger key. Therefore, you can trigger translation
from kana to kanji by Shit+Space or just '^\'.

12) A usage example: If you want to make the Japanese text as below:

私は毎日35分以上歩いて、 更に10分電車に乗って学校に通います。
健康の維持にも役だっていますが、 なかなかたのしいものです。

your keyboard typing stream should be:

watashiHA[^t]mainichi[^t]35[^l]fun[^t]ijou[^t]aruIte, [^t]saraNI[^t]
10[^l]fun[^t]denshaNI[^t]noTte[^t]gakkouNI[^t]kayoImasu.[^t]
kenkouNO[^t]ijiNImo[^t]yakuDAtteimasuga, [^t]nakanaka[^l]tanoshiI[^t]
monodesu.[^l]

where [^t], [^l] indicates 'Shift+Space' and 'ctl-l', respectively.


Kenji Okamoto August 14, 2000


+ 126
- 0
READMEJ.kenji View File

@@ -0,0 +1,126 @@
Plan 9がRelase 3になってソースが公開されました。このため、更に多くのユーザがPlan 9を
使い始める事になると思います。このバージョンになって、Windowシステムが8½からrioに
変更になり、それにともなって、release 2に含まれていたktransが無くなりました。

そこで、Rob Pikeさんにお願いしたら、pipefileというすばらしいアイデアを考えて戴け
ました。これはrelease 2でDennis Ritchieさんが提供した/dev/kbdを置き替えるもので、
このいきさつは、Pikeさんの9fansのlmailing-listへの投稿を同封してありますので、
そちら(pipefile)を御覧下さい。この方法は何時でもどのウィンドへも日本語を入力出来る
ので、以前のバージョンの様にウィンド毎にktransを起動する必要がなくなりました。
pipefileはrioより前に起動される必要がありますので、ここに同封したKanjiという
スクリプトを各自のlib/profileにrioを起動する替わりに、このKanjiスクリプトを
起動する様にして下さい。


Main features are as follows:

1) There is a "local" dictionary file for translation from kana to kanji, which can
easily be edited by the user. The default file name is $home/lib/ktrans-jisho.
If you want to use another dictionary file, set the KTJISHO environment
variable to point to that file. This dictionary comprises many lines of
edittable text strings.

2) Capital romaji input is used for words such as verbs or adjectives with okurigana,
which follows the idea of the SKK system by Masahiko Sato of Kyoto Univ.
(masahiko@kuis.kyoto-u.ac.jp). If you want to get the kanji string (runes)
"動かす", which is a verb, you may input "ugoKasu" from the keyboard.
Note here the Kasu's k is a capital (important). You will see hiragana
runes "うごかす", and then the kanji runes of "動かす", when you type
"Shift+Space".
If you are satisfied by that translation, continue to input the next word.
If you are not pleased with that candidate, hit 'Shift+Space' once more
to see more candiates for that hiragana input. When there are no more candidates
registered in your dictionary, you will see the initial hiragana input.

3) For Japanese "joshi", a post-positioned short word after a noun, you can use another
method that I developed for this work. If you want the kanji string (runes) "私は",
then type "watashiHA" from the keyboard. Note that the sound of "wa(ha)" is expressed
as capitalized "HA". You will see a hiragana string of "わたしは", and then "私は"
after `Shift+Space'.

4) A control sequence of 'ctl-l' is introduced to leave input hiragana runes unchanged.
This is occasionally neccessary.

5) A simple leaning mechanism has been implemented for the in-memory hashing
dictinary, in which the most recently used kanji runes (candidate) moves to the top
of the list of candidates. This is valid only during the session you called ktrans.
It is done this way intentionally, because the present learning method is ..well...
naive. ^_^ I know this; however, I believe you can solve it by making a good
dictionary best fitted to your purposes on your own.

6) 'ctl-x' re-reads the new kana-kanji translation dictionary when you have edited your
kana-kanji translation, and want to incorporate it into your current in-memory translation
dictionary. The kana-kanji translation dictionary is usually read only once, at the
beginning of the ktrans session. I believe this simplification is not a serious constraint,
because you can edit the dictionary anytime by co-working with acme and using this ctl-x
mechanism.

7) A mode change to kana-input is triggered by 'ctl-n', ctl-k for katakana mode,
ctl-g for Greek mode, and ctl-r for Russian mode.

8) As the starting $home/lib/ktrans-jisho, you may re-format the SKK-JISYO.S (66.9KB) of the
SKK system, which can be retrieved from ftp.kuis.kyoto-u.ac.jp. The next three lines
show the short sed filter to transform from an SKK type dictionary to Plan 9. Before
this, you should change the kanji code of the SKK dictionary from ujis(euc) to UTF-8 by
the tcs utility, of course.
s/\// /g
s/ / /g
s/ $//g
The header items are sorted in a strange order in the original SKK dictionary.
This implementation does not care about the order, therefore, you can change it on
your own.

9) SKK jisho, such as SKK-JISYO.S, is composed of two parts, okuri-ari and okuri-nashi
entries. This greatly depends on the Japanese grammer, and okuri-ari may represent
verb/adjective etc., i.e., not noun. These two parts work differently in the original
SKK system, however, I did not employ that method; rather, I took a simple approarch
as described in (2) and (3). Here, we make no difference between these two parts,
and the reason why I left the two-part structure is just to make it easier to read for
editting. Of course, you can change it without any side-effects.
10) The essence of this Japanese input method is to convert every one word by one key
triggering. This may cause some cumbersome feelings for Nihongo users who are accustomed
to, say, Windows. I know this. However, I intended to keep the codes as compact as
possible as a first step towards developing a Nihongo input system on Plan 9.
Furthermore, I've never seen the latter work perfectly. I think the conversion failed
essentially when we see more than, say, five/six candidates for one set of hiragana runes.
Finaly, I'd like to add that I have no problem to write long Japanese documents by
this version.

11) The translation trigger key has been changed from ^t to Shift+Space, because
we experienced butting of the trigger key sequence sometime. For this reason,
you have to edit the key-binding table, such as kbtabshift[0x39] in /sys/src/9/pc/kbd.c
or keymapshift[0x79] in /sys/src/9/ss/screen.c to assign Shift+Space to '^\'.
I use here '^\' as the trigger key. Therefore, you can trigger translation
from kana to kanji by Shit+Space or just '^\'.

12) A usage example: If you want to make the Japanese text as below:

私は毎日35分以上歩いて、 更に10分電車に乗って学校に通います。
健康の維持にも役だっていますが、 なかなかたのしいものです。

your keyboard typing stream should be:

watashiHA[^t]mainichi[^t]35[^l]fun[^t]ijou[^t]aruIte, [^t]saraNI[^t]
10[^l]fun[^t]denshaNI[^t]noTte[^t]gakkouNI[^t]kayoImasu.[^t]
kenkouNO[^t]ijiNImo[^t]yakuDAtteimasuga, [^t]nakanaka[^l]tanoshiI[^t]
monodesu.[^l]

where [^t], [^l] indicates 'Shift+Space' and 'ctl-l', respectively.


Kenji Okamoto August 14, 2000


これはRelease 2のPlan 9に含まれていたDennis Ritchieさんのktransを機能強化したもので、
大阪府立大学の岡本健二が作成いたしました。 疑問、提案等がございましたら、
okamoto@granite.cias.osakafu-u.ac.jpまで御連絡ください。
なお, Plan 9そのものにつきましては、
http://basalt.cias.osakafu-u.ac.jp/plan9/p9index.html に95年度より
ささやかなWeb Pageをもっていますので、そちらも参照くださいませ。

なおこのプログラムはPlan 9のderived workとしてのライセンスを持った配布となります。
Plan 9のLicense fileを同封してありますので、ここに書かれている事を守ってお使い
下さいませ。

大阪府立大学総合科学部 岡本健二 August 14, 2000

+ 220
- 0
jisho.c View File

@@ -0,0 +1,220 @@
/*
* open jisho file, and set the size of this jisho etc
* default personal jisho: $home/lib/ktrans-jisho
*
* Kenji Okamoto August 4, 2000
* Osaka Prefecture Univ.
* okamoto@granite.cias.osakafu-u.ac.jp
*/

#include <u.h>
#include <libc.h>
#include <bio.h>
#include "jisho.h"

Dictionary *openQDIC(char *);
void freeQDIC(Dictionary*);
KouhoList *getKouhoHash(Dictionary*, char *);
KouhoList *getKouhoFile(DicList*, char *);
void selectKouho(KouhoList **, KouhoList*);
int hashVal(char *);
void addHash(Hash **, DicList*);



/*
* Open QuickDIC (hashed personal dictionary)
* open skk styled ktrans dictinary file, and make its hash table
* based on individual header kana strings
*
* KouhoList
* |---------|
* Hash |---->kouho---->kouhotop
* |-------| |
* dic---->dhash---->dicindex---->kanahead
* |--------| |--------|
* Dictionary DicList
*
*/
Dictionary *
openQDIC(char *dicname)
{
Biobuf *f;
void *Bbuf;
Dictionary *dic;
DicList *dicitem; /* for a future extension */
char buf[1024], *startstr, *endstr;
int i;

SET(dicitem); /* yes, I know I'm wrong, but... */

dic = (Dictionary*)malloc(sizeof(Dictionary));
/* make room for pointer array (size=HASHSIZE) of hash table */
for(i=0; i< HASHSIZE; i++) dic->dhash[i] = 0;
dic->dlist = 0; /* for a future extension (more than one dics ^_^ */

if ((f = Bopen(dicname, OREAD)) == 0)
return dic;

/* make hash table by the dic's header word */

while(Bbuf = Brdline(f, '\n')) {
strncpy(buf, (char *)Bbuf, Blinelen(f));

if (buf[0] == ';') /* comment line */
continue;
else {
/* get header word from jisho */
startstr = buf;
if(!(endstr = utfutf(startstr, "\t"))) break;
*endstr = '\0';
/* dicitem includes each header word from the jisho */

dicitem = (DicList*)malloc(sizeof(DicList)+(endstr-startstr+1));
dicitem->nextitem = 0; /* for a future extension */
strcpy(dicitem->kanahead, startstr);

dicitem->kouho = getKouhoFile(dicitem, endstr); /* read kouho from jisho */
addHash(dic->dhash, dicitem);
}
continue;
}
dic->dlist = dicitem;
Bterm(f);
return dic;
}

/*
* free dynamically allocated memory
*/

void
freeQDIC(Dictionary *dic)
{
Hash *hash1, *hash2;
DicList *dlist, *dlist2;
int l;

for (dlist = dic->dlist;
dlist != 0;
dlist2 = dlist, dlist = dlist->nextitem, free((void *)dlist2));
for (l = 0; l < HASHSIZE; l++) {
for (hash1 = dic->dhash[l]; hash1; hash1 = hash2) {
if (hash1->next !=0) {
hash2 = hash1->next;
free((void *)hash1);
}else
break;
}
}
free((void *)dic);
}

/*
* well known method to make a hash table
* I don't know another better method. ^_^
*/
int
hashVal(char *s)
{
int n = 0;

while (*s) {
n += (*s)*(*s);
s++;
}
return n%HASHSIZE;
}

void
addHash(Hash **hash, DicList *ditem)
{
Hash *h;
int v;

v = hashVal(ditem->kanahead);
h = (Hash*)malloc(sizeof(Hash));
h->dicindex = ditem;
h->length = strlen(ditem->kanahead);
h->next = hash[v];
hash[v] = h;
}

/*
* read Kouho list from the jisho file defined by Biobuf descriptor f
*
* revised for Plan 9 by K.Okamoto
*/
KouhoList *
getKouhoFile(DicList *dicitem, char * endstr)

{
char *kouhostart, *kouhoend;
KouhoList *kouhoitem, *currntkouhoitem=0, *prevkouhoitem;

prevkouhoitem = 0;
kouhostart = endstr + 1;
while((kouhoend = utfutf(kouhostart, " ")) ||
(kouhoend = utfutf(kouhostart, "\n"))) {
*kouhoend = '\0';

kouhoitem = (KouhoList*)malloc(sizeof(KouhoList)+(kouhoend-kouhostart+1));
kouhoitem->nextkouho = 0;
kouhoitem->prevkouho = prevkouhoitem;
kouhoitem->dicitem = dicitem;
strcpy(kouhoitem->kouhotop, kouhostart);
if (prevkouhoitem)
prevkouhoitem->nextkouho = kouhoitem;
else
currntkouhoitem = kouhoitem;
prevkouhoitem = kouhoitem;
kouhostart = kouhoend + 1;
}
return currntkouhoitem;
}

/*
* get matched kouho from the hash table of header word of the dic
* if found, returns pointer to the first candidate in the hash table.
* if not found, returns 0.
*
* from getCand() in skklib.c by Akinori Ito et al.,(aito@ei5sun.yz.yamagata-u.ac.jp)
*/

KouhoList *
getKouhoHash(Dictionary *dic, char *s)
{
int l, v;
Hash *h;

l = strlen(s);
v = hashVal(s);
for (h = dic->dhash[v]; h != 0; h = h->next) {
if (h->length != l ||
strcmp(h->dicindex->kanahead, s)) continue;
return h->dicindex->kouho; /* return matched kouho */
}
return 0;
}

/*
*from skklib.c by Akinori Ito et al.,(aito@ei5sun.yz.yamagata-u.ac.jp)
* just modified to read easier for present purpose
*/
void
selectKouho(KouhoList **first, KouhoList *current)
{
/* take off currentkouho from the kouholist table */
if (current->prevkouho) {
current->prevkouho->nextkouho = current->nextkouho;
if (current->nextkouho)
current->nextkouho->prevkouho = current->prevkouho;
current->prevkouho = 0;
}
/* take place of firstkouho by currentkouho */
if (*first != current) {
(*first)->prevkouho = current;
current->nextkouho = *first;
*first = current;
}
}

+ 41
- 0
jisho.h View File

@@ -0,0 +1,41 @@
/*
* Kenji Okamoto August 4, 2000
* Osaka Prefecture Univ.
* okamoto@granite.cias.osakafu-u.ac.jp
*/

#define HASHSIZE 256

/*
* Structure for Dictionary's header word(in Hiragana)
*/
typedef struct DicList DicList;
struct DicList {
struct KouhoList *kouho;
struct DicList *nextitem; /* for a future extension */
char kanahead[1];
};

/*
* Structure for Kouho of each index word in the dictionary
*/
typedef struct KouhoList KouhoList;
struct KouhoList {
struct KouhoList *nextkouho;
struct KouhoList *prevkouho;
struct DicList *dicitem;
char kouhotop[1]; /* top of the kouhos */
} ;

typedef struct Hash Hash;
struct Hash {
DicList *dicindex; /* pointer to a KouhoList and kanahead etc */
short length;
struct Hash *next;
};

typedef struct Dictionary Dictionary;
struct Dictionary {
DicList *dlist; /* for a future extension, having more than one dictionaries */
Hash *dhash[HASHSIZE];
};

+ 7586
- 0
ktrans-jisho
File diff suppressed because it is too large
View File


+ 465
- 0
ktrans.h View File

@@ -0,0 +1,465 @@
typedef struct Map Map;
struct Map {
char *roma;
char *kana;
char advance;
};


Map kata[] = {
"a", "ア", 1,
"-", "ー", 1,
"i", "イ", 1,
"u", "ウ", 1,
"e", "エ", 1,
"o", "オ", 1,
"ka", "カ", 2,
"ga", "ガ", 2,
"ki", "キ", 2,
"kya", "キャ", 3,
"kyu", "キュ", 3,
"kyo", "キョ", 3,
"gi", "ギ", 2,
"gya", "ギャ", 3,
"gyu", "ギュ", 3,
"gyo", "ギョ", 3,
"ku", "ク", 2,
"gu", "グ", 2,
"ke", "ケ", 2,
"ge", "ゲ", 2,
"ko", "コ", 2,
"go", "ゴ", 2,
"sa", "サ", 2,
"za", "ザ", 2,
"si", "シ", 2,
"shi", "シ", 3,
"ji", "ジ", 2,
"sha", "シャ", 3,
"she", "シェ", 3,
"shu", "シュ", 3,
"je", "ジェ", 2,
"sho", "ショ", 3,
"syo", "ショ", 3,
"ja", "ジャ", 2,
"ju", "ジュ", 2,
"je", "ジェ", 2,
"jo", "ジョ", 2,
"su", "ス", 2,
"zu", "ズ", 2,
"se", "セ", 2,
"ze", "ゼ", 2,
"so", "ソ", 2,
"zo", "ゾ", 2,
"ta", "タ", 2,
"da", "ダ", 2,
"ti", "ティ", 2,
"chi", "チ", 3,
"zi", "ヂ", 2,
"cha", "チャ", 3,
"chu", "チュ", 3,
"tyu", "チュ", 3,
"che", "チェ", 3,
"cho", "チョ", 3,
"tu", "ツ", 2,
"tsu", "ツ", 3,
"du", "ヅ", 2,
"te", "テ", 2,
"de", "デ", 2,
"to", "ト", 2,
"do", "ド", 2,
"na", "ナ", 2,
"ni", "ニ", 2,
"nya", "ニャ", 3,
"nyu", "ニュ", 3,
"nyo", "ニョ", 3,
"nu", "ヌ", 2,
"ne", "ネ", 2,
"no", "ノ", 2,
"ha", "ハ", 2,
"ba", "バ", 2,
"pa", "パ", 2,
"hi", "ヒ", 2,
"hya", "ヒャ", 3,
"hyu", "ヒュ", 3,
"hyo", "ヒョ", 3,
"bi", "ビ", 2,
"bya", "ビャ", 3,
"byu", "ビュ", 3,
"byo", "ビョ", 3,
"pi", "ピ", 2,
"pya", "ピャ", 3,
"pyu", "ピュ", 3,
"pyo", "ピョ", 3,
"hu", "フ", 2,
"fu", "フ", 2,
"bu", "ブ", 2,
"pu", "プ", 2,
"he", "ヘ", 2,
"be", "ベ", 2,
"pe", "ペ", 2,
"ho", "ホ", 2,
"bo", "ボ", 2,
"po", "ポ", 2,
"ma", "マ", 2,
"mi", "ミ", 2,
"mya", "ミャ", 3,
"myu", "ミュ", 3,
"myo", "ミョ", 3,
"mu", "ム", 2,
"me", "メ", 2,
"mo", "モ", 2,
"ya", "ヤ", 2,
"yu", "ユ", 2,
"yo", "ヨ", 2,
"ra", "ラ", 2,
"ri", "リ", 2,
"rya", "リャ", 3,
"ryu", "リュ", 3,
"ryo", "リョ", 3,
"ru", "ル", 2,
"re", "レ", 2,
"ro", "ロ", 2,
"wa", "ワ", 2,
"wi", "ヰ", 2,
"we", "ヱ", 2,
"wo", "ヲ", 2,
"n", "ン", 1,
"xn", "ン", 2,
"v", "ヴ", 1,
"xa", "ァ", 2,
"xi", "ィ", 2,
"xe", "ェ", 2,
"xo", "ォ", 2,
"cc", "ッ", 1,
"dd", "ッ", 1,
"kk", "ッ", 1,
"pp", "ッ", 1,
"tt", "ッ", 1,
"tch", "ッ", 1,
"ss", "ッ", 1,
"xn", "ン", 2,
"di", "ディ", 2,
"fa", "ファ", 2,
"fi", "フィ", 2,
"fe", "フェ", 2,
"fo", "フォ", 2,
"va", "ヴァ", 2,
"vi", "ヴィ", 2,
"ve", "ヴェ", 2,
"vo", "ヴォ", 2,
".", "。", 1,
",", "、", 1,
0
};

Map hira[] = {
"a", "あ", 1,
"-", "ー", 1,
"i", "い", 1,
"u", "う", 1,
"e", "え", 1,
"o", "お", 1,
"ka", "か", 2,
"ga", "が", 2,
"ki", "き", 2,
"kya", "きゃ", 3,
"kyu", "きゅ", 3,
"kyo", "きょ", 3,
"gi", "ぎ", 2,
"gya", "ぎゃ", 3,
"gyu", "ぎゅ", 3,
"gyo", "ぎょ", 3,
"ku", "く", 2,
"gu", "ぐ", 2,
"ke", "け", 2,
"ge", "げ", 2,
"ko", "こ", 2,
"go", "ご", 2,
"sa", "さ", 2,
"za", "ざ", 2,
"si", "し", 2,
"shi", "し", 3,
"sha", "しゃ", 3,
"shu", "しゅ", 3,
"she", "しぇ", 3,
"sho", "しょ", 3,
"syo", "しょ", 3,
"zi", "ぢ", 2,
"ja", "じゃ", 2,
"ju", "じゅ", 2,
"je", "じぇ", 2,
"jo", "じょ", 2,
"su", "す", 2,
"zu", "ず", 2,
"se", "せ", 2,
"ze", "ぜ", 2,
"so", "そ", 2,
"zo", "ぞ", 2,
"ta", "た", 2,
"da", "だ", 2,
"ti", "ち", 2,
"chi", "ち", 3,
"cha", "ちゃ", 3,
"chu", "ちゅ", 3,
"tyu", "ちゅ", 3,
"cho", "ちょ", 3,
"ji", "じ", 2,
"tu", "つ", 2,
"tsu", "つ", 3,
"du", "づ", 2,
"te", "て", 2,
"de", "で", 2,
"to", "と", 2,
"do", "ど", 2,
"na", "な", 2,
"ni", "に", 2,
"nya", "にゃ", 3,
"nyu", "にゅ", 3,
"nyo", "にょ", 3,
"nu", "ぬ", 2,
"ne", "ね", 2,
"no", "の", 2,
"ha", "は", 2,
"ba", "ば", 2,
"va", "ば", 2,
"pa", "ぱ", 2,
"hi", "ひ", 2,
"hya", "ひゃ", 3,
"hyu", "ひゅ", 3,
"hyo", "ひょ", 3,
"bi", "び", 2,
"bya", "びゃ", 3,
"byu", "びゅ", 3,
"byo", "びょ", 3,
"vi", "び", 2,
"pi", "ぴ", 2,
"pya", "ぴゃ", 3,
"pyu", "ぴゅ", 3,
"pyo", "ぴょ", 3,
"hu", "ふ", 2,
"fu", "ふ", 2,
"bu", "ぶ", 2,
"vu", "ぶ", 2,
"pu", "ぷ", 2,
"he", "へ", 2,
"be", "べ", 2,
"ve", "べ", 2,
"pe", "ぺ", 2,
"ho", "ほ", 2,
"bo", "ぼ", 2,
"vo", "ぼ", 2,
"po", "ぽ", 2,
"ma", "ま", 2,
"mi", "み", 2,
"mya", "みゃ", 3,
"myu", "みゅ", 3,
"myo", "みょ", 3,
"mu", "む", 2,
"me", "め", 2,
"mo", "も", 2,
"ya", "や", 2,
"yu", "ゆ", 2,
"yo", "よ", 2,
"ra", "ら", 2,
"ri", "り", 2,
"rya", "りゃ", 3,
"ryu", "りゅ", 3,
"ryo", "りょ", 3,
"ru", "る", 2,
"re", "れ", 2,
"ro", "ろ", 2,
"wa", "わ", 2,
"wi", "ゐ", 2,
"we", "ゑ", 2,
"wo", "を", 2,
"n", "ん", 1,
"xn", "ん", 2,
"v", "\x80", 1,
"xa", "ぁ", 2,
"xi", "ぃ", 2,
"xu", "ぅ", 2,
"xe", "ぇ", 2,
"xo", "ぉ", 2,
"cc", "っ", 1,
"dd", "っ", 1,
"kk", "っ", 1,
"pp", "っ", 1,
"tt", "っ", 1,
"ss", "っ", 1,
".", "。", 1,
",", "、", 1,
0,
};

Map cyril[] = {
"YO", "Ё", 2,
"Yo", "Ё", 2,
"A", "А", 1,
"B", "Б", 1,
"V", "В", 1,
"G", "Г", 1,
"D", "Д", 1,
"Ye", "Е", 1,
"YE", "Е", 2,
"E", "Е", 1,
"Zh", "Ж", 2,
"ZH", "Ж", 2,
"Z", "З", 1,
"I", "И", 1,
"J", "Й", 1,
"K", "К", 1,
"L", "Л", 1,
"M", "М", 1,
"N", "Н", 1,
"O", "О", 1,
"P", "П", 1,
"R", "Р", 1,
"S", "С", 1,
"T", "Т", 1,
"U", "У", 1,
"F", "Ф", 1,
"Kh", "Х", 2,
"KH", "Х", 2,
"X", "Х", 1,
"Ts", "Ц", 2,
"TS", "Ц", 2,
"Ch", "Ч", 2,
"CH", "Ч", 2,
"Sh", "Ш", 2,
"SH", "Ш", 2,
"Shch", "Щ", 4,
"SHCH", "Щ", 4,
"''", "ъ", 2,
"Y", "Ы", 1,
"'", "ь", 1,
"EH", "Э", 2,
"Eh", "Э", 2,
"Yu", "Ю", 2,
"YU", "Ю", 2,
"Ya", "Я", 2,
"YA", "Я", 2,
"a", "а", 1,
"b", "б", 1,
"v", "в", 1,
"g", "г", 1,
"d", "д", 1,
"ye", "е", 2,
"e", "е", 1,
"zh", "ж", 2,
"z", "з", 1,
"i", "и", 1,
"j", "й", 1,
"k", "к", 1,
"l", "л", 1,
"m", "м", 1,
"n", "н", 1,
"o", "о", 1,
"p", "п", 1,
"r", "р", 1,
"s", "с", 1,
"t", "т", 1,
"u", "у", 1,
"f", "ф", 1,
"kh", "х", 2,
"x", "х", 1,
"ts", "ц", 2,
"ch", "ч", 2,
"sh", "ш", 2,
"shch", "щ", 4,
"''", "ъ", 2,
"y", "ы", 1,
"'", "ь", 1,
"eh", "э", 2,
"yu", "ю", 2,
"ya", "я", 2,
"yo", "ё", 2,
0,
};

Map greek[] = {
"A", "Α", 1,
"'A", "Ά", 2,
"B", "Β", 1,
"G", "Γ", 1,
"D", "Δ", 1,
"E", "Ε", 1,
"'E", "Έ", 2,
"Z", "Ζ", 1,
"E!", "Η", 2,
"'E!", "Έ", 3,
"TH", "Θ", 2,
"Th", "Θ", 2,
"I", "Ι", 1,
"'I", "Ί", 2,
"K", "Κ", 1,
"L", "Λ", 1,
"M", "Μ", 1,
"N", "Ν", 1,
"KS", "Ξ", 2,
"Ks", "Ξ", 2,
"O", "Ο", 1,
"'O", "Ό", 2,
"P", "Π", 1,
"R", "Ρ", 1,
"S", "Σ", 1,
"T", "Τ", 1,
"U", "Υ", 1,
"'U", "Ύ", 2,
"F", "Φ", 1,
"CH", "Χ", 2,
"Ch", "Χ", 2,
"PS", "Ψ", 2,
"Ps", "Ψ", 2,
"O!", "Ω", 2,
"W", "Ω", 1,
"'O!", "Ώ", 3,
"'W", "Ώ", 2,
"a", "α", 1,
"'a", "ά", 2,
"b", "β", 1,
"v", "β", 1,
"g", "γ", 1,
"d", "δ", 1,
"e", "ε", 1,
"'e", "έ", 2,
"z", "ζ", 1,
"e!", "η", 2,
"'e!", "ή", 3,
"ii", "η", 2,
"'ii", "ή", 3,
"h", "η", 1,
"'h", "ή", 2,
"th", "θ", 2,
"i", "ι", 1,
"'i", "ί", 2,
"k", "κ", 1,
"l", "λ", 1,
"m", "μ", 1,
"n", "ν", 1,
"ks", "ξ", 2,
"x", "ξ", 1,
"o", "ο", 1,
"'o", "ό", 2,
"p", "π", 1,
"r", "ρ", 1,
"s ", "ς", 1,
"s.", "ς", 1,
"s,", "ς", 1,
"s\n", "ς", 1,
"s", "σ", 1,
"t", "τ", 1,
"u", "υ", 1,
"'u", "ΰ", 2,
"y", "υ", 1,
"'y", "ΰ", 2,
"f", "φ", 1,
"ch", "χ", 2,
"ps", "ψ", 2,
"o!", "ω", 2,
"w", "ω", 1,
"'o!", "ώ", 3,
"'w", "ώ", 2,
0
};

/* you can add other Map data here */

+ 92
- 0
ktrans.man View File

@@ -0,0 +1,92 @@
.TH KTRANS 1
.SH NAME
ktrans \- language transliterator
.SH SYNOPSIS
.B ktrans
.SH DESCRIPTION
The
.I ktrans
program works with pipefile(1) which pipes all the input from the keyboard to ktrans,
and ktrans itself transliterate typed letter sequnces intto characters in languages that
do not use the Latin character set, and pipes the result to
.B /dev/cons.
The language is selected by typing a control character:
.TP
.B ctl-e
return to default English mode (no transliteration).
.TP
.B ctl-n
Japanese hiragana:
interpret lower-case letters as a Hepburn representation
of hiragana.
In this mode, typing
.TP
.B Shift+Space
looks up the last `word' in a hiragana-kanji dictionary
and replaces it.
Subsequent Shift+Space characters cycle through the possibilities.
A word is the longest immediately preceding
unbroken string of hiragana characters.
.TP
.B ctl-l
If you want to put the hiragana not converted, you can type.
.TP
.B ctl-x
Read kana-kanji conversion dictionary once more, and renews it. This will be
convenient when you updated kana-kanji conversion dictionary on such acme
editor.In default, the kana-kanji conversion dictionary is read once at beginning and
to make a hashed table, which will be arranged so that the last selected candidate will
be the first candidate for later search.

.TP
.B ctl-k
Japanese katakana.
.TP
.B ctl-r
Russian: interpret letters as Cyrillic;
the transliteration is mostly phonetic, with
.B '
for
.IR myagkij-znak
(ь),
.B ''
for
.I tverdyj-znak
(ъ)
.I yo
for ё,
.B j
for
.IR i-kratkaya
(й).
.TP
.B ctl-g
Greek.
.PP
.SH FILES
.B /bin/pipefile /rc/bin/Kanji
.SH SOURCE
.B /sys/src/cmd/ktrans
.SH "SEE ALSO"
.IR rio(1)
.IR pipefile(1)
.SH EXAMPLE
If you want to make the Japanese text as below:

私は毎日35分以上歩いて、 更に10分電車に乗って学校に通います。
健康の維持にも役だっていますが、 なかなかたのしいものです。

your keyboard typing stream may be:

watashiHA[^t]mainichi[^t]35[^l]fun[^t]ijou[^t]aruIte,
[^t]saraNI[^t]10[^l]fun[^t]denshaNI[^t]noTte[^t]gakkouNI
[^t]kayoImasu.[^t]kenkouNO[^t]ijiNImo[^t]yakuDAtteimasuga,
[^t]nakanaka[^l]tanoshiI[^t]monodesu.[^l]

where [^t], [^l] indicates 'Shift+Space' and 'ctl-l', respectively. See README.kenji
for the details of this Japanese input method.
.SH BUGS
.PP
There is no way to generate the control characters literally.
At the most beggining of a new line, you have to begin with ctl-L
for successful kana-kanji conversion.

+ 622
- 0
license View File

@@ -0,0 +1,622 @@

LUCENT TECHNOLOGIES INC.
PLAN 9 OPEN SOURCE LICENSE AGREEMENT

PLEASE READ THIS AGREEMENT (INCLUDING THE EXHIBITS) CAREFULLY BEFORE
PROCEEDING. BY CLICKING ON THE "ACCEPT" BUTTON, OR BY DOWNLOADING,
INSTALLING, USING, COPYING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR
DERIVATIVE WORKS THEREOF, YOU ARE CONSENTING TO BE BOUND BY THIS
AGREEMENT. IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS AGREEMENT,
CLICK ON THE "DO NOT ACCEPT" BUTTON AND THE INSTALLATION/DOWNLOAD
PROCESS WILL NOT CONTINUE.

1. DEFINITIONS

1.1 "Agreement" means this Lucent Technologies Inc. Plan 9 Open Source
License Agreement (including Exhibits).
1.2 "Contributor(s)" means any individual or legal entity that creates
or contributes to a Modification of the Original Software.
1.3 "Licensee" means an individual or a legal entity entering into and
exercising rights under this Agreement. For the purposes hereunder,
Licensee includes any entity that controls, is controlled by, or is
under common control with Licensee. For purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise; or (ii) ownership of fifty percent (50%) or more of the
controlling shares or beneficial ownership of such entity. Licensee
is also referred to herein as "You" with "Your" as the possessive.
1.4 "Licensed Software" means the Original Software, Modifications, or
any combination of the Original Software and Modifications.
1.5 "Lucent" means Lucent Technologies Inc., a Delaware corporation
having an office at 600 Mountain Ave., Murray Hill, NJ 07974, its
related companies and/or affiliates.
1.6 "Modification(s)" means any addition, deletion, change, or
improvement to the Original Software or prior Modifications thereto.
Modifications do not include additions to the Original Software or
prior Modifications which (i) are separate modules of software which
may be distributed in conjunction with Licensed Software; or (ii) are
not derivative works of the Licensed Software itself.
1.7 "Object Code" means machine executable software code.
1.8 "Original Contributor" means Lucent and its Licensors, collectively.
1.9 "Original Software" means the Plan 9 Software, in both Source Code
form and Object Code form, and any associated documentation, as
furnished under this Agreement.
1.10 "Plan 9 Software" means a network operating system designed for
research into distributed services, applications and software
development.
1.11 "Recipient" means any individual or legal entity receiving the
Licensed Software under this Agreement, including all Contributors, or
receiving the Licensed Software under another license agreement as
authorized herein.
1.12 "Source Code" means human readable software code.

2.0 GRANT OF RIGHTS
2.1 Subject to the terms of this Agreement and to third party
intellectual property claims, Lucent grants to Licensee, a
royalty-free, nonexclusive, non-transferable, worldwide license to
use, reproduce, modify, execute, display, perform, distribute and
sublicense, the Original Software (with or without Modifications) in
Source Code form and/or Object Code form for commercial and/or
non-commercial purposes. This grant includes a nonexclusive and
non-transferable license under any patents which Lucent has a right to
license and which, but for this license, are unavoidably and
necessarily infringed by the execution of the inherent functionality
of the Original Software in the form furnished under this Agreement.
Nothing in this Agreement shall be construed as conferring in any way
(by implication, estoppel or otherwise) any license or right under any
existing or future patent claim which is directed to a combination of
the functionality of the Original Software with the functionality of
any other software programs, or a combination of hardware systems
other than the combination of the Original Software and the hardware
or firmware into which the Original Software is loaded. Distribution
of Licensed Software to third parties pursuant to this grant shall be
subject to the same terms and conditions as set forth in this
Agreement, and may, at Your option, include a reasonable charge for
the cost of any media. You may also, at Your option, charge for any
other software, product or service that includes or incorporates the
Original Software as a part thereof.

2.2 No right is granted to Licensee to create derivative works of or
to redistribute (other than with the Original Software or a derivative
thereof) the screen imprinter fonts identified in subdirectory
/lib/font/bit/lucida and printer fonts (Lucida Sans Unicode, Lucida
Sans Italic, Lucida Sans Demibold, Lucida Typewriter, Lucida Sans
Typewriter83), identified in subdirectory /sys/lib/postscript/font.

2.3 Exhibit A contains additional terms and conditions relating to the
printer fonts identified in subdirectory /sys/lib/ghostscript/font.
In the case of any conflict between the provisions of the body of this
Agreement and Exhibit A regarding such printer fonts, the provisions
of Exhibit A shall control.

2.4 The Original Software licensed herein contains material copyrights
by the Original Contributor, including but not limited to Lucent, B&H
Inc., and Y&Y Inc. No rights are granted with respect to Original
Software except as expressly provided herein.


3.0 DISTRIBUTION OBLIGATIONS

3.1 Modifications which You create or to which You contribute are
governed by the terms of this Agreement and must be made available
under the terms this Agreement in at least the same form as the Source
Code version of Original Software furnished hereunder. Any
distribution by You of the Source Code version of Licensed Software
must be made under the terms of this Agreement or any future version
of this Agreement under Section 11.0, and You must include a copy of
this Agreement with each and every copy of such Source Code version of
Licensed Software which You distribute. You may not offer or impose
any terms on any such Source Code version of Licensed Software that
alters or restricts the terms of the applicable version of this
Agreement or the Recipients' rights and obligations hereunder.
3.2 You must cause all Licensed Software to which You contribute, i.e.
Your Modifications, to contain a clear identification, e.g., a
separate file, documenting the changes made by You and identifying You
as the Contributor that reasonably allows subsequent Recipients to
identify the originator of the Modification. To the extent You create
at least one Modification, You may add Your name as a Contributor to
the requisite notice described in Section 3.3.
3.3 With respect to Your distribution of Licensed Software (or any
portion thereof), You must include the following information in a
conspicuous location governing such distribution (e.g., a separate
file) and on all copies of any Source Code version of Licensed
Software You distribute:
"The contents herein includes software initially developed by Lucent
Technologies Inc. and others, and is subject to the terms of the
Lucent Technologies Inc. Plan 9 Open Source License Agreement. A copy
of the Plan 9 open Source License Agreement is available at:
http://plan9.bell-labs.com/plan9dist/download.html or by contacting
Lucent Technologies at http: //www.lucent.com. All software
distributed under such Agreement is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
Lucent Technologies Inc. Plan 9 Open Source License Agreement for the
specific language governing all rights, obligations and limitations
under such Agreement. Portions of the software developed by Lucent
Technologies Inc. and others are Copyright (2000. All rights
reserved.
Contributor(s):___________________________"
3.4 You may distribute Licensed Software in Object Code form using
this Agreement, or under a license of Your choice provided that You
are in compliance with this Agreement and Your license: (a) complies
with the terms and conditions of this Agreement; (b) does not limit or
alter the Recipient's rights and obligations in the Source Code
version of the Licensed Software set forth in this Agreement; (c)
states that the Source Code version of the Licensed Software is
available from You, and describes how to it may be obtained by
Recipient; (d) effectively disclaims on behalf of Original Contributor
and all Contributors all warranties and conditions, express or
implied, including warranties or conditions of title or
non-infringement, and implied warranties or conditions of
merchantability and fitness for a particular purpose; (e) effectively
excludes on behalf of Original Contributor and all Contributors all
liability for damages, including direct, indirect, special,
incidental, and consequential damages; and (f) clearly states that any
terms which differ from this Agreement are offered by You alone, not
by Original Contributor or any other Contributor. You hereby agree to
indemnify Original Contributor or any other Contributor for any
liability incurred by Original Contributor or any other Contributor as
result of any such differing terms You offer in Your license.
3.5 You may not use the names "Lucent Technologies", "Bell Labs" or
any other name associated with Lucent or any Lucent trademark for any
purposes other than as specifically provided in this Section 3.0.
3.6 You must include all of the original copyright, labels or other
notices on the Licensed Software on any copies of the Licensed
Software which You make; and include with the distribution of any
Modifications You create a copy (or an offer to provide such a copy at
no charge) of the Licensed Software, on the same terms as set forth in
this Agreement.
3.7 While this Agreement contemplates the commercial use and
distribution of Licensed Software, commercial distributors of software
may, for a variety of reasons, accept certain responsibilities with
respect to customers, licensees, business partners and the like. As
such, if You or any Contributor include Licensed Software in a
commercial offering ("Commercial Contributor"), such Commercial
Contributor agrees to defend and indemnify Original Contributor and
all other Contributors (collectively "Indemnified Contributors")
against any liability, losses, damages and costs arising from claims,
lawsuits and other legal actions brought by any third party against
the Indemnified Contributors to the extent caused by the acts or
omissions of such Commercial Contributor in connection with its use or
distribution of Licensed Software in a commercial offering of any
kind.

4.0 MODIFICATIONS
You agree to provide the Original Contributor, at its request, with a
copy of the complete Source Code version, Object Code version and
related documentation for Modifications created or contributed to by
You if used for any purpose. Original Contributor and/or other
Contributors shall have unrestricted, nonexclusive, worldwide,
perpetual, royalty-free rights, to use, reproduce, modify, display,
perform, sublicense and distribute Your Modifications, and to grant
third parties the right to do so, including without limitation as a
part of or with the Licensed Software; and Original Contributor and/or
other Contributors shall have the right to license or to otherwise
transfer to third parties Your Modifications without notice,
obligation or recourse to You. You grant to Original Contributor,
Contributors and their respective licensees all rights and licenses
(including patents) as are necessary to incorporate the Modifications
created or contributed by You into the Licensed Software and to use,
distribute or otherwise exploit such Licensed Software without payment
or accounting to You.

5.0 TITLE
Title, ownership rights, and intellectual property rights in the
Original Software shall remain in the Original Contributor. Original
Contributor and/or the other Contributors reserve all rights not
expressly granted to You, and no other licenses are granted or
implied. The Licensed Software is protected by copyright laws and
treaties.

6.0 TERMINATION
6.1 The licenses and rights granted under this Agreement shall
terminate automatically if (i) You fail to comply with all of the
terms and conditions herein; or (ii) You initiate or participate in
any intellectual property action against Original Contributor and/or
another Contributor.

6.2 The rights and obligations of the parties hereto which by their
nature would continue beyond termination of this Agreement shall
survive and continue after any such termination of this Agreement.

6.3 Upon termination for any reason, You must destroy all copies of
the Licensed Software in Your possession. All sublicenses of Licensed
Software which were validly granted by You to third parties under this
Agreement shall survive such termination.

7.0 DISCLAIMER OF WARRANTY

YOU UNDERSTAND AND ACKNOWLEDGE THAT, TO THE FULLEST EXTENT PERMITTED
BY LAW, THE LICENSED SOFTWARE IS LICENSED UNDER THIS AGREEMENT FREE OF
CHARGE ON AN "AS IS" BASIS WITH ALL FAULTS, LATENT AND PATENT AND
WITHOUT ANY WARRANTY OF ANY TYPE. ORIGINAL CONTRIBUTOR AND THE OTHER
CONTRIBUTORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESSED OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT OF LIMITATION, ORIGINAL
CONTRIBUTOR AND THE OTHER CONTRIBUTORS MAKE NO REPRESENTATIONS OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR THAT THE USE OF
THE LICENSED SOFTWARE WILL NOT INFRINGE ANY PATENT OR OTHER
INTELLECTUAL PROPERTY RIGHT OF ANY THIRD PARTY AND IT SHALL BE THE
SOLE RESPONSIBILITY OF YOU TO MAKE SUCH DETERMINATION AS IS NECESSARY
WITH RESPECT TO THE ACQUISITION OF LICENSES UNDER PATENTS OR OTHER
INTELLECTUAL PROPERTY RIGHTS OF THIRD PARTIES. ORIGINAL CONTRIBUTOR
AND THE OTHER CONTRIBUTORS DO NOT WARRANT THAT THE FUNCTIONS OF THE
LICENSED SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT LICENSED
SOFTWARE OPERATION WILL BE ERROR-FREE OR UNINTERRUPTED. YOU ASSUME
THE RISK OF ANY AND ALL DAMAGE OR LOSS FROM USE, OR INABILITY TO USE,
THE LICENSED SOFTWARE. ORIGINAL CONTRIBUTOR AND THE OTHER
CONTRIBUTORS BEAR NO RESPONSIBILITY FOR CORRECTING THE LICENSED
SOFTWARE, SUPPLYING ASSISTANCE FOR FIXING, OR FOR COMMUNICATING KNOWN
ERRORS TO YOU PERTAINING TO THE LICENSED SOFTWARE FURNISHED HEREUNDER.

ORIGINAL CONTRIBUTOR AND THE OTHER CONTRIBUTORS SHALL NOT BE HELD TO
ANY LIABILITY WITH RESPECT TO ANY PATENT INFRINGEMENT OR ANY OTHER
CLAIM MADE BY YOU OR ANY THIRD PARTY ON ACCOUNT OF, OR ARISING FROM
THE USE OF, THE LICENSED SOFTWARE PROVIDED HEREUNDER.

SOME STATES DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THE
ABOVE EXCLUSION MAY NOT APPLY TO YOU. YOU MAY ALSO HAVE OTHER RIGHTS
THAT VARY FROM JURISDICTION TO JURISDICTION.

8.0 LIMITATION OF LIABILITY
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT, OR
OTHERWISE, SHALL ORIGINAL CONTRIBUTOR AND/OR THE OTHER CONTRIBUTORS BE
LIABLE TO YOU OR ANY OTHER THIRD PARTY FOR DAMAGES OF ANY KIND
INCLUDING, BUT NOT LIMITED TO, ANY DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WHATSOEVER
INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
COMMERCIAL DAMAGES OR LOSSES, EVEN IF THE ORIGINAL CONTRIBUTOR AND/OR
ANY OTHER CONTRIBUTORS SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. FURTHERMORE, SOME
JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL
OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT
APPLY TO YOU. TO THE EXTENT THAT ANY EXCLUSION OF DAMAGES ABOVE IS NOT
VALID, YOU AGREE THAT IN NO EVENT WILL ORIGINAL CONTRIBUTOR'S AND ALL
OTHER CONTRIBUTORS' TOTAL LIABILITY UNDER OR RELATED TO THIS AGREEMENT
EXCEED ONE THOUSAND DOLLARS ($1000.00 US).

9.0 EXPORT CONTROL
You acknowledge that the Licensed Software hereunder is "unrestricted
encryption source code" as the term is defined under the United States
Export Administration Regulations and is subject to export control
under such laws and regulations. You agree that, if you export or
re-export the Licensed Software or any modifications to it, You are
responsible for compliance with the United States Export
Administration Regulations and hereby indemnify the Original
Contributor and all other Contributors for any liability incurred as a
result.

10.0 U.S. GOVERNMENT RIGHTS
You may only acquire the Licensed Software on behalf of, or for
delivery to, any part of the United States Government, if the Licensed
Software is treated as commercial computer software and licensed to
the Government under the terms and conditions of this Agreement,
pursuant to the policies stated in 48 C.F.R. Section 12.212 (October
1995) or 48 C.F.R. Section 227.7202 (June 1995), as applicable.

11.0 LICENSE VERSIONS
LUCENT, at its sole discretion, may from time to time publish a
revised and/or new version of this Agreement (each such revised or new
version shall carry a distinguishing version number) which shall
govern all copies of Licensed Software downloaded after the posting of
such revised or new version of this Agreement.

12.0 MISCELLANEOUS
This Agreement sets forth the entire agreement and understanding
between the parties as to the subject matter hereof and merges all
prior discussions between them. This Agreement shall be governed by
the laws of the State of New York, USA, excluding its conflict of law
provisions. The application of the United Nations Convention of
Contracts for the International Sale of Goods is expressly excluded.
YOUR DOWNLOAD, INSTALLATION AND USE, MODIFICATION OR DISTRIBUTION OF
THE LICENSED SOFTWARE IS EXPRESSLY MADE CONDITIONAL ON YOUR ASSENT TO
THE TERMS SET FORTH HEREIN. You further agree and acknowledge that by
clicking on the "ACCEPT" button below, You shall have manifested
acceptance to enter into this Agreement and shall be deemed to have
manually signed and executed this Agreement making this an enforceable
Agreement between the parties. If any provision of this Agreement is
held to be unenforceable, such provision shall be reformed only to the
extent necessary to make it enforceable.



EXHIBIT A - GNU GENERAL PUBLIC LICENSE


GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
verbatim copies of this license document, but changing it is not
allowed.

Preamble

The licenses for most software are designed to take away your freedom
to share and change it. By contrast, the GNU General Public License
is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.

When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.

We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on,
we want its recipients to know that what they have is not the
original, so that any problems introduced by others will not reflect
on the original authors' reputations.

Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at
all.
The precise terms and conditions for copying, distribution and
modification follow.

GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License applies to any program or other work which contains a
notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the Program
(independent of having been made by running the Program). Whether
that is true depends on what the Program does.

1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a
fee.

2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.

b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any part
thereof, to be licensed as a whole at no charge to all third parties
under the terms of this License.

c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the most ordinary way, to print or display an announcement
including an appropriate copyright notice and a notice that there is
no warranty (or else, saying that you provide a warranty) and that
users may redistribute the program under these conditions, and telling
the user how to view a copy of this License. (Exception: if the
Program itself is interactive but does not normally print such an
announcement, your work based on the Program is not required to print
an announcement.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections 1
and 2 above on a medium customarily used for software interchange; or,

b) Accompany it with a written offer, valid for at least three years,
to give any third party, for a charge no more than your cost of
physically performing source distribution, a complete machine-readable
copy of the corresponding source code, to be distributed under the
terms of Sections 1 and 2 above on a medium customarily used for
software interchange; or,

c) Accompany it with the information you received as to the offer to
distribute corresponding source code. (This alternative is allowed
only for noncommercial distribution and only if you received the
program in object code or executable form with such an offer, in
accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.

9. The Free Software Foundation may publish revised and/or new
versions of the General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Program does not specify a
version number of this License, you may choose any version ever
published by the Free Software Foundation.

10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the
author to ask for permission. For software which is copyrighted by
the Free Software Foundation, write to the Free Software Foundation;
we sometimes make exceptions for this. Our decision will be guided by
the two goals of preserving the free status of all derivatives of our
free software and of promoting the sharing and reuse of software
generally.

NO WARRANTY

11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

END OF TERMS AND CONDITIONS



YOU ACKNOWLEDGE THAT YOU HAVE READ THIS AGREEMENT (INCLUDING THE
EXHIBITS) AND UNDERSTAND IT, AND THAT BY CLICKING ON THE "ACCEPT"
BUTTON BELOW AND INSTALLING/DOWNLOADING THE SOFTWARE YOU ACCEPT AND
AGREE TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS AGREEMENT.

Plan 9 Open Source License - Version 1.0 - 06/03/00 1


+ 429
- 0
main.c View File

@@ -0,0 +1,429 @@
/*
* Mostly based on the original source codes of Plan 9 release 2
* distribution.
* by Kenji Okamoto, August 4 2000
* Osaka Prefecture Univ.
* okamoto@granite.cias.osakafu-u.ac.jp
*/

#include <u.h>
#include <libc.h>
#include <stdio.h>
#include "ktrans.h"
#include "jisho.h"

#define LSIZE 256

Rune lbuf[LSIZE]; /* hiragana buffer for key input written by send() */
Map *table = hira; /* default language conversion table */
uchar okurigana[LSIZE]; /* buffer for okurigana */
char okuri = 0; /* buffer/flag for capital input char */
int in, out;
int llen, olen, joshi = 0;
int natural = 1; /* not Japanese but English mode */

int changelang(int);
int dotrans(Dictionary*);
int noter(void *, char *);
int nrune(char *);
void send(uchar *, int);
Map *match(uchar *p, int *nc, Map *table);

extern Dictionary *openQDIC(char *);
extern KouhoList *getKouhoHash(Dictionary*, char *);
extern KouhoList *getKouhoFile(DicList*, char *);
extern void freeQDIC(Dictionary*);
extern void selectKouho(KouhoList **, KouhoList*);


void
main(int argc, char **argv)
{

uchar *bp, *ep, buf[128];
Map *mp;
int nchar, wantmore;
int n, c;
char jishoname[64], *dicname;
Dictionary *jisho;

USED(argc);
USED(argv);

dicname = getenv("KTJISHO");
if(!dicname)
dicname = strcat(getenv("home"), "/lib/ktrans-jisho");
strcpy(jishoname, dicname);
jisho = openQDIC(jishoname);

in = _IO_stream[0].fd;
out = _IO_stream[1].fd;

if (rfork(RFPROC))
exits(0); /* parent process will die */


atnotify(noter, 1);

bp = ep = buf; /* bp = base point of input string */
/* ep = end point of input string */
/* buf = unsigned buffer array */
wantmore = 0;
for (;;) { /* key board input loop */
getmore:
if (bp>=ep || wantmore) {
if (wantmore==0)
bp = ep = buf; /* clear all */
n = read(in, ep, &buf[sizeof(buf)]-ep); /* read from stdin */
if (n<=0)
exits("");
ep += n; /* ep => end point of input string */
*ep = '\0';
}
while (bp<ep) { /* there are input data */
if (table == hira && natural != 1 && (*bp>'A' && *bp<='Z') && ep-bp<2
&& !strchr("EIOU", *bp)) {
wantmore = 1;
goto getmore;
}
if (!fullrune((char *)bp, ep-bp)) { /* not enough length of input */
wantmore = 1;
goto getmore;
}
wantmore = 0;

if (*bp=='') { /* ^x read ktrans-jisho once more */
freeQDIC(jisho);
jisho = openQDIC(jishoname);
llen = 0;
olen = okuri = joshi = 0;
wantmore=0;
bp=ep=buf;
continue;
}

if (*bp=='') { /* Shift+Space (start translate comannd) */
c = dotrans(jisho);
if (c)
*bp = c; /* pointer to translated rune */
else
bp++;
continue;
}
if (*bp==' ') { /* ^l (no translate comannd) */
bp++;
llen = 0;
olen = okuri = joshi = 0;
continue;
}
if (changelang(*bp)) { /* change language mode OK */
bp++;
olen = okuri = joshi = 0;
continue;
}
if (natural || *bp<=' ' || *bp>='{') { /* English mode but not ascii */
Rune r;
int rlen = chartorune(&r, (char *)bp);
send(bp, rlen); /* write bp to /dev/cons */
bp += rlen;
continue;
}
if (table == hira && (*bp >= 'A' && *bp <= 'Z') && (*(bp+1) < 'A'
|| *(bp+1) > 'Z')) {
*bp = okuri = tolower(*bp);
joshi = olen = 0;
} else if (table == hira && (*bp >= 'A' && *bp <= 'Z') &&
(*(bp+1) >= 'A' && *(bp+1) <= 'Z')) {
*bp = okuri = tolower(*bp);
*(bp+1) = tolower(*(bp+1));
joshi = 1;
olen = 0;
}

/* BUG! we have to hit ^l at every beginning of the new line... sorry
if (table == hira && *bp == '\n') {
Rune r;
int rlen = chartorune(&r, (char *)bp);
send(bp, rlen);
bp++;
olen = okuri = joshi = 0;
continue;
}
*/
mp = match(bp, &nchar, table);
if (mp == 0) {
if (nchar>0) { /* match, longer possible */
wantmore++;
break;
}
send(bp++, 1); /* alphabet in kana mode */
} else {
send((uchar*)mp->kana, strlen(mp->kana));
bp += nchar;
}
}
}
}

int
noter(void *x, char *note)
{
USED(x);
if (strcmp(note, "interrupt")==0)
return 1;
else
return 0;
}

int
min(int a, int b)
{
return a<b? a: b;
}

/*
*send UTF string (p) with length (n) to stdout
* and write rune (r) in global lbuf[] buffer
* or okurigana[] buffer if okuri (verb or joshi) mode
*/

void
send(uchar *p, int n)
{
Rune r;
uchar *ep;

if (write(out, (char *)p, n) != n) /* write to stdout */
exits("");

if (llen>LSIZE-64) {
memmove((char*)lbuf, (char*)lbuf+64, 64*sizeof(Rune));
llen -= 64;
}
if (table!=hira || natural)
return;
ep = p+n;
if(okuri) {
while (olen<LSIZE && p<ep) okurigana[olen++] = *p++;
}
else {
while (llen<LSIZE && p<ep) {
p += chartorune(&r, (char*)p);
if (r=='\b') { /* handle backspace */
if (llen>0)
llen--;
continue;
}
if (r==0x80) /* ignore view key */
continue;
/*
if (r<0x3041 || r>0x309e) { reset if out of hiragana range
llen = 0; we use this for okuri-ari entries
continue;
}
*/
lbuf[llen++] = r;
}
}

}

/*
* Romaji to Hiragana/Katakana conversion
* romaji shoud be input as small letter
* returns the matched address in table, hira, kata etc.
* nc: nubmer of character(return value)
*/

Map *
match(uchar *p, int *nc, Map *table)
{
register Map *longp = 0, *kp;
static char last;
int longest = 0;

*nc = -1;
for (kp=table; kp->roma; kp++) {
if (*p == *kp->roma) {
int lr = strlen(kp->roma);
int len = min(lr, strlen((char *)p));
if (strncmp(kp->roma, (char *)p, len)==0) {
if (len<lr) {
*nc = 1;
return 0;
}
if (len>longest) {
longest = len;
longp = kp;
}
}
}
}
if (longp) {
last = longp->roma[longest-1];
*nc = longp->advance;
}
return(longp);
}

int
changelang(int c)
{
if (c==' ') { /* ^k (Japanese Katakana input mode) */
natural = 0;
table = kata;
llen = 0;
return 1;
}

if (c=='') { /* ^n (Japanese hiragana mode ) */
natural = 0;
llen = 0;
table = hira;
return 1;
}

if (c=='') { /* ^e (English mode) */
natural = 1;
llen = 0;
return 1;
}

if (c=='') { /* ^r (Russian mode) */
natural = 0;
table = cyril;
llen = 0;
return 1;
}
if (c=='') { /* ^g (Greek mode ) */
natural = 0;
table = greek;
llen = 0;
return 1;
}
return 0;

}

/*
* write translated kanji runes to stdout
* and returns last charcter if it's not Shift+Space.
* if the last is Shift+Space, proceed translation to next kouho
*/

int
dotrans(Dictionary *dic)
{
Rune *res, r[1];
char v[1024], *p, tbuf[64], hirabuf[64];
int j, lastlen, nokouho = 0;
char ch;
KouhoList *fstkouho, *currentkouho;

if (llen==0)
return 0; /* not use kanji transform function */
if (okuri && joshi != 1) {
lbuf[llen++] = (Rune)okuri;
lbuf[llen] = 0;
}else
lbuf[llen] = 0;
okurigana[olen] = 0;

/*
* search the mached index to the key word from the dict hash table , and
* returns a pointer to the matched kouho if success,
* or returns 0 if failed.
*/

res = lbuf;
for (j=0; *res != L'\0'; j += runetochar(v+j, res++));
v[j++] = '\0';
strcpy(tbuf, v);
strcpy(hirabuf, v); /* to remeber the initial hiragana input */
if (okuri && joshi != 1) hirabuf[strlen(hirabuf) - 1] = '\0'; /* verb mode */
if(!(fstkouho = getKouhoHash(dic, v))) { /* not found */
llen = olen = okuri = joshi = 0;
okurigana[0] = 0;
return 0;
}

currentkouho = fstkouho;
for(;;) {
p = currentkouho->kouhotop; /* p to the head of kanji kouho array */
lastlen = nrune(tbuf); /* number of rune chars */
if (okuri && joshi != 1) /* verb mode */
for (j=0; j<lastlen-1; j++)
write(out, "\b", 1); /* clear hiragana input */
else
for (j=0; j<lastlen; j++)
write(out, "\b", 1); /* clear hiragana input */
if (okuri) {
lastlen = nrune((char *)okurigana);
for (j=0; j<lastlen; j++) write(out, "\b", 1);
}
write(out, p, strlen(p)); /* write kanji to stdout */
if (okuri) write(out, (char *)okurigana, olen);

if (read(in, &ch, 1)<=0) /* read from stdin */
exits(0);

if (ch == '') { /* if next input is Shift+Space, once more */
if(currentkouho->nextkouho != 0) { /* have next kouho */
nokouho = 0;
strcpy(tbuf, p);
currentkouho = currentkouho->nextkouho;
if (okuri && joshi != 1) { /* verb mode */
for (j=0; j<nrune(tbuf); j++)
write(out, "\b", 1);
}
continue;
} else { /* the last kouho */
if (okuri) {
lastlen = nrune((char *)okurigana);
for (j=0; j<lastlen; j++)
write(out, "\b", 1);
}
for (j=0, lastlen=0; *p != 0; p += j) {
j = chartorune(r, p);
lastlen++;
}
for (j=0; j<lastlen; j++)
write(out, "\b", 1);
if(hirabuf[0])
write(out, hirabuf, strlen(hirabuf));
if(okurigana[0])
write(out, (char *)okurigana, olen);
olen = okuri = joshi = 0;
okurigana[0] = 0;
nokouho = 1;
break;
}
}
else {
if(!nokouho) /* learn the previous use of the kouho */
selectKouho(&(fstkouho->dicitem->kouho), currentkouho);
olen = okuri = joshi = 0;
okurigana[0] = 0;
break;
}
}
llen = 0;
return ch;
}

/*
* returns number of characters in the pointed Rune
*/
int
nrune(char *p)
{
int n = 0;
Rune r;

while (*p) {
p += chartorune(&r, p);
n++;
}
return n;
}

+ 467
- 0
main.c.cinap View File

@@ -0,0 +1,467 @@
/*
* Mostly based on the original source codes of Plan 9 release 2
* distribution.
* by Kenji Okamoto, August 4 2000
* Osaka Prefecture Univ.
* okamoto@granite.cias.osakafu-u.ac.jp
*/

#include <u.h>