diff options
author | Peng Wu <alexepico@gmail.com> | 2011-08-05 20:39:07 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-08-05 20:44:36 +0800 |
commit | 589b10be816c4264fc1663f4680e4d71861f1682 (patch) | |
tree | 6afd902bc10eef7c16618c3f537b8436fd057010 /utils/storage | |
parent | 0572b575851a7c7055ae10b7c22d072fe685c5be (diff) | |
download | libpinyin-589b10be816c4264fc1663f4680e4d71861f1682.tar.gz libpinyin-589b10be816c4264fc1663f4680e4d71861f1682.tar.xz libpinyin-589b10be816c4264fc1663f4680e4d71861f1682.zip |
refine autoconf
Diffstat (limited to 'utils/storage')
-rw-r--r-- | utils/storage/gen_binary_files.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/utils/storage/gen_binary_files.cpp b/utils/storage/gen_binary_files.cpp index 95374c1..14aa973 100644 --- a/utils/storage/gen_binary_files.cpp +++ b/utils/storage/gen_binary_files.cpp @@ -20,9 +20,32 @@ */ #include <stdio.h> +#include <locale.h> #include "pinyin.h" +void print_help(){ + printf("Usage: gen_binary_files --table-dir <DIRNAME>\n"); +} + int main(int argc, char * argv[]){ + int i = 1; + const char * table_dir = "../../data"; + + 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; + } + /* generate pinyin index*/ PinyinCustomSettings custom; PinyinLargeTable pinyinlargetable(&custom); @@ -31,7 +54,10 @@ int main(int argc, char * argv[]){ /* generate phrase index */ FacadePhraseIndex phrase_index; - FILE * gbfile = fopen("../../data/gb_char.table", "r"); + gchar * filename = g_build_filename(table_dir, "gb_char.table", NULL); + FILE * gbfile = fopen(filename, "r"); + g_free(filename); + if ( gbfile == NULL) { fprintf(stderr, "open gb_char.table failed!"); exit(ENOENT); @@ -45,9 +71,12 @@ int main(int argc, char * argv[]){ phrase_index.load_text(1, gbfile); fclose(gbfile); - FILE * gbkfile = fopen("../../data/gbk_char.table","r"); + filename = g_build_filename(table_dir, "gbk_char.table", NULL); + FILE * gbkfile = fopen(filename, "r"); + g_free(filename); + if ( gbkfile == NULL) { - fprintf(stderr, "open gb_char.table failed!"); + fprintf(stderr, "open gbk_char.table failed!"); exit(ENOENT); } |