diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-02-07 20:29:53 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-02-07 20:29:53 +0200 |
commit | 548e46e7de424c06743d844fc35b091982d5bee5 (patch) | |
tree | 9e6e118d80a6e2d3fa52fca87c16ea453b378f58 | |
parent | 4be79061e8f68f6e3174a05452d96f31e8062464 (diff) | |
download | cflow-548e46e7de424c06743d844fc35b091982d5bee5.tar.gz cflow-548e46e7de424c06743d844fc35b091982d5bee5.tar.bz2 |
Use exit codes consistently.
* doc/cflow.1: Document exit codes.
* doc/cflow.texi: Likewise.
* src/cflow.h: Define exit code constants.
* src/main.c: Use exit codes consistently.
* src/output.c: Likewise.
* src/parser.c: Likewise.
* src/posix.c: Likewise.
* src/rc.c: Likewise.
-rw-r--r-- | doc/cflow.1 | 12 | ||||
-rw-r--r-- | doc/cflow.texi | 16 | ||||
-rw-r--r-- | src/cflow.h | 6 | ||||
-rw-r--r-- | src/main.c | 60 | ||||
-rw-r--r-- | src/output.c | 2 | ||||
-rw-r--r-- | src/parser.c | 6 | ||||
-rw-r--r-- | src/posix.c | 3 | ||||
-rw-r--r-- | src/rc.c | 13 |
8 files changed, 75 insertions, 43 deletions
diff --git a/doc/cflow.1 b/doc/cflow.1 index bf6923d..592482a 100644 --- a/doc/cflow.1 +++ b/doc/cflow.1 | |||
@@ -224,6 +224,18 @@ Print a summary of available options. | |||
224 | \fB\-V\fR, \fB\-\-version\fR | 224 | \fB\-V\fR, \fB\-\-version\fR |
225 | Print program version. | 225 | Print program version. |
226 | .SH "RETURN VALUE" | 226 | .SH "RETURN VALUE" |
227 | .TP | ||
228 | .B 0 | ||
229 | Successful completion. | ||
230 | .TP | ||
231 | .B 1 | ||
232 | Fatal error occurred. | ||
233 | .TP | ||
234 | .B 2 | ||
235 | Some input files cannot be read or parsed. | ||
236 | .TP | ||
237 | .B 3 | ||
238 | Command line usage error. | ||
227 | .SH "SEE ALSO" | 239 | .SH "SEE ALSO" |
228 | Online copies of \fBGNU cflow\fR documentation in various formats can be | 240 | Online copies of \fBGNU cflow\fR documentation in various formats can be |
229 | found at: | 241 | found at: |
diff --git a/doc/cflow.texi b/doc/cflow.texi index a9f2313..cb9326c 100644 --- a/doc/cflow.texi +++ b/doc/cflow.texi | |||
@@ -75,6 +75,7 @@ documents GNU cflow Version @value{VERSION}. | |||
75 | * Configuration:: Configuration Files and Variables. | 75 | * Configuration:: Configuration Files and Variables. |
76 | * Makefiles:: Using @command{cflow} in Makefiles. | 76 | * Makefiles:: Using @command{cflow} in Makefiles. |
77 | * Options:: Complete Listing of @command{cflow} Options. | 77 | * Options:: Complete Listing of @command{cflow} Options. |
78 | * Exit Codes:: Exit Codes, | ||
78 | * Emacs:: Using @command{cflow} with GNU Emacs. | 79 | * Emacs:: Using @command{cflow} with GNU Emacs. |
79 | 80 | ||
80 | * Reporting Bugs:: How to Report a Bug. | 81 | * Reporting Bugs:: How to Report a Bug. |
@@ -1449,6 +1450,21 @@ sources. | |||
1449 | Print program version. | 1450 | Print program version. |
1450 | @end table | 1451 | @end table |
1451 | 1452 | ||
1453 | @node Exit Codes | ||
1454 | @chapter Exit Codes | ||
1455 | @cindex exit codes | ||
1456 | |||
1457 | @table @asis | ||
1458 | @item 0 | ||
1459 | Successful completion. | ||
1460 | @item 1 | ||
1461 | Fatal error occurred. | ||
1462 | @item 2 | ||
1463 | Some input files cannot be read or parsed. | ||
1464 | @item 3 | ||
1465 | Command line usage error. | ||
1466 | @end table | ||
1467 | |||
1452 | @node Emacs | 1468 | @node Emacs |
1453 | @chapter Using @command{cflow} with GNU Emacs. | 1469 | @chapter Using @command{cflow} with GNU Emacs. |
1454 | @cindex cflow-mode introduced | 1470 | @cindex cflow-mode introduced |
diff --git a/src/cflow.h b/src/cflow.h index 28ba0db..e60d222 100644 --- a/src/cflow.h +++ b/src/cflow.h | |||
@@ -41,6 +41,12 @@ | |||
41 | # define setlocale(category, locale) /* empty */ | 41 | # define setlocale(category, locale) /* empty */ |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | /* Exit codes */ | ||
45 | #define EX_OK 0 /* Success */ | ||
46 | #define EX_FATAL 1 /* Fatal error */ | ||
47 | #define EX_SOFT 2 /* Some input files cannot be read or parsed */ | ||
48 | #define EX_USAGE 3 /* Command line usage error */ | ||
49 | |||
44 | #define NUMITEMS(a) sizeof(a)/sizeof((a)[0]) | 50 | #define NUMITEMS(a) sizeof(a)/sizeof((a)[0]) |
45 | 51 | ||
46 | struct linked_list_entry { | 52 | struct linked_list_entry { |
@@ -260,10 +260,9 @@ symbol_override(const char *str) | |||
260 | Symbol *sp; | 260 | Symbol *sp; |
261 | 261 | ||
262 | ptr = strchr(str, ':'); | 262 | ptr = strchr(str, ':'); |
263 | if (!ptr) { | 263 | if (!ptr) |
264 | error(0, 0, _("%s: no symbol type supplied"), str); | 264 | error(EX_USAGE, 0, _("%s: no symbol type supplied"), str); |
265 | return; | 265 | else { |
266 | } else { | ||
267 | name = strndup(str, ptr - str); | 266 | name = strndup(str, ptr - str); |
268 | if (ptr[1] == '=') { | 267 | if (ptr[1] == '=') { |
269 | Symbol *alias = lookup(ptr+2); | 268 | Symbol *alias = lookup(ptr+2); |
@@ -281,10 +280,8 @@ symbol_override(const char *str) | |||
281 | sp->flag = symbol_alias; | 280 | sp->flag = symbol_alias; |
282 | } else { | 281 | } else { |
283 | int type = find_option_type(symbol_optype, ptr+1, 0); | 282 | int type = find_option_type(symbol_optype, ptr+1, 0); |
284 | if (type == 0) { | 283 | if (type == 0) |
285 | error(0, 0, _("unknown symbol type: %s"), ptr+1); | 284 | error(EX_USAGE, 0, _("unknown symbol type: %s"), ptr+1); |
286 | return; | ||
287 | } | ||
288 | sp = install(name, INSTALL_OVERWRITE); | 285 | sp = install(name, INSTALL_OVERWRITE); |
289 | sp->type = SymToken; | 286 | sp->type = SymToken; |
290 | sp->token_type = type; | 287 | sp->token_type = type; |
@@ -310,7 +307,7 @@ set_print_option(char *str) | |||
310 | 307 | ||
311 | opt = find_option_type(print_optype, str, 0); | 308 | opt = find_option_type(print_optype, str, 0); |
312 | if (opt == 0) { | 309 | if (opt == 0) { |
313 | error(0, 0, _("unknown print option: %s"), str); | 310 | error(EX_USAGE, 0, _("unknown print option: %s"), str); |
314 | return; | 311 | return; |
315 | } | 312 | } |
316 | print_option |= opt; | 313 | print_option |= opt; |
@@ -432,19 +429,16 @@ parse_level_string(const char *str, char **return_ptr) | |||
432 | c = p[-1]; | 429 | c = p[-1]; |
433 | for (i = 1; i < num; i++) { | 430 | for (i = 1; i < num; i++) { |
434 | *p++ = c; | 431 | *p++ = c; |
435 | if (*p == 0) { | 432 | if (*p == 0) |
436 | error(1, 0, _("level indent string is too long")); | 433 | error(EX_USAGE, 0, |
437 | return; | 434 | _("level indent string is too long")); |
438 | } | ||
439 | } | 435 | } |
440 | break; | 436 | break; |
441 | default: | 437 | default: |
442 | copy: | 438 | copy: |
443 | *p++ = *str++; | 439 | *p++ = *str++; |
444 | if (*p == 0) { | 440 | if (*p == 0) |
445 | error(1, 0, _("level indent string is too long")); | 441 | error(EX_USAGE, 0, _("level indent string is too long")); |
446 | return; | ||
447 | } | ||
448 | } | 442 | } |
449 | } | 443 | } |
450 | *p = 0; | 444 | *p = 0; |
@@ -469,10 +463,8 @@ set_level_indent(const char *str) | |||
469 | 463 | ||
470 | p = str; | 464 | p = str; |
471 | while (*p != '=') { | 465 | while (*p != '=') { |
472 | if (*p == 0) { | 466 | if (*p == 0) |
473 | error(1, 0, _("level-indent syntax")); | 467 | error(EX_USAGE, 0, _("level-indent syntax")); |
474 | return; | ||
475 | } | ||
476 | p++; | 468 | p++; |
477 | } | 469 | } |
478 | ++p; | 470 | ++p; |
@@ -494,7 +486,7 @@ set_level_indent(const char *str) | |||
494 | parse_level_string(p, &level_end[1]); | 486 | parse_level_string(p, &level_end[1]); |
495 | break; | 487 | break; |
496 | default: | 488 | default: |
497 | error(1, 0, _("unknown level indent option: %s"), str); | 489 | error(EX_USAGE, 0, _("unknown level indent option: %s"), str); |
498 | } | 490 | } |
499 | } | 491 | } |
500 | 492 | ||
@@ -571,7 +563,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
571 | break; | 563 | break; |
572 | case 'f': | 564 | case 'f': |
573 | if (select_output_driver(arg)) | 565 | if (select_output_driver(arg)) |
574 | argp_error(state, _("%s: No such output driver"), optarg); | 566 | error(EX_USAGE, 0, _("%s: No such output driver"), optarg); |
575 | output_init(); | 567 | output_init(); |
576 | break; | 568 | break; |
577 | case OPT_LEVEL_INDENT: | 569 | case OPT_LEVEL_INDENT: |
@@ -599,7 +591,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
599 | SYMBOL_EXCLUDE(*arg); | 591 | SYMBOL_EXCLUDE(*arg); |
600 | break; | 592 | break; |
601 | default: | 593 | default: |
602 | argp_error(state, _("Unknown symbol class: %c"), *arg); | 594 | error(EX_USAGE, 0, _("Unknown symbol class: %c"), *arg); |
603 | } | 595 | } |
604 | break; | 596 | break; |
605 | case OPT_OMIT_ARGUMENTS: | 597 | case OPT_OMIT_ARGUMENTS: |
@@ -726,7 +718,7 @@ include_symbol(Symbol *sym) | |||
726 | void | 718 | void |
727 | xalloc_die(void) | 719 | xalloc_die(void) |
728 | { | 720 | { |
729 | error(1, ENOMEM, _("Exiting")); | 721 | error(EX_FATAL, ENOMEM, _("Exiting")); |
730 | } | 722 | } |
731 | 723 | ||
732 | void | 724 | void |
@@ -755,7 +747,8 @@ int | |||
755 | main(int argc, char **argv) | 747 | main(int argc, char **argv) |
756 | { | 748 | { |
757 | int index; | 749 | int index; |
758 | 750 | int status = EX_OK; | |
751 | |||
759 | set_program_name(argv[0]); | 752 | set_program_name(argv[0]); |
760 | argp_version_setup("cflow", program_authors); | 753 | argp_version_setup("cflow", program_authors); |
761 | 754 | ||
@@ -769,14 +762,17 @@ main(int argc, char **argv) | |||
769 | symbol_map = SM_FUNCTIONS|SM_STATIC|SM_UNDEFINED; | 762 | symbol_map = SM_FUNCTIONS|SM_STATIC|SM_UNDEFINED; |
770 | 763 | ||
771 | if (getenv("POSIXLY_CORRECT")) { | 764 | if (getenv("POSIXLY_CORRECT")) { |
772 | if (select_output_driver("posix")) | 765 | if (select_output_driver("posix")) { |
773 | error(1, 0, _("%s: No such output driver"), "posix"); | 766 | error(0, 0, _("INTERNAL ERROR: %s: No such output driver"), |
767 | "posix"); | ||
768 | abort(); | ||
769 | } | ||
774 | output_init(); | 770 | output_init(); |
775 | } | 771 | } |
776 | 772 | ||
777 | sourcerc(&argc, &argv); | 773 | sourcerc(&argc, &argv); |