From: girst Date: Fri, 16 Feb 2018 08:37:50 +0000 (+0100) Subject: add GREP_OVERRIDE, update man page, generate README X-Git-Url: https://git.gir.st/forkaftergrep.git/commitdiff_plain/4495ab7512f587495d121862a8a06f7fe2a0ecd9 add GREP_OVERRIDE, update man page, generate README --- diff --git a/README.md b/README.md index fbc28b3..2073686 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,20 @@ OPTIONS -t SECONDS Set a timeout of SECONDS seconds. - -k [SIGNAL] + -k[SIGNAL] If given, send a signal to PROGRAM. SIGNAL defaults to SIGTERM (15). Right now, only decimal notation is implemented. - -e Search PATTERN on stderr instead of stdout. + -r Search PATTERN on stderr instead of stdout. - -V Be verbose; print program's stdout (or stderr if -e is set) to + -l FILE + Log PROGRAM's stdout to FILE. The file will be opened in append + mode and created with permissions 0600 if it doesn't exist. + + -L FILE + Same as -l but logs PROGRAM's stderr. + + -V Be verbose; print program's stdout (or stderr if -r is set) to stderr. Generic Program Information @@ -34,6 +41,20 @@ OPTIONS -v Display version and copyright information and exit. + Supported grep Options + -E, -F, -G, -P + Matcher selection switches for extended regular expressions, + fixed strings, basic regular expressions (default) or Perl- + compatible regular expressions. At most one of them may be + supplied. + + -i, -w, -x, -U + Matching control switches for ignore case distinctions, whole + words only, whole lines only and treat as binary. + + -Z, -J Decompression switches for gzip(1) and bzip2(1). Not widely + supported; check your grep's capabilities. + EXIT STATUS If PATTERN was found, 0 is returned. Otherwise, the exit status follows the BSD guideline outlined in #include if the error @@ -50,20 +71,26 @@ BUGS https://github.com/girst/forkaftergrep/. NOTES - SIGNAL needs to be given as an integer. implementing mnemonics is dirty - and not very portable; maybe support in the future. + Usually, fag uses the grep supplied in the path. This behaviour can be + overridden with the environment variable GREP_OVERRIDE. - Since 1.1, if fag gets interrupted or terminated, SIGTERM is sent to + Since 1.2, if fag gets interrupted or terminated before a match is + found (or the timeout has been reached), this signal is passed to PROGRAM. + In version 1.2 the command line switch -e was renamed to -r to avoid + overloading grep's own switches. An error will be thrown when -e or -f + is supplied as an argument. + COPYRIGHT - Copyright 2017 Tobias Girstmair. This is free software; see + Copyright 2017-2018 Tobias Girstmair. This is free software released + under the terms of the GNU General Public License Version 3; see https://www.gnu.org/licenses/gpl-3.0.html for conditions. AUTHOR - Tobias Girstmair (https://gir.st) + Tobias Girstmair (https://gir.st/) -1.1 13 October 2017 fag(1) +1.2 16 February 2018 fag(1) ``` ## Notes diff --git a/fag.1 b/fag.1 index 5789c9d..793be99 100644 --- a/fag.1 +++ b/fag.1 @@ -27,7 +27,7 @@ Set a timeout of .I SECONDS seconds. .TP -.BR \-k " [" \fISIGNAL\fP "] +.BR \-k "[" \fISIGNAL\fP "] If given, send a signal to .IR PROGRAM . .I SIGNAL @@ -74,7 +74,7 @@ Display version and copyright information and exit. .SS "Supported grep Options" .TP .BR \-E ", " \-F ", " \-G ", " \-P -Matcher selection switches for extended regular expressions, fixed strings, basic regular expressions (default) or Perl-compatible regular expressions. You may only supply one of them. +Matcher selection switches for extended regular expressions, fixed strings, basic regular expressions (default) or Perl-compatible regular expressions. At most one of them may be supplied. .TP .BR \-i ", " \-w ", " \-x ", " \-U Matching control switches for ignore case distinctions, whole words only, whole lines only and treat as binary. @@ -99,22 +99,28 @@ if grep gets killed (e.g. `killall grep'), fag should terminate. .SS Reporting Bugs Please report bugs and patches to the issue tracker at https://github.com/girst/forkaftergrep/. .SH NOTES -.IR SIGNAL -needs to be given as an integer. implementing mnemonics is dirty and not very portable; maybe support in the future. +Usually, +.B fag +uses the +.B grep +supplied in the path. This behaviour can be overridden with the environment variable +.IR GREP_OVERRIDE . .PP -Since 1.1, if +Since 1.2, if .B fag -gets interrupted or terminated, -.BR SIGTERM -is sent to -.IR PROGRAM. +gets interrupted or terminated before a match is found (or the timeout has been reached), this signal is passed to +.IR PROGRAM . .PP -In 1.2 the command line switch +In version 1.2 the command line switch .B \-e was renamed to .B \-r to avoid overloading -.B grep\fR's own switches. +.B grep\fR's own switches. An error will be thrown when +.BR \-e +or +.BR \-f +is supplied as an argument. .SH COPYRIGHT -Copyright 2017 Tobias Girstmair. This is free software; see https://www.gnu.org/licenses/gpl-3.0.html for conditions. +Copyright 2017-2018 Tobias Girstmair. This is free software released under the terms of the GNU General Public License Version 3; see https://www.gnu.org/licenses/gpl-3.0.html for conditions. .SH AUTHOR -Tobias Girstmair (https://gir.st) +Tobias Girstmair (https://gir.st/) diff --git a/fag.c b/fag.c index 7d713f4..1ba077d 100644 --- a/fag.c +++ b/fag.c @@ -5,6 +5,7 @@ #define _DEFAULT_SOURCE #include #include +#include #include #include #include @@ -243,7 +244,12 @@ int fork_after_grep (struct opt opts) { close (STDOUT_FILENO); - execlp ("grep", "grep", opts.grepopt, "--", opts.pattern, NULL); + char* grep_override = getenv("GREP_OVERRIDE"); + if (grep_override != NULL) { + execlp (grep_override, basename(grep_override), opts.grepopt, "--", opts.pattern, NULL); + } else { + execlp ("grep", "grep", opts.grepopt, "--", opts.pattern, NULL); + } fprintf (stderr, "exec error (grep): %s", strerror (errno)); _exit (EX_SOFTWARE); } else {