All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: Stefan Puiu <stefan.puiu@gmail.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>,
	lnx-man <linux-man@vger.kernel.org>, Walter Harms <wharms@bfs.de>
Subject: Re: [PATCH v9] scripts/bash_aliases: Add useful functions
Date: Sat, 27 Feb 2021 18:16:11 +0100	[thread overview]
Message-ID: <072ee0c3-f30f-9da3-1b3f-37b5bc095806@gmail.com> (raw)
In-Reply-To: <CACKs7VAD69B2+rRPkXLwy0YtVOswvbqJjvvMNQ_rdQoBjF-sow@mail.gmail.com>

Hi Stefan,

On 2/27/21 4:09 PM, Stefan Puiu wrote:
> Sorry for jumping in this discussion so late, but I was wondering
> about one thing (see below).
> 
> On Fri, Feb 19, 2021 at 4:38 PM Alejandro Colomar
> <alx.manpages@gmail.com> wrote:
>> +#  grep_syscall()  finds the prototype of a syscall in the kernel sources,
>> +# printing the filename, line number, and the prototype.
>> +# It should be run from the root of the linux kernel source tree.
>> +# Usage example:  .../linux$ grep_syscall openat2;
>> +
>> +function grep_syscall()
>> +{
>> +       if ! [ -v 1 ]; then
>> +               >&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
>> +               return ${EX_USAGE};
>> +       fi
>> +
>> +       find * -type f \
>> +       |grep '\.c$' \
>> +       |sort -V \
>> +       |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
>> +       |sed -E 's/^[^:]+:[0-9]+:/&\n/';
>> +
>> +       find * -type f \
>> +       |grep '\.[ch]$' \
> 
> Any reason not to use "find . -type f -name '*.[ch]'" when you need to
> restrict the files you're looking at? I would expect that to be
> faster.

I don't like find syntax.  I never remember how all of its options work.
grep is much simpler, and everyone knows how it works.

find has: -[i]lname, -[i]name, -[i]path, -[i]regex, -[i]wholename
I don't want to be reading the manual for all of them each time I use 
find.  grep does the same with optional -i and some simple regex which 
anyone could understand with some basic regex knowledge.

For the performance part, I don't know; but we might be surprised.  At 
most it might be a bit faster (nothing like 200%), but I care more about 
readability.

I also avoid using find -exec option, and instead use xargs.  It's way 
simpler to understand, at least for me.

See also:
<http://doc.cat-v.org/unix/find-history>
<http://harmful.cat-v.org/cat-v/>

> Also, not sure what you are trying to do with 'sort -V' - why
> not feed the results directly to pcregrep?

Some consistency.  Sometimes this function finds more than one prototype 
for a syscall.  I prefer that everyone using this function gets the 
results in the same predictable order, instead of some random order.

> 
>> +       |sort -V \
>> +       |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
>> +       |sed -E 's/^[^:]+:[0-9]+:/&\n/';
>> +}

Regards,

Alex

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

  reply	other threads:[~2021-02-27 17:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 13:15 [PATCH] scripts/bash_aliases: Add useful functions Alejandro Colomar
2021-02-15 13:36 ` Alejandro Colomar (man-pages)
2021-02-15 20:31 ` Alejandro Colomar
2021-02-15 20:32 ` [PATCH v3] " Alejandro Colomar
2021-02-16 10:54   ` AW: " Walter Harms
2021-02-16 11:00     ` Alejandro Colomar (man-pages)
2021-02-18 18:47 ` [PATCH v4] " Alejandro Colomar
2021-02-18 19:33 ` [PATCH v5] " Alejandro Colomar
2021-02-18 21:17 ` [PATCH v6] " Alejandro Colomar
2021-02-19 14:13 ` [PATCH v7] " Alejandro Colomar
2021-02-19 14:22 ` [PATCH v8] " Alejandro Colomar
2021-02-19 14:32 ` [PATCH v9] " Alejandro Colomar
2021-02-20 14:35   ` Michael Kerrisk (man-pages)
2021-02-20 21:45   ` Michael Kerrisk (man-pages)
2021-02-27 15:09   ` Stefan Puiu
2021-02-27 17:16     ` Alejandro Colomar (man-pages) [this message]
2021-03-01 10:19       ` Stefan Puiu
2021-03-01 14:16         ` Alejandro Colomar (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=072ee0c3-f30f-9da3-1b3f-37b5bc095806@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=stefan.puiu@gmail.com \
    --cc=wharms@bfs.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.