Skip to content

Commit

Permalink
chore: format comment styles
Browse files Browse the repository at this point in the history
* Prefer use single line comment with //
  * To describe simple comment about codeblock below
  * To describe after the code line
* Prefer use multiple line comment with /* */
  * Always use /* */ for multiple line comment
  * To emphasize code block below
    (ex. Interface Implementation)
  * Documentation such as doxygen (not applied yet)

Signed-off-by: JaeSang Yoo <[email protected]>
  • Loading branch information
JSYoo5B committed Apr 15, 2022
1 parent 219f3e2 commit 5c22882
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
74 changes: 42 additions & 32 deletions hanjpautomata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
#include <gmodule.h>
#include <hangul.h>

/* Extern function signature which isn't exported in libhangul header */
// Extern function signature which aren't exported in libhangul header
extern ucschar hangul_choseong_to_jongseong(ucschar c);
extern ucschar hangul_jongseong_to_choseong(ucschar c);

/* Kana Table index enums */

/*
* Kana Table
*/
// table indexing enums
enum
{
KANA_VOWEL_A,
// Vowel indices
KANA_VOWEL_A = 0,
KANA_VOWEL_I,
KANA_VOWEL_U,
KANA_VOWEL_E,
KANA_VOWEL_O
};
enum
{
KANA_CONSONANT__,
KANA_VOWEL_O,
// Consonant indices
KANA_CONSONANT__ = 0,
KANA_CONSONANT_K,
KANA_CONSONANT_S,
KANA_CONSONANT_T,
Expand All @@ -30,28 +33,30 @@ enum
KANA_CONSONANT_W
};

// Fifty notes
// For example か(ka) = KANA_TABLE[KANA_CONSONANT_K][KANA_VOWEL_A]
// Fifty notes, ex. か(ka) = KANA_TABLE[KANA_CONSONANT_K][KANA_VOWEL_A]
static const gunichar KANA_TABLE[][5] = {
// A, I, U, E, O
{0x3042, 0x3044, 0x3046, 0x3048, 0x304A}, // A
{0x304B, 0x304D, 0x304F, 0x3051, 0x3053}, // KA
{0x3055, 0x3057, 0x3059, 0x305B, 0x305D}, // SA
{0x305F, 0x3061, 0x3064, 0x3066, 0x3068}, // TA
{0x306A, 0x306B, 0x306C, 0x306D, 0x306E}, // NA
{0x306F, 0x3072, 0x3075, 0x3078, 0x307B}, // HA
{0x307E, 0x307F, 0x3080, 0x3081, 0x3082}, // MO
{0x3084, 0x0000, 0x3086, 0x0000, 0x3088}, // YA
{0x3089, 0x308A, 0x308B, 0x308C, 0x308D}, // RA
{0x308F, 0x3090, 0x0000, 0x3091, 0x3092} // WA
// _A, _I, _U, _E, _O
{ 0x3042, 0x3044, 0x3046, 0x3048, 0x304A }, // _
{ 0x304B, 0x304D, 0x304F, 0x3051, 0x3053 }, // K_
{ 0x3055, 0x3057, 0x3059, 0x305B, 0x305D }, // S_
{ 0x305F, 0x3061, 0x3064, 0x3066, 0x3068 }, // T_
{ 0x306A, 0x306B, 0x306C, 0x306D, 0x306E }, // N_
{ 0x306F, 0x3072, 0x3075, 0x3078, 0x307B }, // H_
{ 0x307E, 0x307F, 0x3080, 0x3081, 0x3082 }, // M_
{ 0x3084, 0x0000, 0x3086, 0x0000, 0x3088 }, // Y_
{ 0x3089, 0x308A, 0x308B, 0x308C, 0x308D }, // R_
{ 0x308F, 0x3090, 0x0000, 0x3091, 0x3092 } // W_
};

// Other Kana characters (which cannot be indexed through KANA_TABLE
static const gunichar KANA_SMALL_TU = 0x3063;
static const gunichar KANA_NN = 0x3093;

/* Jamo to Kana conversion */
// Jamo to Kana conversion results
#define KANA_CONV_SUCCESS (0)
#define KANA_CONV_FAIL (-1)

// Jamo to Kana conversion functions
static gint choseong_to_kana_index(gunichar cho, gint *conso_idx, gint *diacrit);
static gint jungseong_to_kana_index(gunichar jung, gint *vowel_idx);
static gint jongseong_to_kana(gunichar jong, gunichar *kana);
Expand All @@ -71,13 +76,15 @@ typedef union
#define N_COMBINE_TABLE_ELEMENTS 30


/* Automata Interface Definition */
/*
* Automata Interface Definition
*/
G_DEFINE_INTERFACE(HanjpAutomata, hanjp_am, G_TYPE_OBJECT)


static void hanjp_am_default_init(HanjpAutomataInterface *iface)
{
/* add properties and signals to the interface here */
// Nothing to do
}


Expand Down Expand Up @@ -129,7 +136,9 @@ void hanjp_am_flush(HanjpAutomata *am)
}


/* AutomataBase Implementation */
/*
* AutomataBase Implementation
*/
typedef struct
{
HanjpBuffer buffer;
Expand All @@ -138,6 +147,7 @@ typedef struct
guint32 combine_table_vals[N_COMBINE_TABLE_ELEMENTS];
} HanjpAutomataBasePrivate;


G_DEFINE_TYPE_WITH_PRIVATE(HanjpAutomataBase, hanjp_am_base, G_TYPE_OBJECT)


Expand Down Expand Up @@ -226,7 +236,7 @@ static void divide_jungseong(HanjpBuffer *buffer, gint *conso_idx)
}
}


static gint jungseong_to_kana_index(gunichar jung, gint *vowel_idx)
{
switch (jung) {
Expand Down Expand Up @@ -310,7 +320,7 @@ static gint hanjp_am_base_to_kana(HanjpAutomata *am, GArray *dest, HanjpBuffer *

hanjp_buffer_clear_filler(buffer);

// check whether batchim is available and move choseong to jongseong if conditions are met
// When Batchim is available, then move choseong to jongseong
if (buffer->cho != 0 && buffer->jung == 0 && dest->len != 0) {
kana = g_array_index(dest, gunichar, dest->len - 1); // Last kana character
if(kana != KANA_NN && kana != KANA_SMALL_TU) {
Expand All @@ -319,7 +329,7 @@ static gint hanjp_am_base_to_kana(HanjpAutomata *am, GArray *dest, HanjpBuffer *
}
}

//eat Choseong and Jungseong
// eat Choseong and Jungseong
while (buffer->cho || buffer->jung || buffer->jung2) {
// Convert choseong into kana indexing
jamo = hanjp_buffer_pop_choseong(buffer);
Expand Down Expand Up @@ -471,11 +481,12 @@ static void hanjp_am_base_class_init(HanjpAutomataBaseClass *klass)
}


/* AutomataBuiltin Implementation */
/*
* AutomataBuiltin Implementation
*/
static void hanjp_am_builtin_interface_init(HanjpAutomataInterface *iface);
G_DEFINE_TYPE_WITH_CODE(HanjpAutomataBuiltin, hanjp_am_builtin, HANJP_TYPE_AM_BASE,
G_IMPLEMENT_INTERFACE(HANJP_TYPE_AM,
hanjp_am_builtin_interface_init))
G_IMPLEMENT_INTERFACE(HANJP_TYPE_AM, hanjp_am_builtin_interface_init))


static void hanjp_am_builtin_init(HanjpAutomataBuiltin *am)
Expand Down Expand Up @@ -547,5 +558,4 @@ static void hanjp_am_builtin_interface_init(HanjpAutomataInterface *iface)
iface->backspace = hanjp_am_base_backspace;
iface->flush = hanjp_am_base_flush;
}

/**/
6 changes: 4 additions & 2 deletions hanjpbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#include <gmodule.h>
#include <hangul.h>

/* Extern function signature which isn't exported in libhangul header */
// Extern function signature which aren't exported in libhangul header
extern ucschar hangul_choseong_to_jongseong(ucschar c);
extern ucschar hangul_jongseong_to_choseong(ucschar c);

static const int BUFF_SIZE =
(sizeof(((HanjpBuffer*)0)->stack) / sizeof(((HanjpBuffer*)0)->stack[0]));


/* HanjpBuffer Implementation */
/*
* HanjpBuffer Implementation
*/
gunichar hanjp_buffer_push(HanjpBuffer *buffer, gunichar ch)
{
if ((hangul_is_choseong(ch)) && (buffer->cho == 0)) {
Expand Down
8 changes: 4 additions & 4 deletions hanjpinputcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void hanjp_ic_dispose(GObject *self)
g_array_unref(priv->hangul);
priv->hangul = NULL;

//chain up
// chain up
G_OBJECT_CLASS(hanjp_ic_parent_class)->dispose(self);
}

Expand Down Expand Up @@ -134,16 +134,16 @@ gint hanjp_ic_process(HanjpInputContext *self, gint ascii)
g_return_if_fail(HANJP_IS_INPUTCONTEXT(self));
priv = hanjp_ic_get_instance_private(self);

//map jaso from ascii
// map jaso from ascii
ch = hanjp_kb_get_mapping(priv->keyboard, 0, ascii);
if (ch == 0) {
ch = (gunichar)ascii;
}
//shrink preedit before push
// shrink preedit before push
g_array_set_size(priv->preedit, priv->kana_len);
g_array_set_size(priv->committed, 0);
g_array_set_size(priv->hangul, 0);
//push jaso into automata
// push jaso into automata
res = hanjp_am_push(priv->cur_am, priv->preedit, priv->hangul, ch);

if (res < 0) {
Expand Down
5 changes: 5 additions & 0 deletions hanjpkeyboard.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "hanjpkeyboard.h"
#include "hangul.h"

// Extern function signature which isn't exported in libhangul header
extern ucschar hangul_keyboard_get_mapping(const HangulKeyboard* keyboard, int tableid, unsigned key);


/*
* Keyboard Interface Definition
*/
G_DEFINE_INTERFACE(HanjpKeyboard, hanjp_kb, G_TYPE_OBJECT)


Expand Down
2 changes: 1 addition & 1 deletion hanjpunicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ enum
HANGUL_JUNGSEONG_O_YAE
};

// syllable trailing consonants jamo (초성)
// syllable trailing consonants jamo (종성)
enum
{
// modern Hangul trailing consonants
Expand Down

0 comments on commit 5c22882

Please sign in to comment.