| … | … | @@ -497,6 +497,43 @@ static const char *fbasename(const char *fpath) |
| 497 | 497 | return progf + 1; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | /** |
| 501 | * Return a dictionary handle for \p languege. Return NULL on failure. |
| 502 | * silence library verbose output if needed. |
| 503 | */ |
| 504 | static Dictionary dictionary_setup(const char *language, bool quiet, |
| 505 | Parse_Options opts) |
| 506 | { |
| 507 | Dictionary dict; |
| 508 | int save_verbosity = parse_options_get_verbosity(opts); |
| 509 | |
| 510 | if (quiet && (save_verbosity == 1)) |
| 511 | parse_options_set_verbosity(opts, 0); |
| 512 | |
| 513 | if (language && *language) |
| 514 | { |
| 515 | dict = dictionary_create_lang(language); |
| 516 | if (dict == NULL) |
| 517 | { |
| 518 | prt_error("Fatal error: Unable to open dictionary.\n"); |
| 519 | return NULL; |
| 520 | } |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | dict = dictionary_create_default_lang(); |
| 525 | if (dict == NULL) |
| 526 | { |
| 527 | prt_error("Fatal error: Unable to open default dictionary.\n"); |
| 528 | return NULL; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | parse_options_set_verbosity(opts, save_verbosity); |
| 533 | |
| 534 | return dict; |
| 535 | } |
| 536 | |
| 500 | 537 | static void print_usage(FILE *out, char *argv0, Command_Options *copts, int exit_value) |
| 501 | 538 | { |
| 502 | 539 | |
| … | … | @@ -599,24 +636,8 @@ int main(int argc, char * argv[]) |
| 599 | 636 | } |
| 600 | 637 | /* End of debug options setup. */ |
| 601 | 638 | |
| 602 | | if (language && *language) |
| 603 | | { |
| 604 | | dict = dictionary_create_lang(language); |
| 605 | | if (dict == NULL) |
| 606 | | { |
| 607 | | prt_error("Fatal error: Unable to open dictionary.\n"); |
| 608 | | exit(-1); |
| 609 | | } |
| 610 | | } |
| 611 | | else |
| 612 | | { |
| 613 | | dict = dictionary_create_default_lang(); |
| 614 | | if (dict == NULL) |
| 615 | | { |
| 616 | | prt_error("Fatal error: Unable to open default dictionary.\n"); |
| 617 | | exit(-1); |
| 618 | | } |
| 619 | | } |
| 639 | dict = dictionary_setup(language, quiet_start > 0, opts); |
| 640 | if (dict == NULL) exit(-1); |
| 620 | 641 | |
| 621 | 642 | set_default_parse_options(opts); |
| 622 | 643 | |