summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-12 14:10:53 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-12 14:11:42 +0200
commit9d731d282c3eb7b7b6cb192c0b19e3702c6cd658 (patch)
treeb72cb47223989043a9b99447140ad631025415fc
parentfbed97a8ff8878e88cc60023fee5862a01965353 (diff)
grepc, grepc.1: Add -t option to restrict the search to a type of code.
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rwxr-xr-xbin/grepc54
-rw-r--r--share/man/man1/grepc.127
2 files changed, 78 insertions, 3 deletions
diff --git a/bin/grepc b/bin/grepc
index 6b9e31c..e829a7c 100755
--- 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;
}
diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1
index 7003255..c459510 100644
--- a/share/man/man1/grepc.1
+++ b/share/man/man1/grepc.1
@@ -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 .