From a8abe097d3f725518d787de409caa0013834fa75 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 2 Apr 2013 14:44:26 +0800 Subject: update validate_k_mixture_model.cpp --- utils/training/validate_k_mixture_model.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'utils/training') diff --git a/utils/training/validate_k_mixture_model.cpp b/utils/training/validate_k_mixture_model.cpp index b9b864c..c51bbc5 100644 --- a/utils/training/validate_k_mixture_model.cpp +++ b/utils/training/validate_k_mixture_model.cpp @@ -137,19 +137,23 @@ bool validate_bigram(KMixtureModelBigram * bigram){ } int main(int argc, char * argv[]){ - int i = 1; - const char * k_mixture_model_filename = NULL; - - while ( i < argc ){ - if ( strcmp ("--help", argv[i]) == 0 ){ - print_help(); - exit(0); - } else { - k_mixture_model_filename = argv[i]; - } - ++i; + + GError * error = NULL; + GOptionContext * context; + + context = g_option_context_new("- validate k mixture model"); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("option parsing failed:%s\n", error->message); + exit(EINVAL); } + if (2 != argc) { + fprintf(stderr, "wrong arguments.\n"); + exit(EINVAL); + } + + const char * k_mixture_model_filename = argv[1]; + KMixtureModelBigram bigram(K_MIXTURE_MODEL_MAGIC_NUMBER); bigram.attach(k_mixture_model_filename, ATTACH_READONLY); -- cgit v1.2.1