summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWon-Kyu Park <wkpark@gmail.com>2023-02-27 00:39:32 +0900
committerWon-Kyu Park <wkpark@gmail.com>2023-03-02 12:41:10 +0900
commitbad12bde8ac496a6736f611ae03c50839b253003 (patch)
tree59b2d1ac5d355536c0a83ff9047d8b7e012142b9
parent7c2fb9216e72302134115c1483d4c3d2b1edd3a1 (diff)
downloadlibhangul-bad12bde8ac496a6736f611ae03c50839b253003.tar.gz
win32: use Find*File() for win32
-rw-r--r--hangul/hangulkeyboard.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/hangul/hangulkeyboard.c b/hangul/hangulkeyboard.c
index 9e1e599..10d7ca3 100644
--- a/hangul/hangulkeyboard.c
+++ b/hangul/hangulkeyboard.c
@@ -26,7 +26,9 @@
#if ENABLE_EXTERNAL_KEYBOARDS
#include <locale.h>
+#ifdef HAVE_GLOB_H
#include <glob.h>
+#endif /* HAVE_GLOB_H */
#include <libgen.h>
#include <expat.h>
#endif /* ENABLE_EXTERNAL_KEYBOARDS */
@@ -36,8 +38,11 @@
#include "hangulinternals.h"
#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <fileapi.h>
#define strdup _strdup
-#endif
+#endif /* _WIN32 */
/**
* @file hangulkeyboard.c
@@ -798,6 +803,7 @@ hangul_keyboard_list_load_dir(const char* path)
snprintf(pattern, len, "%s%s", path, subpattern);
+#ifdef HAVE_GLOB_H
glob_t result;
int res = glob(pattern, GLOB_ERR, NULL, &result);
if (res != 0) {
@@ -815,6 +821,54 @@ hangul_keyboard_list_load_dir(const char* path)
globfree(&result);
free(pattern);
+#else /* _WIN32 */
+ WIN32_FIND_DATAW findFileData;
+ HANDLE hFind;
+ int n = (strlen(pattern) + 1) * sizeof(WCHAR);
+
+ LPWSTR wpattern = (LPWSTR)malloc(n);
+ if (wpattern == NULL) {
+ free(pattern);
+ return 0;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pattern, -1, wpattern, n);
+
+ hFind = FindFirstFileW(wpattern, &findFileData);
+ if (hFind == INVALID_HANDLE_VALUE) {
+ free(wpattern);
+ free(pattern);
+ return 0;
+ }
+
+ do {
+ n = WideCharToMultiByte(CP_ACP, 0, findFileData.cFileName, -1, NULL, 0, NULL, NULL);
+ if (n == 0)
+ continue;
+
+ int path_len = strlen(path);
+ len = path_len + n + 2;
+ char* file = (char*)malloc(len);
+ if (file == NULL)
+ continue;
+
+ memcpy(file, path, path_len);
+ file[path_len] = '/';
+ char* pfile = &file[path_len + 1];
+ WideCharToMultiByte(CP_ACP, 0, findFileData.cFileName, -1, pfile, n, NULL, NULL);
+
+ HangulKeyboard* keyboard = hangul_keyboard_new_from_file(file);
+ free(file);
+
+ if (keyboard == NULL)
+ continue;
+ hangul_keyboard_list_append(keyboard);
+ } while(FindNextFileW(hFind, &findFileData));
+
+ FindClose(hFind);
+ free(wpattern);
+ free(pattern);
+#endif /* HAVE_GLOB_H */
return hangul_keyboards.n;
}