aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-02-07 20:29:53 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-02-07 20:29:53 +0200
commit548e46e7de424c06743d844fc35b091982d5bee5 (patch)
tree9e6e118d80a6e2d3fa52fca87c16ea453b378f58 /src
parent4be79061e8f68f6e3174a05452d96f31e8062464 (diff)
downloadcflow-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.
Diffstat (limited to 'src')
-rw-r--r--src/cflow.h6
-rw-r--r--src/main.c60
-rw-r--r--src/output.c2
-rw-r--r--src/parser.c6
-rw-r--r--src/posix.c3
-rw-r--r--src/rc.c13
6 files changed, 47 insertions, 43 deletions
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
46struct linked_list_entry { 52struct linked_list_entry {
diff --git a/src/main.c b/src/main.c
index e78993a..4facaf5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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)
726void 718void
727xalloc_die(void) 719xalloc_die(void)
728{ 720{
729 error(1, ENOMEM, _("Exiting")); 721 error(EX_FATAL, ENOMEM, _("Exiting"));
730} 722}
731 723
732void 724void
@@ -755,7 +747,8 @@ int
755main(int argc, char **argv) 747main(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);
778 if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, &index, NULL)) 774 if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
779 exit(1); 775 exit(EX_USAGE);
780 776
781 if (print_option == 0) 777 if (print_option == 0)
782 print_option = PRINT_TREE; 778 print_option = PRINT_TREE;
@@ -801,13 +797,15 @@ main(int argc, char **argv)
801 while (argc--) { 797 while (argc--) {
802 if (source(*argv++) == 0) 798 if (source(*argv++) == 0)
803 yyparse(); 799 yyparse();
800 else
801 status = EX_SOFT;
804 } 802 }
805 803
806 if (input_file_count == 0) 804 if (input_file_count == 0)
807 error(1, 0, _("no input files")); 805 error(EX_USAGE, 0, _("no input files"));
808 806
809 output(); 807 output();
810 return 0; 808 return status;
811} 809}
812 810
813 811
diff --git a/src/output.c b/src/output.c
index d46b496..2def906 100644
--- a/src/output.c
+++ b/src/output.c
@@ -419,7 +419,7 @@ output()
419 } else { 419 } else {
420 outfile = fopen(outname, "w"); 420 outfile = fopen(outname, "w");
421 if (!outfile) 421 if (!outfile)
422 error(2, errno, _("cannot open file `%s'"), outname); 422 error(EX_FATAL, errno, _("cannot open file `%s'"), outname);
423 } 423 }
424 424
425 set_level_mark(0, 0); 425 set_level_mark(0, 0);
diff --git a/src/parser.c b/src/parser.c
index be82197..c26cd9c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -307,8 +307,10 @@ nexttoken()
307int 307int
308putback() 308putback()
309{ 309{
310 if (curs == 0) 310 if (curs == 0) {
311 error(10, 0, _("INTERNAL ERROR: cannot return token to stream")); 311 error(0, 0, _("INTERNAL ERROR: cannot return token to stream"));
312 abort();
313 }
312 curs--; 314 curs--;
313 if (curs > 0) { 315 if (curs > 0) {
314 tok = token_stack[curs-1]; 316 tok = token_stack[curs-1];
diff --git a/src/posix.c b/src/posix.c
index d0caac8..4a63183 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -55,7 +55,8 @@ posix_output_handler(cflow_output_command cmd,
55 case cflow_output_init: 55