diff --git a/tools/compose.c b/tools/compose.c index f18c3f90..8803fa86 100644 --- a/tools/compose.c +++ b/tools/compose.c @@ -36,9 +36,10 @@ static void usage(FILE *fp, char *progname) { fprintf(fp, - "Usage: %s [--locale LOCALE | --locale-from-env | --locale-from-setlocale]\n", + "Usage: %s [--file FILE] [--locale LOCALE | --locale-from-env | --locale-from-setlocale]\n", progname); fprintf(fp, + " --file - specify a file to load\n" " --locale - specify the locale directly\n" " --locale-from-env - get the locale from the LC_ALL/LC_CTYPE/LANG environment variables (falling back to C)\n" " --locale-from-setlocale - get the locale using setlocale(3)\n" @@ -78,12 +79,17 @@ main(int argc, char *argv[]) struct xkb_context *ctx = NULL; struct xkb_compose_table *compose_table = NULL; const char *locale = NULL; + const char *path = NULL; + /* TODO: add option */ + enum xkb_compose_format format = XKB_COMPOSE_FORMAT_TEXT_V1; enum options { + OPT_FILE, OPT_LOCALE, OPT_LOCALE_FROM_ENV, OPT_LOCALE_FROM_SETLOCALE, }; static struct option opts[] = { + {"file", required_argument, 0, OPT_FILE}, {"locale", required_argument, 0, OPT_LOCALE}, {"locale-from-env", no_argument, 0, OPT_LOCALE_FROM_ENV}, {"locale-from-setlocale", no_argument, 0, OPT_LOCALE_FROM_SETLOCALE}, @@ -101,6 +107,9 @@ main(int argc, char *argv[]) break; switch (opt) { + case OPT_FILE: + path = optarg; + break; case OPT_LOCALE: locale = optarg; break; @@ -135,14 +144,31 @@ main(int argc, char *argv[]) goto out; } - compose_table = - xkb_compose_table_new_from_locale(ctx, locale, - XKB_COMPOSE_COMPILE_NO_FLAGS); - if (!compose_table) { - fprintf(stderr, "Couldn't create compose from locale\n"); - goto out; + if (path != NULL) { + FILE *file = fopen(path, "rb"); + if (file == NULL) { + perror(path); + goto file_error; + } + compose_table = + xkb_compose_table_new_from_file(ctx, file, locale, format, + XKB_COMPOSE_COMPILE_NO_FLAGS); + fclose(file); + if (!compose_table) { + fprintf(stderr, "Couldn't create compose from file: %s\n", path); + goto out; + } + } else { + compose_table = + xkb_compose_table_new_from_locale(ctx, locale, + XKB_COMPOSE_COMPILE_NO_FLAGS); + if (!compose_table) { + fprintf(stderr, "Couldn't create compose from locale\n"); + goto out; + } } + struct xkb_compose_table_iterator *iter = xkb_compose_table_iterator_new(compose_table); while (xkb_compose_table_iterator_next(iter)) { compose_table_print_cb(xkb_compose_table_iterator_current(iter), NULL); @@ -151,6 +177,7 @@ main(int argc, char *argv[]) out: xkb_compose_table_unref(compose_table); +file_error: xkb_context_unref(ctx); return ret;