ref: 920367d75626ca3077dc881dcba8c19530bbab03
parent: 8e3dffdf43bdb9470ed9d5f96f1b1b282a8ce37e
author: Ethan Long <ethandavidlong@gmail.com>
date: Sun Jun 27 04:52:24 EDT 2021
Added a test program, and a basic romaji to kana program.
--- /dev/null
+++ b/src/mkfile
@@ -1,0 +1,2 @@
+%: %.c
+ 8c $stem.c && 8l -o $stem.out $stem.8
--- /dev/null
+++ b/src/test.c
@@ -1,0 +1,47 @@
+#include <u.h>
+#include <libc.h>
+#include <String.h>
+
+void
+test(char in[2], int dakuten, Rune* out)
+{
+ Rune letter = (Rune)((int)(L'か') + dakuten);
+ Rune str[] = {letter};
+ //print("%S, %C", str, letter);
+ out[0] = letter;
+ return;
+}
+
+Rune*
+withinfunc(void)
+{
+ Rune str[3];
+ test("aa", 1, str);
+ return(str);
+}
+
+void
+main()
+{
+ Rune str[3];
+ test("aa", 1, str);
+ print("%S", str);
+
+ Rune* string2 = withinfunc();
+ print("%S\n", str);
+
+ print("%d , %d\n", L'あ' , L'か');
+ print("%d , %d\n", L'か' , L'さ');
+ print("%d , %d\n", L'さ' , L'た');
+ print("%d , %d\n", L'た' , L'な');
+ print("%d , %d\n", L'な' , L'は');
+ print("%d , %d\n", L'は' , L'ま');
+ print("%d , %d\n", L'ま' , L'や');
+ print("%d , %d\n", L'や' , L'ら');
+ print("%d , %d\n", L'ら' , L'わ');
+ for(int i = 0; i < 100; i++){
+ print("%C\n", (Rune)(12353 + i));
+ }
+
+ exits(nil);
+}
--- /dev/null
+++ b/src/to-kana.c
@@ -1,0 +1,323 @@
+#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);
+}