9front - general discussion about 9front
 help / color / mirror / Atom feed
From: npmania <np@mkv.li>
To: 9front@9front.org
Subject: [9front] [PATCH] ktrans: fix Korean input
Date: Sun, 24 Mar 2024 19:57:42 +0900	[thread overview]
Message-ID: <20240324195742.15746b88@coaster> (raw)

Before applying the patch, /lib/ktrans/hangul.map file has to be
replaced with new one to work properly. The file was generated to
provide correct mapping between QWERTY and Dubeolsik layout. Due to
it's size, I have uploaded it on:
http://okturing.com/src/19014/body

This patch implements two specific behaviors of Dubeolsik layout.

dubeollkup function makes Jongseong(final consonant) to be treated as
Choseong(initial consonant) when possible. For example, QWERTY input
"zhem" in Dubeolsik has to be "코드", not "콛ㅡ" where switched
Jongseong is "ㄷ".

dubeolbksp function emits out syllable remaining after single
backspace. So when user presses backspace on "코드", the expected output
is "코ㄷ", still allowing user to edit latter syllable, rather than
"코" without dubeolbksp. This should only apply to last syllable
considering it's de facto in Dubeolsik implementations.

diff 57b4f2b8e4c5037f726d71c71479a4561ab03137 uncommitted
--- a/sys/man/1/ktrans
+++ b/sys/man/1/ktrans
@@ -167,8 +167,8 @@
 standard diacritic suffixes.
 .SS KOREAN
 Mapping is done by emulating a Dubeolsik layout, with each Latin
-character mapping to a single Jamo. Sequences of up to three Jamo
-are automatically converted to Hangul syllables.
+character mapping to a single Jamo. Sequences of Jamo are automatically
+converted to Hangul syllables.
 .SH EXAMPLES
 To type the following Japanese text:

--- a/sys/src/cmd/ktrans/main.c
+++ b/sys/src/cmd/ktrans/main.c
@@ -581,6 +581,59 @@
 }

 static void
+dubeolbksp(Str *line)
+{
+	Map lkup;
+
+	popstr(line);
+	/* lookup and emit remaining Jamo to output */
+	if(hmapget(hangul, line->b, &lkup) < 0)
+		return;
+	emitutf(output, lkup.kana, 0);
+}
+
+static void
+dubeollkup(Str *line)
+{
+	Map lkup;
+	char buf[UTFmax*2];
+	char *e2, *e1;
+
+	e1 = peekstr(line->p, line->b);
+	if(e1 != line->b){
+		e2 = peekstr(e1, line->b);
+		pushutf(buf, buf+sizeof buf, e2, utflen(e2));
+	}else
+		pushutf(buf, buf+sizeof buf, e1, utflen(e1));
+
+	if(hmapget(hangul, line->b, &lkup) < 0){
+		if(hmapget(hangul, buf, &lkup) < 0){
+			resetstr(line, nil);
+			line->p = pushutf(line->p, strend(line), e1, utflen(e1));
+			if(hmapget(hangul, line->b, &lkup) < 0)
+				return;
+		}else{
+			/* treat Jongseong as Choseong when it matches with new Jamo */
+			popstr(line);
+			popstr(line);
+			hmapget(hangul, line->b, &lkup);
+			emitutf(output, backspace, 2);
+			emitutf(output, lkup.kana, 0);
+
+			hmapget(hangul, buf, &lkup);
+			emitutf(output, lkup.kana, 0);
+			line->p = pushutf(line->b, strend(line), buf, utflen(buf));
+			return;
+		}
+	}
+	if(utflen(line->b) == 1)
+		emitutf(output, backspace, 1);
+	else
+		emitutf(output, backspace, 2);
+	emitutf(output, lkup.kana, 0);
+}
+
+static void
 keythread(void*)
 {
 	int lang;
@@ -645,6 +698,10 @@
 				resetstr(&line, nil);
 				continue;
 			} else if(r == '\b'){
+				if(lang == LangKO){
+					dubeolbksp(&line);
+					continue;
+				}
 				popstr(&line);
 				continue;
 			}
@@ -652,6 +709,9 @@
 			line.p = pushutf(line.p, strend(&line), p, 1);
 			if(lang == LangVN){
 				telexlkup(&line);
+				continue;
+			}else if(lang == LangKO){
+				dubeollkup(&line);
 				continue;
 			}
 			if(maplkup(lang, line.b, &lkup) < 0){
--- a/sys/src/cmd/ktrans/test.c
+++ b/sys/src/cmd/ktrans/test.c
@@ -43,6 +43,9 @@
 	"\fddaua", L"đâu",
 	"\fhoir", L"hỏi",
 	"\fgi\fof", L"giò",
+
+	"\f\x13gpffhdnjfemsms wlruqwksw\bgdk, wha tlstjsgks rj djqtdj?",
+	L"헬로월드는 지겹잖아, 좀 신선한 거 없어?",
 };

 char*

             reply	other threads:[~2024-03-24 10:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 10:57 npmania [this message]
2024-03-29 19:23 ` Jacob Moody

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240324195742.15746b88@coaster \
    --to=np@mkv.li \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).