summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac5
-rw-r--r--hangul/hangulkeyboard.c96
-rw-r--r--test/Makefile.am8
-rw-r--r--test/hangul.c4
-rw-r--r--test/test.c4
5 files changed, 89 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac
index 369f904..d382bb0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,6 +92,11 @@ test/Makefile
tools/Makefile
])
+AC_CONFIG_LINKS([
+data/keyboards/hangul-combination-default.xml:data/keyboards/hangul-combination-default.xml
+data/keyboards/hangul-combination-full.xml:data/keyboards/hangul-combination-full.xml
+])
+
AC_OUTPUT
# vim: et
diff --git a/hangul/hangulkeyboard.c b/hangul/hangulkeyboard.c
index ac94cb8..11354d8 100644
--- a/hangul/hangulkeyboard.c
+++ b/hangul/hangulkeyboard.c
@@ -58,7 +58,6 @@
*/
#define LIBHANGUL_KEYBOARD_DIR LIBHANGUL_DATA_DIR "/keyboards"
-//#define LIBHANGUL_KEYBOARD_DIR TOP_SRCDIR "/data/keyboards"
#define HANGUL_KEYBOARD_TABLE_SIZE 0x80
@@ -832,6 +831,62 @@ hangul_keyboard_list_clear()
hangul_keyboards.keyboards = NULL;
}
+static char*
+hangul_keyboard_get_default_keyboard_path()
+{
+ char* keyboard_path = NULL;
+ size_t keyboard_path_len = 1;
+
+ /* default LIBHANGUL_KEYBOARD_PATH is
+ * SYSTEM_KEYBOARD_DIR:USER_KEYBOARD_DIR */
+
+ /* system default dir */
+ const char* system_dir = LIBHANGUL_KEYBOARD_DIR;
+ keyboard_path_len += strlen(system_dir);
+
+ /* user default dir */
+ char* xdg_data_home = getenv("XDG_DATA_HOME");
+ if (xdg_data_home == NULL) {
+ char* home_dir = getenv("HOME");
+ if (home_dir == NULL) {
+ /* no user data dir */
+ keyboard_path = (char*)malloc(keyboard_path_len);
+ if (keyboard_path != NULL) {
+ snprintf(keyboard_path, keyboard_path_len, "%s", system_dir);
+ }
+ } else {
+ const char* subdir = "/.local/share/libhangul/keyboards";
+ keyboard_path_len += 1 + strlen(home_dir) + strlen(subdir);
+ keyboard_path = (char*)malloc(keyboard_path_len);
+ if (keyboard_path != NULL) {
+ snprintf(keyboard_path, keyboard_path_len, "%s:%s%s", system_dir, home_dir, subdir);
+ }
+ }
+ } else {
+ const char* subdir = "/libhangul/keyboards";
+ keyboard_path_len += 1 + strlen(xdg_data_home) + strlen(subdir);
+ keyboard_path = (char*)malloc(keyboard_path_len);
+ if (keyboard_path != NULL) {
+ snprintf(keyboard_path, keyboard_path_len, "%s:%s%s", system_dir, xdg_data_home, subdir);
+ }
+ }
+
+ return keyboard_path;
+}
+
+static char*
+hangul_keyboard_get_keyboard_path()
+{
+ char* keyboard_path = getenv("LIBHANGUL_KEYBOARD_PATH");
+ if (keyboard_path == NULL) {
+ keyboard_path = hangul_keyboard_get_default_keyboard_path();
+ } else {
+ keyboard_path = strdup(keyboard_path);
+ }
+
+ return keyboard_path;
+}
+
int
hangul_keyboard_list_init()
{
@@ -847,35 +902,24 @@ hangul_keyboard_list_init()
* builtin 키보드는 하위 호환을 위해 남겨둔다. */
hangul_builtin_keyboard_count = 0;
- unsigned n = 0;
/* libhangul data dir에서 keyboard 로딩 */
- n += hangul_keyboard_list_load_dir(LIBHANGUL_KEYBOARD_DIR);
+ char* libhangul_keyboard_path = hangul_keyboard_get_keyboard_path();
- /* 유저의 개별 키보드 파일 로딩 */
- char* user_data_dir = NULL;
- char* xdg_data_home = getenv("XDG_DATA_HOME");
- if (xdg_data_home == NULL) {
- char* home_dir = getenv("HOME");
- if (home_dir != NULL) {
- const char* subdir = "/.local/share/libhangul/keyboards";
- size_t len = strlen(home_dir) + strlen(subdir) + 1;
- user_data_dir = (char*)malloc(len);
- if (user_data_dir != NULL) {
- snprintf(user_data_dir, len, "%s%s", home_dir, subdir);
- }
- }
- } else {
- const char* subdir = "/libhangul/keyboards";
- size_t len = strlen(xdg_data_home) + strlen(subdir) + 1;
- user_data_dir = (char*)malloc(len);
- if (user_data_dir != NULL) {
- snprintf(user_data_dir, len, "%s%s", xdg_data_home, subdir);
+ unsigned n = 0;
+
+ char* dir = libhangul_keyboard_path;
+ while (dir != NULL && dir[0] != '\0') {
+ char* next = strchr(dir, ':');
+ if (next != NULL) {
+ next[0] = '\0';
+ ++next;
}
+
+ n += hangul_keyboard_list_load_dir(dir);
+ dir = next;
}
- if (user_data_dir != NULL) {
- n += hangul_keyboard_list_load_dir(user_data_dir);
- free(user_data_dir);
- }
+
+ free(libhangul_keyboard_path);
if (n == 0)
return 1;
diff --git a/test/Makefile.am b/test/Makefile.am
index 6364f50..071d0a2 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,7 @@
noinst_PROGRAMS = hangul hanja
-hangul_CFLAGS =
+hangul_CFLAGS = -DTEST_LIBHANGUL_KEYBOARD_PATH=\"${abs_top_builddir}/data/keyboards\"
hangul_SOURCES = hangul.c
hangul_LDADD = ../hangul/libhangul.la $(LTLIBINTL) $(LTLIBICONV)
@@ -12,5 +12,9 @@ hanja_LDADD = ../hangul/libhangul.la $(LTLIBINTL)
TESTS = test
check_PROGRAMS = test
test_SOURCES = test.c ../hangul/hangul.h
-test_CFLAGS = $(CHECK_CFLAGS) -DTEST_SOURCE_DIR=\"$(abs_srcdir)\"
+test_CFLAGS = \
+ $(CHECK_CFLAGS) \
+ -DTEST_SOURCE_DIR=\"$(abs_srcdir)\" \
+ -DTEST_LIBHANGUL_KEYBOARD_PATH=\"${abs_top_builddir}/data/keyboards\" \
+ $(NULL)
test_LDADD = $(CHECK_LIBS) ../hangul/libhangul.la $(LTLIBINTL)
diff --git a/test/hangul.c b/test/hangul.c
index 797c14d..a019f06 100644
--- a/test/hangul.c
+++ b/test/hangul.c
@@ -68,6 +68,10 @@ main(int argc, char *argv[])
keyboard = argv[1];
}
+ char* keyboard_path = getenv("LIBHANGUL_KEYBOARD_PATH");
+ if (keyboard_path == NULL)
+ setenv("LIBHANGUL_KEYBOARD_PATH", TEST_LIBHANGUL_KEYBOARD_PATH, 1);
+
hangul_init();
hic = hangul_ic_new(keyboard);
diff --git a/test/test.c b/test/test.c
index c64fd6e..2a0b383 100644
--- a/test/test.c
+++ b/test/test.c
@@ -613,6 +613,10 @@ Suite* libhangul_suite()
int main()
{
+ char* keyboard_path = getenv("LIBHANGUL_KEYBOARD_PATH");
+ if (keyboard_path == NULL)
+ setenv("LIBHANGUL_KEYBOARD_PATH", TEST_LIBHANGUL_KEYBOARD_PATH, 1);
+
hangul_init();
int number_failed;