diff options
author | Peng Wu <alexepico@gmail.com> | 2013-04-01 15:36:27 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-04-01 15:36:27 +0800 |
commit | 1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb (patch) | |
tree | cfbe5cfabe69f6d391ea2493b63571b99df1c482 /utils | |
parent | c72df519d81a6735798f07d459a8fcace5ff7838 (diff) | |
download | libpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.tar.gz libpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.tar.xz libpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.zip |
update gen_binary_files.cpp
Diffstat (limited to 'utils')
-rw-r--r-- | utils/storage/gen_binary_files.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/utils/storage/gen_binary_files.cpp b/utils/storage/gen_binary_files.cpp index ac0f45c..bc874ba 100644 --- a/utils/storage/gen_binary_files.cpp +++ b/utils/storage/gen_binary_files.cpp @@ -24,27 +24,25 @@ #include "pinyin_internal.h" #include "utils_helper.h" -void print_help(){ - printf("Usage: gen_binary_files --table-dir <DIRNAME>\n"); -} +static const gchar * table_dir = "."; -int main(int argc, char * argv[]){ - int i = 1; - const char * table_dir = "."; +static GOptionEntry entries[] = +{ + {"table-dir", 0, 0, G_OPTION_ARG_FILENAME, &table_dir, "table directory", NULL}, + {NULL} +}; +int main(int argc, char * argv[]){ setlocale(LC_ALL, ""); - while ( i < argc ){ - if ( strcmp("--help", argv[i]) == 0 ){ - print_help(); - exit(0); - } else if ( strcmp("--table-dir", argv[i]) == 0){ - if ( ++i >= argc ){ - print_help(); - exit(EINVAL); - } - table_dir = argv[i]; - } - ++i; + + GError * error = NULL; + GOptionContext * context; + + context = g_option_context_new("- generate binary files"); + g_option_context_add_main_entries(context, entries, NULL); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed:%s\n", error->message); + exit(EINVAL); } /* generate pinyin index*/ |