On Sun, Oct 06, 2019 at 02:28:09PM -0400, Ted Unangst wrote:
> The zstd package includes a zstdgrep script, which should behave like zgrep,
> however it assumes a few gnu grep behaviors we don't support.
> 
> 1. --label=name prints a custom label, so you can get file.txt, not
> file.txt.zst in the output.
> 
> 2. It uses - for stdin instead of a missing argument.
> 
> Both are easy to address, as below. With this, I can grep my old log files
> with having to do the zstdcat | grep dance myself.
These additions could be worth it but your diff does does not do well if
one deviates from your very specific use case;  comments inline.

> @@ -458,6 +464,11 @@ main(int argc, char *argv[])
>  
>       if (argc != 0 && needpattern) {
>               add_patterns(*argv);
> +             --argc;
> +             ++argv;
> +     }
> +     if (argc == 1 && strcmp(*argv, "-") == 0) {
> +             /* stdin */
If a dash denotes standard input, it should be allowed in every position.

>               --argc;
>               ++argv;
>       }
> Index: grep.h
> ===================================================================
> RCS file: /home/cvs/src/usr.bin/grep/grep.h,v
> retrieving revision 1.26
> diff -u -p -r1.26 grep.h
> --- grep.h    23 Jan 2019 23:00:54 -0000      1.26
> +++ grep.h    6 Oct 2019 18:09:32 -0000
> @@ -70,6 +70,7 @@ extern int   Aflag, Bflag, Eflag, Fflag, 
>                bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag, qflag,
>                sflag, vflag, wflag, xflag;
>  extern int    binbehave;
> +extern const char *labelname;
>  
>  extern int    first, matchall, patterns, tail, file_err;
>  extern char    **pattern;
> Index: util.c
> ===================================================================
> RCS file: /home/cvs/src/usr.bin/grep/util.c,v
> retrieving revision 1.60
> diff -u -p -r1.60 util.c
> --- util.c    17 Jul 2019 04:24:20 -0000      1.60
> +++ util.c    6 Oct 2019 18:10:07 -0000
> @@ -122,6 +122,8 @@ procfile(char *fn)
>       }
>  
>       ln.file = fn;
> +     if (labelname)
> +             ln.file = (char *)labelname;
This should only apply for standard input, otherwise you'll assign the
same label to all files when multiple are given.

>       ln.line_no = 0;
>       ln.len = 0;
>       linesqueued = 0;
> 

Reply via email to