]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: -h: Add option to print the usage message.
authorAlejandro Colomar <alx.manpages@gmail.com>
Wed, 11 May 2022 17:51:46 +0000 (19:51 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:57 +0000 (21:28 +0100)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc
share/man/man1/grepc.1

index ad60951e91fb0a0d8c6773e6a682b6070ec0eada..3d78821dacc07910218cff2d063edb8e94d2d6c4 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -1,10 +1,34 @@
 #!/bin/sh
 
 
-if [ $# -ne 1 ]; then
-       >&2 echo "Usage: $0 IDENTIFIER";
-       exit 1;
-fi;
+grepc_usage()
+{
+       echo "Usage: $0 [OPTION] IDENTIFIER";
+}
+
+
+grepc_parse_cmd()
+{
+       while getopts "h" opt; do
+               case "$opt" in
+               h)
+                       grepc_usage;
+                       exit 0;
+                       ;;
+               ?)
+                       grepc_usage >&2;
+                       exit 1;
+                       ;;
+               esac;
+       done;
+       shift $(($OPTIND-1));
+
+       if [ $# -ne 1 ]; then
+               grepc_usage >&2;
+               exit 1;
+       fi;
+       identifier=$1;
+}
 
 
 grepc_find_files()
@@ -180,15 +204,17 @@ grepc_type()
 
 main()
 {
-       grepc_find_files "$1";
+       grepc_parse_cmd $@;
+
+       grepc_find_files "$identifier";
 
-       grepc_macro "$1";
-       grepc_enum_constant "$1";
-       grepc_func "$1";
-       grepc_linux "$1";
-       grepc_glibc "$1";
-       grepc_type "$1";
+       grepc_macro "$identifier";
+       grepc_enum_constant "$identifier";
+       grepc_func "$identifier";
+       grepc_linux "$identifier";
+       grepc_glibc "$identifier";
+       grepc_type "$identifier";
 }
 
 
-main "$1";
+main $@;
index ce53aa32b187ab1ee9c9d5b7f66147da1a46c3e8..02fb715c293917cb4f2cbb4eca3b33bc821fd6b5 100644 (file)
@@ -3,6 +3,7 @@
 grepc \- find C declarations and definitions in source code
 .SH SYNOPSIS
 .B grepc
+.RI [ option ]
 .I identifier
 .SH DESCRIPTION
 .MR grepc 1
@@ -13,6 +14,10 @@ in all .c and .h files under the current working directory.
 is normally a C identifier,
 but it is actually a PCRE pattern,
 so it can be used to find complex patterns.
+.SH OPTIONS
+.TP
+.B \-h
+Output a help message and exit.
 .SH EXAMPLES
 .EX
 .RB \(ti/src/nginx/unit$ " grepc nxt_sprintf;"