ref: 920367d75626ca3077dc881dcba8c19530bbab03
dir: /src/to-kana.c/
#include <u.h> #include <stdio.h> #include <libc.h> #include <String.h> void kanafill(Rune base, char in[2], int dakuten, Rune* out) { switch(base){ /* Special Boys */ case L'や': switch(in[0]){ case 'a': out[0] = L'や'; break; case 'u': out[0] = L'ゆ'; break; case 'o': out[0] = L'よ'; break; default: break; } break; case L'ん': out[0] = L'ん'; break; /* は family has marudakuten */ case L'は': switch(in[0]){ case 'a': out[0] = (Rune)((int)base + dakuten); break; case 'i': out[0] = (Rune)((int)base + 3 + dakuten); break; case 'u': out[0] = (Rune)((int)base + 6 + dakuten); break; case 'e': out[0] = (Rune)((int)base + 9 + dakuten); break; case 'o': out[0] = (Rune)((int)base + 12 + dakuten); break; case 'y': out[0] = (Rune)((int)base + 3 + dakuten); switch(in[1]){ case 'a': out[1] = L'ゃ'; break; case 'u': out[1] = L'ゅ'; break; case 'o': out[1] = L'ょ'; break; default: break; } default: break; } break; /* families with no dakuten or small forms */ case L'ら': case L'ま': case L'な': case L'わ': switch(in[0]){ case 'a': out[0] = base; break; case 'i': out[0] = (Rune)((int)base + 1); break; case 'u': out[0] = (Rune)((int)base + 2); break; case 'e': out[0] = (Rune)((int)base + 3); break; case 'o': out[0] = (Rune)((int)base + 4); break; case 'y': out[0] = (Rune)((int)base + 1); switch(in[1]){ case 'a': out[1] = L'ゃ'; break; case 'u': out[1] = L'ゅ'; break; case 'o': out[1] = L'ょ'; break; default: break; } default: break; } break; /* families with just dakuten */ case L'か': case L'さ': switch(in[0]){ case 'a': out[0] = (Rune)((int)base + dakuten); break; case 'i': out[0] = (Rune)((int)base + 2 + dakuten); break; case 'u': out[0] = (Rune)((int)base + 4 + dakuten); break; case 'e': out[0] = (Rune)((int)base + 6 + dakuten); break; case 'o': out[0] = (Rune)((int)base + 8 + dakuten); break; case 'y': out[0] = (Rune)((int)base + 2 + dakuten); switch(in[1]){ case 'a': out[1] = L'ゃ'; break; case 'u': out[1] = L'ゅ'; break; case 'o': out[1] = L'ょ'; break; default: break; } default: break; } break; /* た family has small つ and dakuten */ case L'た': switch(in[0]){ case 'a': out[0] = (Rune)((int)base + dakuten); break; case 'i': out[0] = (Rune)((int)base + 2 + dakuten); break; case 'u': out[0] = (Rune)((int)base + 5 + dakuten); break; case 'e': out[0] = (Rune)((int)base + 7 + dakuten); break; case 'o': out[0] = (Rune)((int)base + 9 + dakuten); break; case 'y': out[0] = (Rune)((int)base + 2 + dakuten); switch(in[1]){ case 'a': out[1] = L'ゃ'; break; case 'u': out[1] = L'ゅ'; break; case 'o': out[1] = L'ょ'; break; default: break; } default: break; } break; default: break; } return; } void kanalook(char buf[3], Rune* str) { print("%s\n", buf); char end[2]; end[0] = buf[1]; end[1] = buf[2]; switch(buf[0]){ /* あ family */ case 'a': str[0] = L'あ'; break; case 'i': str[0] = L'い'; break; case 'u': str[0] = L'う'; break; case 'e': str[0] = L'え'; break; case 'o': str[0] = L'お'; break; /* か family */ case 'k': kanafill(L'か', end, 0, str); break; case 'g': kanafill(L'か', end, 1, str); break; /* さ family */ case 's': kanafill(L'さ', end, 0, str); break; case 'z': kanafill(L'さ', end, 1, str); break; case 'j': if(buf[1] != 'y' && buf[1] != 'i'){ end[0] = 'y'; end[1] = buf[1]; kanafill(L'さ', end, 1, str); } else kanafill(L'さ', end, 1, str); break; /* た family */ case 't': kanafill(L'た', end, 0, str); break; case 'c': if(buf[1] != 'y' && buf[1] != 'i'){ end[0] = 'y'; end[1] = buf[1]; kanafill(L'た', end, 0, str); } else kanafill(L'た', end, 0, str); break; case 'd': kanafill(L'た', end, 1, str); break; /* な family (and ん) */ case 'n': kanafill(L'な', end, 0, str); break; /* は family */ case 'h': kanafill(L'は', end, 0, str); break; case 'f': end[0] = 'f'; end[1] = buf[1]; kanafill(L'は', end, 0, str); break; case 'b': kanafill(L'は', end, 1, str); break; case 'p': kanafill(L'は', end, 2, str); break; /* ま family */ case 'm': kanafill(L'ま', end, 0, str); break; /* や family */ case 'y': kanafill(L'や', end, 0, str); break; /* ら family */ case 'r': kanafill(L'ら', end, 0, str); break; /* わ family */ case 'w': kanafill(L'わ', end, 0, str); break; default: break; } print("%S\n", str); return; } void main(int argc, char *argv[]) { ARGBEGIN{ default: print("No commandline arguments have been implemented yet\n"); break; }ARGEND; int fp = fileno(stdin); char buf[3]; read(fp, buf, 2); Rune kana[2]; kanalook(buf, kana); print("%s\n", buf); print("%S\n", kana); print("Hello World\n"); exits(nil); }