bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small patch for grep


From: Alain Magloire
Subject: Re: Small patch for grep
Date: Sat, 31 Mar 2001 12:00:59 -0500 (EST)

Bonjour

  I do not see this as particularly usefull, at first glance.  But that
does not mean I'm right 8).  So I will bounce you mail to bug-gnu-utils.
Someone else may find it usefull and convice me otherwise.  You may want
to send the patch to <address@hidden> with a proper format also.

Thanks for the feedback.

--
alain

> 
> --azLHFNyN32YCQGCU
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> Hi.
> 
> If I'm not wrong, U are maintainer of gnu grep?
> 
> I wrote small, but very useful patch for grep (and I want for U applied it
> to grep :-)
> 
> I added key -D (or --filename-once), that print "-- filename:" instead of "--"
> with options such as -C, for example:
> 
> W/o using my patch:
> 
> address@hidden:/usr/share/vim/vim56/doc]% grep -C3 using *.txt | head -15
> autocmd.txt-                                                    *GUIEnter*
> autocmd.txt-GUIEnter                    After starting the GUI succesfully, 
> and
> after
> autocmd.txt-                            opening the window.  It is triggered 
> before
> autocmd.txt:                            VimEnter when using gvim.  Can be 
> used to
> autocmd.txt-                            position the window from a .gvimrc 
> file:autocmd.txt->   :autocommand GUIEnter * winpos 100 50
> autocmd.txt-                                                    *VimEnter*
> --
> autocmd.txt->    let myfiletypefile = "~/vim/myfiletypes.vim"
> autocmd.txt-
> autocmd.txt-   Your file will then be sourced after the default FileType 
> autocommands have
> autocmd.txt:   been installed.  This allows you to overrule any of the 
> defaults, by using
> autocmd.txt-   ":au!" to remove any existing FileType autocommands for the 
> same
> pattern.
> autocmd.txt-   Only the autocommand to source the scripts.vim file is given 
> later.  This
> autocmd.txt-   makes sure that your autocommands in "myfiletypefile" are used 
> before
> address@hidden:/usr/share/vim/vim56/doc]%
> 
> U'll value this if U read this in term. with width ~ 80 cols.
> Using my patch:
> 
> address@hidden:/usr/share/vim/vim56/doc]% grep -DC3 using *.txt | head -15
> -- autocmd.txt:
>                                                         *GUIEnter*
> GUIEnter                        After starting the GUI succesfully, and after
>                                 opening the window.  It is triggered before
>                                 VimEnter when using gvim.  Can be used to
>                                 position the window from a .gvimrc file:
> >       :autocommand GUIEnter * winpos 100 50
>                                                         *VimEnter*
> -- autocmd.txt:
> >    let myfiletypefile = "~/vim/myfiletypes.vim"
> 
>    Your file will then be sourced after the default FileType autocommands have
>    been installed.  This allows you to overrule any of the defaults, by using
>    ":au!" to remove any existing FileType autocommands for the same pattern.
>    Only the autocommand to source the scripts.vim file is given later.  This
> address@hidden:/usr/share/vim/vim56/doc]%
> 
> If I do that writing full path name 
> (grep -C3 using /usr/share/vim/vim56/doc/*.txt) it become unable to read
> output :-)
> 
> This is very useful patch.
> 
> And some else: If U agree to apply this patch, I'll write patch for grep.1 
> (man. page).
> 
> I'm sorry for my bad English, I don't like to go University to English 
> lessons :-)
> 
> Please, confirm this letter (to address@hidden) in any case, my post
> sometimes doesn't work properly.
> 
> Stepan K.
> 
> 
> --azLHFNyN32YCQGCU
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: attachment; filename="grep-2.4.2-yozh.patch"
> 
> *** grep-2.4.2/src/grep.c     Wed Feb  2 08:49:07 2000
> --- grep-2.4.2.my/src/grep.c  Tue Mar 27 02:51:40 2001
> ***************
> *** 61,65 ****
>   /* Short options.  */
>   static char const short_options[] =
> ! "0123456789A:B:C::EFGHIUVX:abcd:e:f:hiLlnqrsuvwxyZz";
>   
>   /* Non-boolean long options that have no corresponding short equivalents.  
> */
> --- 61,65 ----
>   /* Short options.  */
>   static char const short_options[] =
> ! "0123456789A:B:C::DEFGHIUVX:abcd:e:f:hiLlnqrsuvwxyZz";
>   
>   /* Non-boolean long options that have no corresponding short equivalents.  
> */
> ***************
> *** 82,85 ****
> --- 82,86 ----
>     {"extended-regexp", no_argument, NULL, 'E'},
>     {"file", required_argument, NULL, 'f'},
> +   {"filename-once", no_argument, NULL, 'D' },
>     {"files-with-matches", no_argument, NULL, 'l'},
>     {"files-without-match", no_argument, NULL, 'L'},
> ***************
> *** 486,489 ****
> --- 487,491 ----
>   static int no_filenames;    /* Suppress file names.  */
>   static int suppress_errors; /* Suppress diagnostics.  */
> + static int filename_once;   /* Show filename once after "--" */
>   
>   /* Internal variables to keep track of byte count, context, etc. */
> ***************
> *** 597,603 ****
>         while (p > bp && p[-1] != eol);
>   
>         /* We only print the "--" separator if our output is
>        discontiguous from the last output in the file. */
> !       if ((out_before || out_after) && used && p != lastout)
>       puts ("--");
>   
> --- 599,609 ----
>         while (p > bp && p[-1] != eol);
>   
> +       /* We only print the "-- filename:" if our output is
> +     discontiguous from the last output in the file :-) */
> +       if((out_before || out_after) && p != lastout && filename_once)
> +     printf ("-- %s:\n", filename);
>         /* We only print the "--" separator if our output is
>        discontiguous from the last output in the file. */
> !       else if ((out_before || out_after) && used && p != lastout)
>       puts ("--");
>   
> ***************
> *** 992,995 ****
> --- 998,1002 ----
>     -C, --context[=NUM]       print NUM (default 2) lines of output context\n\
>                               unless overridden by -A or -B\n\
> +   -D, --filename-once       print \"-- filename:\" instead of \"--\"
>     -NUM                      same as --context=NUM\n\
>     -U, --binary              do not strip CR characters at EOL (MSDOS)\n\
> ***************
> *** 1221,1224 ****
> --- 1228,1236 ----
>       else
>         default_context = 2;
> +     break;
> +       case 'D':
> +     /* Using with -A, -B or -C print "-- filename:" intead of "--" */
> +     filename_once = 1;
> +     no_filenames = 1;
>       break;
>         case 'E':
> 
> --azLHFNyN32YCQGCU--
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]