From 1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 1 Apr 2013 15:36:27 +0800 Subject: update gen_binary_files.cpp --- utils/storage/gen_binary_files.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'utils') 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 \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*/ -- cgit