aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
authorAlejandro Colomar <alx.manpages@gmail.com>2021-05-09 23:39:26 +0200
committerMichael Kerrisk <mtk.manpages@gmail.com>2021-05-10 11:33:51 +1200
commit34afcb0daddba9412f471e928dd2d1392a3de308 (patch)
tree38c8a5c47a222132f4834143caf0fb966498490e /scripts
parent94bf02f41b28c2dd5251d9bcc9368da2ec542f84 (diff)
downloadman-pages-34afcb0daddba9412f471e928dd2d1392a3de308.tar.gz
scripts/bash_aliases: srcfix
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bash_aliases24
1 files changed, 12 insertions, 12 deletions
diff --git a/scripts/bash_aliases b/scripts/bash_aliases
index a14026bda2..358e2f37a5 100644
--- a/scripts/bash_aliases
+++ b/scripts/bash_aliases
@@ -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/';