1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# Copyright, the authors of the Linux man-pages project
# SPDX-License-Identifier: GPL-2.0-only
########################################################################
# Exit status
EX_USAGE=64;
########################################################################
# C
# sed_rm_ccomments() removes C comments.
# It can't handle mixed //... and /*...*/ comments.
# Use as a filter (see man_lsfunc() in this file).
sed_rm_ccomments()
{
perl -p -e 's%/\*.*?\*/%%g' \
|sed -E '\%/\*%, \%\*/% {\%(\*/|/\*)%!d}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed 's%//.*%%';
}
########################################################################
# Linux man-pages
# 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;
man_lsfunc()
{
if [ $# -lt 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
return $EX_USAGE;
fi
mansect 'SYNOPSIS' "$@" \
|mandoc -Tutf8 2>/dev/null \
|col -pbx \
|sed_rm_ccomments \
|pcre2grep -Mn '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]*?(...)?\s*\); *$' \
|grep '^[0-9]' \
|sed -E 's/syscall\(SYS_(\w*),?/\1(/' \
|sed -E 's/^[^(]+ \**(\w+)\(.*/\1/' \
|uniq;
}
# man_lsvar() prints the name of all C variables 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_lsvar man3;
man_lsvar()
{
if [ $# -lt 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
return $EX_USAGE;
fi
mansect 'SYNOPSIS' "$@" \
|mandoc -Tutf8 2>/dev/null \
|col -pbx \
|sed_rm_ccomments \
|pcre2grep -Mv '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]+?(...)?\s*\); *$' \
|pcre2grep -Mn \
-e '(?s)^ +extern [\w ]+ \**\(\*+[\w ]+\)\([\w\s(,)[\]*]+?\s*\); *$' \
-e '^ +extern [\w ]+ \**[\w ]+; *$' \
|grep '^[0-9]' \
|grep -v 'typedef' \
|sed -E 's/^[0-9]+: +extern [^(]+ \**\(\*+(\w* )?(\w+)\)\(.*/\2/' \
|sed 's/^[0-9]\+: \+extern .* \**\(\w\+\); */\1/' \
|uniq;
}
# Print a list of all files with changes staged for commit
# (basename only if the files are within <man/>), separated by ", ".
# Usage example: .../man-pages$ git commit -m "$(man_gitstaged): msg";
man_gitstaged()
{
git diff --staged --name-only \
|sed 's/$/, /' \
|sed '/^man\//s%.*/%%' \
|tr -d '\n' \
|sed 's/, $//';
}
|