]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: Add optional FILE trailing arguments
authorAlejandro Colomar <alx.manpages@gmail.com>
Wed, 11 May 2022 18:46:01 +0000 (20:46 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:58 +0000 (21:28 +0100)
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc
share/man/man1/grepc.1

index 89cd84d11b45d6b39de2dd22ff8960fff7a76936..56a1914d191b6d8b32bd67ff1aa62fa1aaed9702 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -4,11 +4,12 @@
 # Defaults:
 git='no';
 ext='\.[ch]$';
+FILES='.';
 
 
 grepc_usage()
 {
-       echo "Usage: $0 [OPTION ...] IDENTIFIER";
+       echo "Usage: $0 [OPTION ...] IDENTIFIER [FILE ...]";
 }
 
 
@@ -34,11 +35,16 @@ grepc_parse_cmd()
        done;
        shift $(($OPTIND-1));
 
-       if [ $# -ne 1 ]; then
+       if [ $# -lt 1 ]; then
                grepc_usage >&2;
                exit 1;
        fi;
        identifier=$1;
+       shift;
+
+       if [ $# -gt 0 ]; then
+               FILES=$@;
+       fi;
 }
 
 
@@ -47,9 +53,9 @@ grepc_find_files()
        files="$(mktemp -t 'grepc.XXXXXX')";
 
        if [ "$git" = 'yes' ]; then
-               git ls-files .;
+               git ls-files $FILES;
        else
-               find . -type f;
+               find $FILES -type f;
        fi \
        | grep -P "$ext" \
        | xargs grep -lPI "$1\b" \
index 6caaeb5044ac4b0ff2327179e602d9dff55761cf..b8403f9b8765250e29e6c9b464457fdeba4bc1b7 100644 (file)
@@ -5,15 +5,33 @@ grepc \- find C declarations and definitions in source code
 .B grepc
 .RI [ option " ...]"
 .I identifier
+.RI [ file " ...]"
 .SH DESCRIPTION
 .MR grepc 1
-searches for all C declarations and definitions of
+searches for C declarations and definitions of
 .I identifier
-in all .c and .h files under the current working directory.
+in each
+.IR file .
+.PP
 .I identifier
 is normally a C identifier,
 but it is actually a PCRE pattern,
 so it can be used to find complex patterns.
+.PP
+If
+.I file
+is a directory,
+the search is recursive within that directory.
+If
+.I file
+doesn't match a certain extension, it is skipped
+(see
+.B \-x
+in OPTIONS).
+If no
+.I file
+is given,
+the working directory is searched.
 .SH OPTIONS
 .TP
 .B \-g