]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
scripts/bash_aliases: srcfix
authorAlejandro Colomar <alx.manpages@gmail.com>
Sun, 9 May 2021 21:39:26 +0000 (23:39 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Sun, 9 May 2021 23:33:51 +0000 (11:33 +1200)
I clarified the code about two things:

- Checking how many arguments are being passed.
    Here, some functions didn't reject extra arguments when they
    weren't being used.  Fix that.
    I also changed the code to use $#, which is more explicit.
    And use arithmetic expressions, which better indicate that
    we're dealing with numbers.

- Remove unneeded options from sort.
Reported-by: Stefan Puiu <stefan.puiu@gmail.com>
    After Stefan asked about why am I using 'sort -V',
    I noticed that I really don't need '-V', and it may confuse
    people trying to understand the script, so even though I
    slightly prefer the output of 'sort -V', in this case, it's
    better to use the simpler 'sort' (yet I need 'sort', to
    maintain consistency in the results (find is quite random)).

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
scripts/bash_aliases

index a14026bda2b96b819c6d68125d3c2a357795e56c..358e2f37a58dbd03338aab42e4c07a66e90d4d29 100644 (file)
@@ -45,20 +45,20 @@ function sed_rm_ccomments()
 
 function grep_syscall()
 {
-       if ! [ -v 1 ]; then
+       if (($# != 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
                return ${EX_USAGE};
        fi
 
        find * -type f \
        |grep '\.c$' \
-       |sort -V \
+       |sort \
        |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
 
        find * -type f \
        |grep '\.[ch]$' \
-       |sort -V \
+       |sort \
        |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
 }
@@ -70,14 +70,14 @@ function grep_syscall()
 
 function grep_syscall_def()
 {
-       if ! [ -v 1 ]; then
+       if (($# != 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
                return ${EX_USAGE};
        fi
 
        find * -type f \
        |grep '\.c$' \
-       |sort -V \
+       |sort \
        |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?^}" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';
 }
@@ -91,7 +91,7 @@ function grep_syscall_def()
 
 function man_section()
 {
-       if ! [ -v 2 ]; then
+       if (($# < 2)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>...";
                return ${EX_USAGE};
        fi
@@ -104,7 +104,7 @@ function man_section()
        |xargs wc -l \
        |grep -v -e '\b1 ' -e '\btotal\b' \
        |awk '{ print $2 }' \
-       |sort -V \
+       |sort \
        |while read -r manpage; do
                cat \
                <(<${manpage} sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}') \
@@ -125,7 +125,7 @@ function man_section()
 
 function man_lsfunc()
 {
-       if ! [ -v 1 ]; then
+       if (($# < 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
                return ${EX_USAGE};
        fi
@@ -147,7 +147,7 @@ function man_lsfunc()
 
 function man_lsvar()
 {
-       if ! [ -v 1 ]; then
+       if (($# < 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
                return ${EX_USAGE};
        fi
@@ -172,7 +172,7 @@ function man_lsvar()
 
 function pdfman()
 {
-       if ! [ -v 1 ]; then
+       if (($# != 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <man-page.n>";
                return ${EX_USAGE};
        fi;
@@ -209,14 +209,14 @@ function man_gitstaged()
 
 function grep_glibc_prototype()
 {
-       if ! [ -v 1 ]; then
+       if (($# != 1)); then
                >&2 echo "Usage: ${FUNCNAME[0]} <func>";
                return ${EX_USAGE};
        fi
 
        find * -type f \
        |grep '\.h$' \
-       |sort -V \
+       |sort \
        |xargs pcregrep -Mn \
          "(?s)^[\w[][\w\s(,)[:\]]+\s+\**${1}\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" \
        |sed -E 's/^[^:]+:[0-9]+:/&\n/';