int
main(int argc, char *argv[])
{
- HanjaTable *table = hanja_table_load(NULL);
+ char* hanja_table_file = NULL;
+ char buf[256] = { '\0', };
- HanjaList *list = hanja_table_match_prefix(table, argv[1]);
+ if (argc > 1)
+ hanja_table_file = argv[1];
- int i, n;
- n = hanja_list_get_size(list);
- for (i = 0; i < n; i++) {
- const char* value = hanja_list_get_nth_value(list, i);
- printf("%s\n", value);
- }
+ HanjaTable *table = hanja_table_load(hanja_table_file);
+
+ while (fgets(buf, sizeof(buf), stdin) != NULL) {
+ char* p = strchr(buf, '\n');
+ if (p != NULL)
+ *p = '\0';
+
+ HanjaList *list = hanja_table_match_prefix(table, buf);
- hanja_list_delete(list);
+ int i, n;
+ n = hanja_list_get_size(list);
+ for (i = 0; i < n; i++) {
+ const char* value = hanja_list_get_nth_value(list, i);
+ printf("%s\n", value);
+ }
+
+ hanja_list_delete(list);
+ }
hanja_table_delete(table);