]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: Add -t option to restrict the search to a type of code.
authorAlejandro Colomar <alx.manpages@gmail.com>
Thu, 12 May 2022 12:10:53 +0000 (14:10 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:59 +0000 (21:28 +0100)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc
share/man/man1/grepc.1

index 6b9e31c2d4c755e097de9669fd32fd78a445e634..e829a7c87834d28f606ca197d16833f281bc259b 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -5,6 +5,11 @@
 git='no';
 ext='\.[ch]$';
 FILES='.';
+tflag='no';
+t_enum='no';
+t_func='no';
+t_macro='no';
+t_type='no';
 
 
 grepc_usage()
@@ -15,7 +20,7 @@ grepc_usage()
 
 grepc_parse_cmd()
 {
-       while getopts "ghx:" opt; do
+       while getopts "ght:x:" opt; do
                case "$opt" in
                g)
                        git='yes';
@@ -24,6 +29,27 @@ grepc_parse_cmd()
                        grepc_usage;
                        exit 0;
                        ;;
+               t)
+                       case "$OPTARG" in
+                       e)
+                               t_enum='yes';
+                               ;;
+                       f)
+                               t_func='yes';
+                               ;;
+                       m)
+                               t_macro='yes';
+                               ;;
+                       t)
+                               t_type='yes';
+                               ;;
+                       *)
+                               grepc_usage;
+                               exit 1;
+                               ;;
+                       esac;
+                       tflag='yes';
+                       ;;
                x)
                        ext="$OPTARG";
                        ;;
@@ -225,7 +251,7 @@ grepc_type()
 }
 
 
-grepc_grepc()
+grepc_search_default()
 {
        grepc_enum_constant "$1";
        grepc_func "$1";
@@ -234,11 +260,33 @@ grepc_grepc()
 }
 
 
+grepc_search()
+{
+       if [ "$tflag" = 'no' ]; then
+               grepc_search_default "$1";
+
+       else
+               if [ "$t_enum" = 'yes' ]; then
+                       grepc_enum_constant "$1";
+               fi;
+               if [ "$t_func" = 'yes' ]; then
+                       grepc_func "$1";
+               fi;
+               if [ "$t_macro" = 'yes' ]; then
+                       grepc_macro "$1";
+               fi;
+               if [ "$t_type" = 'yes' ]; then
+                       grepc_type "$1";
+               fi;
+       fi;
+}
+
+
 main()
 {
        grepc_parse_cmd $@;
        grepc_find_files "$identifier";
-       grepc_grepc "$identifier" \
+       grepc_search "$identifier" \
        | tail -n+3;
 }
 
index 7003255910733e1cacf68bf6c51260c1fc7049fd..c45951032a0fbdc698355eb9fd36cb8724a9945a 100644 (file)
@@ -32,6 +32,24 @@ If no
 .I file
 is given,
 the working directory is searched.
+.SS Types of code
+This program can search for several types of code.
+The following arguments can be passed to the
+.B \-t
+option
+to select the types of code that will be searched.
+.TP
+.B e
+enum constant definitions.
+.TP
+.B f
+Function declarations and definitions.
+.TP
+.B m
+Macro definitions.
+.TP
+.B t
+Type definitions.
 .SH OPTIONS
 .TP
 .B \-g
@@ -40,6 +58,15 @@ Restrict the search to files tracked by git.
 .B \-h
 Output a help message and exit.
 .TP
+.BI \-t " type"
+Restrict the search to a specific
+.I type
+of code (see Types of code under DESCRIPTION).
+This option can be passed multiple times
+to search for various types of code.
+Default:
+.BR "e f m t" .
+.TP
 .BI \-x " extension"
 Restrict the search to files ending with
 .IR extension .