summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/storage/flexible_ngram.h3
-rw-r--r--tests/storage/test_phrase_index.cpp5
-rw-r--r--tests/storage/test_pinyin_index.cpp4
-rw-r--r--utils/segment/ngseg.cpp5
-rw-r--r--utils/segment/spseg.cpp11
-rw-r--r--utils/storage/gen_binary_files.cpp4
-rw-r--r--utils/storage/gen_pinyin_table.cpp14
-rw-r--r--utils/storage/import_interpolation.cpp4
-rw-r--r--utils/training/estimate_k_mixture_model.cpp11
-rw-r--r--utils/training/gen_ngram.cpp11
10 files changed, 46 insertions, 26 deletions
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h
index 3fa452d..9b08a0d 100644
--- a/src/storage/flexible_ngram.h
+++ b/src/storage/flexible_ngram.h
@@ -25,6 +25,7 @@
#define FLEXIBLE_NGRAM_H
#include <db.h>
+#include <errno.h>
/* Note: the signature of the template parameters.
* struct MagicHeader, ArrayHeader, ArrayItem.
@@ -367,7 +368,7 @@ public:
if ( ret != DB_NOTFOUND ){
fprintf(stderr, "training db error, exit!");
- exit(1);
+ exit(EIO);
}
/* Cursors must be closed */
diff --git a/tests/storage/test_phrase_index.cpp b/tests/storage/test_phrase_index.cpp
index c5d5828..12cc398 100644
--- a/tests/storage/test_phrase_index.cpp
+++ b/tests/storage/test_phrase_index.cpp
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <sys/time.h>
+#include <errno.h>
#include <glib.h>
#include "pinyin.h"
@@ -93,7 +94,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.load_text(1, infile);
@@ -102,7 +103,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.load_text(2, infile);
diff --git a/tests/storage/test_pinyin_index.cpp b/tests/storage/test_pinyin_index.cpp
index 90f0437..e0e42bf 100644
--- a/tests/storage/test_pinyin_index.cpp
+++ b/tests/storage/test_pinyin_index.cpp
@@ -51,7 +51,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);
@@ -60,7 +60,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/segment/ngseg.cpp b/utils/segment/ngseg.cpp
index 504cacc..c1a06a7 100644
--- a/utils/segment/ngseg.cpp
+++ b/utils/segment/ngseg.cpp
@@ -51,7 +51,6 @@ enum CONTEXT_STATE{
void print_help(){
printf("Usage: ngseg [--generate-extra-enter]\n");
- exit(1);
}
bool deal_with_segmentable(GArray * current_utf16){
@@ -93,8 +92,12 @@ int main(int argc, char * argv[]){
while ( i < argc ){
if ( strcmp ("--help", argv[i]) == 0 ){
print_help();
+ exit(0);
} else if ( strcmp("--generate-extra-enter", argv[i]) == 0 ){
gen_extra_enter = true;
+ } else {
+ print_help();
+ exit(EINVAL);
}
++i;
}
diff --git a/utils/segment/spseg.cpp b/utils/segment/spseg.cpp
index 910770a..6a54288 100644
--- a/utils/segment/spseg.cpp
+++ b/utils/segment/spseg.cpp
@@ -129,7 +129,6 @@ bool backtrace(GArray * steps, glong phrase_len, GArray * strings){
void print_help(){
printf("Usage: spseg [--generate-extra-enter]\n");
- exit(1);
}
int main(int argc, char * argv[]){
@@ -141,8 +140,12 @@ int main(int argc, char * argv[]){
while ( i < argc ){
if ( strcmp ("--help", argv[i]) == 0) {
print_help();
- }else if (strcmp("--generate-extra-enter", argv[i]) == 0) {
+ exit(0);
+ } else if (strcmp("--generate-extra-enter", argv[i]) == 0) {
gen_extra_enter = true;
+ } else {
+ print_help();
+ exit(EINVAL);
}
++i;
}
@@ -152,7 +155,7 @@ int main(int argc, char * argv[]){
FILE * gb_file = fopen("../../data/gb_char.table", "r");
if ( gb_file == NULL ){
fprintf(stderr, "can't open gb_char.table!\n");
- exit(1);
+ exit(ENOENT);
}
g_phrases->load_text(gb_file);
fclose(gb_file);
@@ -160,7 +163,7 @@ int main(int argc, char * argv[]){
FILE * gbk_file = fopen("../../data/gbk_char.table", "r");
if ( gbk_file == NULL ){
fprintf(stderr, "can't open gbk_char.table!\n");
- exit(1);
+ exit(ENOENT);
}
g_phrases->load_text(gbk_file);
fclose(gbk_file);
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);
diff --git a/utils/training/estimate_k_mixture_model.cpp b/utils/training/estimate_k_mixture_model.cpp
index 7a827c9..37a88df 100644
--- a/utils/training/estimate_k_mixture_model.cpp
+++ b/utils/training/estimate_k_mixture_model.cpp
@@ -26,7 +26,6 @@
void print_help(){
printf("estimate_k_mixture_model [--bigram-file <FILENAME>]\n");
printf(" [--deleted-bigram-file <FILENAME]\n");
- exit(1);
}
parameter_t compute_interpolation(KMixtureModelSingleGram * deleted_bigram,
@@ -100,16 +99,22 @@ int main(int argc, char * argv[]){
while ( i < argc ){
if ( strcmp("--help", argv[i] ) == 0 ){
print_help();
+ exit(0);
} else if ( strcmp("--bigram-file", argv[i]) == 0 ){
- if ( ++i >= argc )
+ if ( ++i >= argc ) {
print_help();
+ exit(EINVAL);
+ }
bigram_filename = argv[i];
} else if ( strcmp("--deleted-bigram-file", argv[i]) == 0){
- if ( ++i >= argc )
+ if ( ++i >= argc ) {
print_help();
+ exit(EINVAL);
+ }
deleted_bigram_filename = argv[i];
} else{
print_help();
+ exit(EINVAL);
}
++i;
}
diff --git a/utils/training/gen_ngram.cpp b/utils/training/gen_ngram.cpp
index 367728a..4ac75e3 100644
--- a/utils/training/gen_ngram.cpp
+++ b/utils/training/gen_ngram.cpp
@@ -31,7 +31,6 @@ static PhraseLargeTable * g_phrases = NULL;
void print_help(){
printf("gen_ngram [--skip-pi-gram-training] [--skip-unigram-training]\n");
printf(" [--bigram-file <FILENAME>]\n");
- exit(1);
}
int main(int argc, char * argv[]){
@@ -44,16 +43,20 @@ int main(int argc, char * argv[]){
while ( i < argc ){
if ( strcmp("--help", argv[i] ) == 0){
print_help();
+ exit(0);
}else if ( strcmp("--skip-pi-gram-training", argv[i] ) == 0) {
train_pi_gram = false;
}else if ( strcmp("--skip-unigram-training", argv[i] ) == 0) {
train_unigram = false;
}else if ( strcmp("--bigram-file", argv[i] ) == 0){
- if ( ++i >= argc )
+ if ( ++i >= argc ) {
print_help();
+ exit(EINVAL);
+ }
bigram_filename = argv[i];
}else{
print_help();
+ exit(EINVAL);
}
++i;
}
@@ -63,14 +66,14 @@ int main(int argc, char * argv[]){
FILE * gb_file = fopen("../../data/gb_char.table", "r");
if ( gb_file == NULL ){
fprintf(stderr, "can't open gb_char.table!\n");
- exit(1);
+ exit(ENOENT);
}
g_phrases->load_text(gb_file);
fclose(gb_file);
FILE * gbk_file = fopen("../../data/gbk_char.table", "r");
if ( gbk_file == NULL ){
fprintf(stderr, "can't open gbk_char.table!\n");
- exit(1);
+ exit(ENOENT);
}
g_phrases->load_text(gbk_file);
fclose(gbk_file);