diff options
author | Peng Wu <alexepico@gmail.com> | 2011-04-28 15:04:46 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-04-28 15:04:46 +0800 |
commit | 80d2b005249b772e7cd7fdf763e217576d401823 (patch) | |
tree | 1b1611cef942e5b98b88c1448ad53d9df7ba5e85 /utils/storage | |
parent | b7909ecd1b39843c99b44118a8e0fe269da7f098 (diff) | |
download | libpinyin-80d2b005249b772e7cd7fdf763e217576d401823.tar.gz libpinyin-80d2b005249b772e7cd7fdf763e217576d401823.tar.xz libpinyin-80d2b005249b772e7cd7fdf763e217576d401823.zip |
use errno
Diffstat (limited to 'utils/storage')
-rw-r--r-- | utils/storage/gen_binary_files.cpp | 4 | ||||
-rw-r--r-- | utils/storage/gen_pinyin_table.cpp | 14 | ||||
-rw-r--r-- | utils/storage/import_interpolation.cpp | 4 |
3 files changed, 13 insertions, 9 deletions
diff --git a/utils/storage/gen_binary_files.cpp b/utils/storage/gen_binary_files.cpp index 757b075..f8d3c70 100644 --- a/utils/storage/gen_binary_files.cpp +++ b/utils/storage/gen_binary_files.cpp @@ -68,7 +68,7 @@ int main(int argc, char * argv[]){ FILE* infile = fopen("../../data/gb_char.table", "r"); if ( NULL == infile ){ printf("open gb_char.table failed!\n"); - exit(1); + exit(ENOENT); } phrase_index.load_text(1, infile); @@ -77,7 +77,7 @@ int main(int argc, char * argv[]){ infile = fopen("../../data/gbk_char.table", "r"); if ( NULL == infile ){ printf("open gbk_char.table failed!\n"); - exit(1); + exit(ENOENT); } phrase_index.load_text(2, infile); diff --git a/utils/storage/gen_pinyin_table.cpp b/utils/storage/gen_pinyin_table.cpp index a753a89..1808162 100644 --- a/utils/storage/gen_pinyin_table.cpp +++ b/utils/storage/gen_pinyin_table.cpp @@ -59,7 +59,6 @@ void print_help(){ printf("<OUTPUTFILE> the result output file\n"); printf("<FILEi> input pinyin files\n"); printf("<PHRASE_INDEX> phrase index identifier\n"); - exit(1); } gint phrase_item_compare(gconstpointer a, gconstpointer b){ @@ -83,13 +82,18 @@ int main(int argc, char * argv[]){ while ( i < argc ){ if ( strcmp("--help", argv[i] ) == 0) { print_help(); + exit(0); }else if ( strcmp("-t", argv[i] ) == 0){ - if ( ++i >= argc ) + if ( ++i >= argc ) { print_help(); + exit(EINVAL); + } phrase_index = atoi(argv[i]); }else if ( strcmp("-o", argv[i] ) == 0 ){ - if ( ++i >= argc ) + if ( ++i >= argc ) { print_help(); + exit(EINVAL); + } strcpy( outfilename, argv[i]); } else { feed_file(argv[i]); @@ -113,7 +117,7 @@ void feed_file ( const char * filename){ FILE * infile = fopen(filename, "r"); if ( NULL == infile ){ fprintf(stderr, "Can't open file %s.\n", filename); - exit(1); + exit(ENOENT); } while ( !feof(infile)){ fscanf(infile, "%s", phrase); @@ -226,7 +230,7 @@ void gen_phrase_file(const char * outfilename, int phrase_index){ FILE * outfile = fopen(outfilename, "w"); if (NULL == outfile ) { fprintf(stderr, "Can't write file %s.\n", outfilename); - exit(1); + exit(ENOENT); } phrase_token_t token = 1; char pinyin_buffer[4096]; diff --git a/utils/storage/import_interpolation.cpp b/utils/storage/import_interpolation.cpp index 71c4e63..57c87c1 100644 --- a/utils/storage/import_interpolation.cpp +++ b/utils/storage/import_interpolation.cpp @@ -231,7 +231,7 @@ int main(int argc, char * argv[]){ ssize_t result = my_getline(input); if ( result == -1 ) { fprintf(stderr, "empty file input.\n"); - exit(1); + exit(ENODATA); } //read "\data" line @@ -241,7 +241,7 @@ int main(int argc, char * argv[]){ assert(g_hash_table_lookup_extended(required, "model", NULL, (gpointer *)&value)); if ( !( strcmp("interpolation", value) == 0 ) ) { fprintf(stderr, "error: interpolation model expected.\n"); - exit(1); + exit(ENODATA); } result = my_getline(input); |