#!/bin/sh # # Generates mh-chart.man from other .man files that have a SYNOPSIS # section. # # This code is Copyright (c) 2012, by the authors of nmh. # See the COPYRIGHT file in the root directory of the nmh # distribution for complete copyright information. nmhmandir=`dirname $0` # The following ensures the generated date field in the manpage is divorced # from the local build environment when building distribution packages. LC_TIME=C; export LC_TIME unset LANG datestamp=`date +%Y-%m-%d` cat <<__HOOPY_FROOD .TH MH-CHART %manext7% "${datestamp}" "%nmhversion%" . .\" %nmhwarning% . .SH NAME mh-chart \- chart of nmh commands and their options .SH SYNOPSIS .na __HOOPY_FROOD for i in $nmhmandir/*.man; do case $i in */mh-chart.man) ;; *) if grep '^\.SH SYNOPSIS' "$i" >/dev/null; then #### Extract lines from just after .SH SYNOPSIS to just before .ad. #### Filter out the "typical usage:" section in pick.man. awk '/.SH SYNOPSIS/,/^(\.ad|typical usage:)/ { if ($0 !~ /^(\.SH SYNOPSIS|\.na|\.ad|typical usage:)/) print }' "$i" echo elif sed 1p $i | grep '^\.so man' >/dev/null then : skip one-line pages that just include others else # pages without SYNOPSIS are section 5 and 7 see_also="$see_also $i" fi ;; esac done echo '.SH "SEE ALSO"' for i in $see_also do # extract the section number from the first (.TH) line section=`sed -n '1s/.*manext\([1-7]\).*/\1/p' $i` # get the name and description. name_desc=`grep -A1 '^\.SH NAME' "$i" | grep -v '^\.SH NAME'` # isolate the name(s) (note: some pages (mh_tailor/mts.conf) have # two names, so everything up to the \- is name(s) name=`echo $name_desc | sed -n 's/\(.*\) \\\\-.*/\1/p'` # escape spaces and hyphens, since this will come after .IR name=`echo $name | sed 's/[- ]/\\\\&/g'` # everything after the \- is description desc=`echo $name_desc | sed -n 's/.*\\\\- \(.*\)/\1/p'` # sort first by section, then by name echo "$section.IR $name ($section)XYZZY$desc" done | sort | sed -e 's/^[1-7]//' -e 's/XYZZY\(.*\)/\ .RS\ \1\ .RE/'