diff options
-rw-r--r-- | cfg.mk | 1 | ||||
-rw-r--r-- | src/grep.c | 33 | ||||
-rw-r--r-- | src/search.c | 32 | ||||
-rw-r--r-- | src/system.h | 2 | ||||
-rw-r--r-- | src/vms_fab.c | 2 |
5 files changed, 37 insertions, 33 deletions
@@ -26,7 +26,6 @@ local-checks-to-skip = \ sc_error_message_uppercase \ sc_m4_quote_check \ sc_makefile_TAB_only_indentation \ - sc_prohibit_magic_number_exit \ sc_prohibit_strcmp \ sc_space_tab \ sc_useless_cpp_parens @@ -396,7 +396,8 @@ context_length_arg (char const *str, int *out) && 0 <= (*out = value) && *out == value)) { - error (2, 0, "%s: %s\n", str, _("invalid context length argument")); + error (EXIT_TROUBLE, 0, "%s: %s\n", str, + _("invalid context length argument")); } } @@ -657,7 +658,7 @@ add_count (uintmax_t a, uintmax_t b) { uintmax_t sum = a + b; if (sum < a) - error (2, 0, _("input is too large to count")); + error (EXIT_TROUBLE, 0, _("input is too large to count")); return sum; } @@ -1047,7 +1048,7 @@ grepbuf (char const *beg, char const *lim) if (!outleft || done_on_match) { if (exit_on_match) - exit (0); + exit (EXIT_SUCCESS); after_last_match = bufoffset - (buflim - endp); return nlines; } @@ -1529,7 +1530,7 @@ static void setmatcher (char const *m) { if (matcher && strcmp (matcher, m) != 0) - error (2, 0, _("conflicting matchers specified")); + error (EXIT_TROUBLE, 0, _("conflicting matchers specified")); matcher = m; } @@ -1905,7 +1906,7 @@ main (int argc, char **argv) else if (strcmp (optarg, "skip") == 0) devices = SKIP_DEVICES; else - error (2, 0, _("unknown devices method")); + error (EXIT_TROUBLE, 0, _("unknown devices method")); break; #ifdef GREP_PROGRAM @@ -1979,7 +1980,7 @@ main (int argc, char **argv) else if (strcmp (optarg, "recurse") == 0) directories = RECURSE_DIRECTORIES; else - error (2, 0, _("unknown directories method")); + error (EXIT_TROUBLE, 0, _("unknown directories method")); break; case 'e': @@ -1993,7 +1994,7 @@ main (int argc, char **argv) case 'f': fp = strcmp (optarg, "-") != 0 ? fopen (optarg, "r") : stdin; if (!fp) - error (2, errno, "%s", optarg); + error (EXIT_TROUBLE, errno, "%s", optarg); for (keyalloc = 1; keyalloc <= keycc + 1; keyalloc *= 2) ; keys = xrealloc (keys, keyalloc); @@ -2047,7 +2048,7 @@ main (int argc, char **argv) break; default: - error (2, 0, _("invalid max count")); + error (EXIT_TROUBLE, 0, _("invalid max count")); } } break; @@ -2102,7 +2103,7 @@ main (int argc, char **argv) else if (strcmp (optarg, "without-match") == 0) binary_files = WITHOUT_MATCH_BINARY_FILES; else - error (2, 0, _("unknown binary-files type")); + error (EXIT_TROUBLE, 0, _("unknown binary-files type")); break; case COLOR_OPTION: @@ -2140,7 +2141,7 @@ main (int argc, char **argv) if (add_exclude_file (add_exclude, excluded_patterns, optarg, EXCLUDE_WILDCARDS, '\n') != 0) { - error (2, errno, "%s", optarg); + error (EXIT_TROUBLE, errno, "%s", optarg); } break; @@ -2171,7 +2172,7 @@ main (int argc, char **argv) break; default: - usage (2); + usage (EXIT_TROUBLE); break; } @@ -2213,11 +2214,11 @@ This is free software: you are free to change and redistribute it.\n\ There is NO WARRANTY, to the extent permitted by law.\n"), "2009"); printf ("\n"); - exit (0); + exit (EXIT_SUCCESS); } if (show_help) - usage (0); + usage (EXIT_SUCCESS); if (keys) { @@ -2240,7 +2241,7 @@ There is NO WARRANTY, to the extent permitted by law.\n"), strcpy(keys, argv[optind++]); } else - usage (2); + usage (EXIT_TROUBLE); #ifdef GREP_PROGRAM if (! matcher) @@ -2270,7 +2271,7 @@ There is NO WARRANTY, to the extent permitted by law.\n"), #endif if (max_count == 0) - exit (1); + exit (EXIT_FAILURE); if (optind < argc) { @@ -2297,6 +2298,6 @@ There is NO WARRANTY, to the extent permitted by law.\n"), status = grepfile ((char *) NULL, &stats_base); /* We register via atexit() to test stdout. */ - exit (errseen ? 2 : status); + exit (errseen ? EXIT_TROUBLE : status); } /* vim:set shiftwidth=2: */ diff --git a/src/search.c b/src/search.c index edcb3764..cf39e0df 100644 --- a/src/search.c +++ b/src/search.c @@ -64,7 +64,7 @@ kwsinit (void) trans[i] = TOLOWER (i); if (!(kwset = kwsalloc (match_icase ? trans : (char *) 0))) - error (2, 0, _("memory exhausted")); + xalloc_die (); } #ifndef FGREP_PROGRAM @@ -86,7 +86,7 @@ size_t pcount; void dfaerror (char const *mesg) { - error (2, 0, "%s", mesg); + error (EXIT_TROUBLE, 0, "%s", mesg); } /* Number of compiled fixed strings known to exactly match the regexp. @@ -116,7 +116,7 @@ kwsmusts (void) continue; ++kwset_exact_matches; if ((err = kwsincr (kwset, dm->must, strlen (dm->must))) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); } /* Now, we compile the substrings that will require the use of the regexp matcher. */ @@ -125,10 +125,10 @@ kwsmusts (void) if (dm->exact) continue; if ((err = kwsincr (kwset, dm->must, strlen (dm->must))) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); } if ((err = kwsprep (kwset)) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); } } #endif /* !FGREP_PROGRAM */ @@ -248,12 +248,12 @@ GEAcompile (char const *pattern, size_t size, reg_syntax_t syntax_bits) patterns = realloc (patterns, (pcount + 1) * sizeof (*patterns)); if (patterns == NULL) - error (2, errno, _("memory exhausted")); + error (EXIT_TROUBLE, errno, _("memory exhausted")); patterns[pcount] = patterns0; if ((err = re_compile_pattern (motif, len, &(patterns[pcount].regexbuf))) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); pcount++; motif = sep; @@ -547,13 +547,13 @@ COMPILE_FCT(Fcompile) #endif } if ((err = kwsincr (kwset, beg, end - beg)) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); beg = lim; } while (beg < pattern + size); if ((err = kwsprep (kwset)) != NULL) - error (2, 0, "%s", err); + error (EXIT_TROUBLE, 0, "%s", err); } EXECUTE_FCT(Fexecute) @@ -663,7 +663,9 @@ static pcre_extra *extra; COMPILE_FCT(Pcompile) { #if !HAVE_LIBPCRE - error (2, 0, "%s", _("Support for the -P option is not compiled into this --disable-perl-regexp binary")); + error (EXIT_TROUBLE, 0, "%s", + _("Support for the -P option is not compiled into " + "this --disable-perl-regexp binary")); #else int e; char const *ep; @@ -676,9 +678,9 @@ COMPILE_FCT(Pcompile) /* FIXME: Remove these restrictions. */ if (eolbyte != '\n') - error (2, 0, _("The -P and -z options cannot be combined")); + error (EXIT_TROUBLE, 0, _("The -P and -z options cannot be combined")); if (memchr(pattern, '\n', size)) - error (2, 0, _("The -P option only supports a single pattern")); + error (EXIT_TROUBLE, 0, _("The -P option only supports a single pattern")); *n = '\0'; if (match_lines) @@ -716,11 +718,11 @@ COMPILE_FCT(Pcompile) cre = pcre_compile (re, flags, &ep, &e, pcre_maketables ()); if (!cre) - error (2, 0, "%s", ep); + error (EXIT_TROUBLE, 0, "%s", ep); extra = pcre_study (cre, 0, &ep); if (ep) - error (2, 0, "%s", ep); + error (EXIT_TROUBLE, 0, "%s", ep); free (re); #endif @@ -748,7 +750,7 @@ EXECUTE_FCT(Pexecute) return -1; case PCRE_ERROR_NOMEMORY: - error (2, 0, _("Memory exhausted")); + error (EXIT_TROUBLE, 0, _("Memory exhausted")); default: abort (); diff --git a/src/system.h b/src/system.h index dddb0268..93fdbf14 100644 --- a/src/system.h +++ b/src/system.h @@ -54,6 +54,8 @@ #include <string.h> #include <ctype.h> +enum { EXIT_TROUBLE = 2 }; + /* The extra casts work around common compiler bugs. */ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ diff --git a/src/vms_fab.c b/src/vms_fab.c index ec3cc23e..4106175b 100644 --- a/src/vms_fab.c +++ b/src/vms_fab.c @@ -63,7 +63,7 @@ vms_fab (int * argp, char **argvp[]) if (fab_stat != 65537) { fprintf (stderr, "No Matches found.\n"); - exit (0); + exit (EXIT_SUCCESS); } /* |