summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-04-01 15:36:27 +0800
committerPeng Wu <alexepico@gmail.com>2013-04-01 15:36:27 +0800
commit1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb (patch)
treecfbe5cfabe69f6d391ea2493b63571b99df1c482
parentc72df519d81a6735798f07d459a8fcace5ff7838 (diff)
downloadlibpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.tar.gz
libpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.tar.xz
libpinyin-1d7a1b5e2efa0e559ba600d5452aa0444ddf56cb.zip
update gen_binary_files.cpp
-rw-r--r--tests/storage/test_parser2.cpp2
-rw-r--r--utils/storage/gen_binary_files.cpp34
2 files changed, 17 insertions, 19 deletions
diff --git a/tests/storage/test_parser2.cpp b/tests/storage/test_parser2.cpp
index 5ea3fb8..cc330e9 100644
--- a/tests/storage/test_parser2.cpp
+++ b/tests/storage/test_parser2.cpp
@@ -29,7 +29,7 @@
#include "pinyin_parser2.h"
-static gchar * parsername = "";
+static const gchar * parsername = "";
static gboolean incomplete = FALSE;
static GOptionEntry entries[] =
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*/