Closed alejandro-colomar closed 12 months ago
Note: pcre2grep is more of a demo program, not a grep replacement. Adding features there is not a priority, so we cannot promise anything.
... but I will take a look at this soon because it doesn't sound to be too much work.
On Wed, Nov 15, 2023 at 02:21:55AM -0800, Zoltan Herczeg wrote:
Note: pcre2grep is more of a demo program, not a grep replacement. Adding features there is not a priority, so we cannot promise anything.
Heh! You may be interested in learning that I've abused your demo program to some useful extremes: :)
https://www.alejandro-colomar.es/src/alx/alx/grepc.git https://www.alejandro-colomar.es/src/alx/alx/grepc.git/tree/bin/grepc
That's a program resembing grep(1), but instead of finding text, it finds C code. It is basically a wrapper around pcre2grep(1), with some quite complex regexes. Below go some examples of use.
Cheers, Alex
$ grepc MAX /usr/include/
/usr/include/x86_64-linux-gnu/sys/param.h:#define MAX(a,b) (((a)>(b))?(a):(b))
$ grepc -C2 MAX /usr/include/
/usr/include/x86_64-linux-gnu/sys/param.h-/* Macros for min/max. */
/usr/include/x86_64-linux-gnu/sys/param.h-#define MIN(a,b) (((a)<(b))?(a):(b))
/usr/include/x86_64-linux-gnu/sys/param.h:#define MAX(a,b) (((a)>(b))?(a):(b))
/usr/include/x86_64-linux-gnu/sys/param.h-
/usr/include/x86_64-linux-gnu/sys/param.h-
$ grepc is_valid_user_name /home/alx/src/shadow/shadow/master/
/home/alx/src/shadow/shadow/master/lib/chkname.h:extern bool is_valid_user_name (const char *name);
/home/alx/src/shadow/shadow/master/lib/chkname.c:bool is_valid_user_name (const char *name)
{
/*
* User names length are limited by the kernel
*/
if (strlen (name) > sysconf(_SC_LOGIN_NAME_MAX)) {
return false;
}
return is_valid_name (name);
}
$ </usr/include/x86_64-linux-gnu/sys/param.h grepc -n roundup
(standard input):93:# define roundup(x, y) (__builtin_constant_p (y) && powerof2 (y) \
? (((x) + (y) - 1) & ~((y) - 1)) \
: ((((x) + ((y) - 1)) / (y)) * (y)))
(standard input):97:# define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
-- Reply to this email directly or view it on GitHub: https://github.com/PCRE2Project/pcre2/issues/316#issuecomment-1812178486 You are receiving this because you authored the thread.
Message ID: @.***>
I have implemented this in HEAD.
Thanks! I'll be waiting for your next release. :)
Closed as completed.
From GNU grep(1):
In pcre2grep(1) there's
but there's no way to tweak the separator between matches in -A, -B, or -C mode.