All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alejandro Colomar (man-pages)" <alx.manpages@gmail.com>
To: mtk.manpages@gmail.com
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH] scripts/bash_aliases: Add useful functions
Date: Mon, 15 Feb 2021 14:36:36 +0100	[thread overview]
Message-ID: <de484d8e-9a91-1fb4-f198-8cfee370dba1@gmail.com> (raw)
In-Reply-To: <20210215131522.450666-11-alx.manpages@gmail.com>

On 2/15/21 2:15 PM, Alejandro Colomar wrote:
> That file should be sourced (.) from 'bashrc' (or 'bash_aliases').
> 
> It contains functions that are useful for the maintenance of this
> project.
> 
> - grep_syscall()
> - grep_syscall_def()
> - man_section()
> - man_lsfunc()
> - pdfman()
> - grep_glibc_prototype()
> 
> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
> ---
>  scripts/bash_aliases | 172 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 172 insertions(+)
>  create mode 100644 scripts/bash_aliases
> 
> diff --git a/scripts/bash_aliases b/scripts/bash_aliases
> new file mode 100644
> index 000000000..4fcd66e62
> --- /dev/null
> +++ b/scripts/bash_aliases
> @@ -0,0 +1,172 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +########################################################################
> +#
> +# (C) Copyright 2021, Alejandro Colomar
> +# This program is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU General Public License
> +# as published by the Free Software Foundation; version 2.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details
> +# (http://www.gnu.org/licenses/gpl-2.0.html).
> +#
> +########################################################################
> +
> +########################################################################
> +#	Exit status
> +
> +EX_OK=0;
> +EX_USAGE=64;
> +
> +########################################################################
> +#	Linux kernel
> +
> +#  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]$' \
> +	|sort -V \
> +	|xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
> +	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
> +}
> +
> +#  grep_syscall_def()  finds the definition of a syscall in the kernel sources,
> +# printing the filename, line number, and the function definition.
> +# It should be run from the root of the linux kernel source tree.
> +# Usage example:  .../linux$ grep_syscall_def openat2;
> +
> +function grep_syscall_def()
> +{
> +	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/';
> +}
> +
> +########################################################################
> +#	Linux man-pages
> +
> +#  man_section()  prints a specific manual page section (DESCRIPTION, SYNOPSIS,
> +# ...) of all manual pages in a directory (or in a single manual page file).
> +# Usage example:  .../man-pages$ man_section man2 SYNOPSIS;
> +
> +function man_section()
> +{
> +	if ! [ -v 2 ]; then
> +		>&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>";
> +		return ${EX_USAGE};
> +	fi
> +
> +	find "${1}" -type f \
> +	|xargs grep -l "\.SH ${2}" \
> +	|sort -V \
> +	|while read -r manpage; do
> +		<${manpage} \
> +		sed -n \
> +			-e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
> +			-e "/^\.SH ${2}/p" \
> +			-e "/^\.SH ${2}/,/^\.SH/{/^\.SH/!p}" \
> +		|man -P cat -l - 2>/dev/null;
> +	done;
> +}
> +
> +#  man_lsfunc()  prints the name of all C functions declared in the SYNOPSIS
> +# of all manual pages in a directory (or in a single manual page file).
> +# Each name is printed in a separate line
> +# Usage example:  .../man-pages$ man_lsfunc man2;
> +
> +function man_lsfunc()
> +{
> +	if ! [ -v 1 ]; then
> +		>&2 echo "Usage: ${FUNCNAME[0]} <dir>";
> +		return ${EX_USAGE};
> +	fi
> +
> +	find "${1}" -type f \
> +	|xargs grep -l "\.SH SYNOPSIS" \
> +	|sort -V \
> +	|while read -r manpage; do
> +		<${manpage} \
> +		sed -n \
> +			-e '/^\.TH/,/^\.SH/{/^\.SH/!p}' \
> +			-e "/^\.SH SYNOPSIS/p" \
> +			-e "/^\.SH SYNOPSIS/,/^\.SH/{/^\.SH/!p}" \
> +		|sed \
> +			-e '/Feature/,$d' \
> +			-e '/{/,/}/d' \
> +		|man -P cat -l - 2>/dev/null;
> +	done \
> +	|sed -n "/^SYNOPSIS/,/^\w/p" \
> +	|grep '^       \w' \
> +	|grep -v ':' \
> +	|sed 's/^[^(]* \**\(\w*\)(.*/\1/' \
> +	|grep '^\w' \
> +	|uniq;
> +}
> +
> +#  pdfman()  reanders a manual page in PDF
> +# Usage example:  .../man-pages$ pdfman man2/membarrier.2

Hi Michael,

Please, add a ';' there for consistency.

Thanks,

Alex

> +
> +function pdfman()
> +{
> +	if ! [ -v 1 ]; then
> +		>&2 echo "Usage: ${FUNCNAME[0]} <man-page.n>";
> +		return ${EX_USAGE};
> +	fi;
> +
> +	local tmp="$(mktemp -t "${1##*/}.XXXXXX")";
> +
> +	<${1} \
> +	man -Tps -l - \
> +	|ps2pdf - - \
> +	>${tmp};
> +	xdg-open ${tmp};
> +}
> +
> +########################################################################
> +#	Glibc
> +
> +#  grep_glibc_prototype()  finds a function prototype in the glibc sources,
> +# printing the filename, line number, and the prototype.
> +# It should be run from the root of the glibc source tree.
> +# Usage example:  .../glibc$ grep_glibc_prototype printf;
> +
> +function grep_glibc_prototype()
> +{
> +	if ! [ -v 1 ]; then
> +		>&2 echo "Usage: ${FUNCNAME[0]} <func>";
> +		return ${EX_USAGE};
> +	fi
> +
> +	find * -type f \
> +	|grep '\.h$' \
> +	|sort -V \
> +	|xargs pcregrep -Mn \
> +	  "(?s)^[^\s#][\w\s]+\s+\**${1}\s*\([\w\s()[\]*,]*?(...)?\)[\w\s()]*;" \
> +	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
> +}
> +
> 


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

  reply	other threads:[~2021-02-15 13:50 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) [this message]
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)
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=de484d8e-9a91-1fb4-f198-8cfee370dba1@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /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.