From 4d44e2f8b58c3e4a34c44fad933945b33d7e1001 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 27 Dec 2018 03:39:24 -0500 Subject: tools/shman.sh: Implement SYNOPSIS --- diff --git a/tools/shman.sh b/tools/shman.sh index 953965a..57fc974 100755 --- a/tools/shman.sh +++ b/tools/shman.sh @@ -70,10 +70,12 @@ gen_doc_func() { local sym="${1}" local doc="${2}" - shift 2 + local shso="${3}" + shift 3 local cmd= local args= local sect_name= + local sect_syn= local sect_desc= local opt= local optarg= @@ -91,9 +93,12 @@ gen_doc_func() local pure= local sect_attr= - # TODO: SYNOPSIS - sect_name=".SH NAME${LF}${sym}" + sect_syn=".SH SYNOPSIS${LF}" + if [ -n "${shso}" ]; then + sect_syn="${sect_syn}.B . ${shso}${LF}.P${LF}" + fi + sect_syn="${sect_syn}.B ${sym}${LF}" while read -r cmd args; do case "${cmd}" in 'brief') @@ -111,12 +116,13 @@ gen_doc_func() fi first_opt=false if [ "x${optarg}" = 'x-' ]; then - opt=".B ${opt}" + opt="\\fB${opt}\\fP" else - opt=".BI ${opt} \\ ${optarg}" + opt="\\fB${opt}\\fP \\fI${optarg}\\fP" fi sect_opts="${sect_opts}.TP${LF}${opt}${LF}" sect_opts="${sect_opts}${desc}${LF}" + sect_syn="${sect_syn}[${opt}]${LF}" ;; 'operand') read -r opd req desc <<-EOF @@ -128,6 +134,13 @@ gen_doc_func() first_opd=false sect_opds="${sect_opds}.TP${LF}.I ${opd}${LF}" sect_opds="${sect_opds}${desc}${LF}" + case "${req}" in + 'r'*|'R'*|'y'*|'Y'*) + opd="\\fI${opd}\\fP";; + *) + opd="[\\fI${opd}\\fP]";; + esac + sect_syn="${sect_syn}${opd}${LF}" ;; 'stdin') sect_in=".SH STDIN${LF}${args}" @@ -155,7 +168,7 @@ gen_doc_func() ${doc} EOF - printf '%s\n\n' "${sect_name}" "${sect_desc}" \ + printf '%s\n\n' "${sect_name}" "${sect_syn}" "${sect_desc}" \ "${sect_opts}" "${sect_opds}" "${sect_in}" "${sect_ret}" \ "${sect_out}" "${sect_err}" "${sect_attr}" } @@ -165,11 +178,12 @@ gen_doc() local date="${1}" local source="${2}" local manual="${3}" - local sym="${4}" - local is_func="${5}" - local doc="${6}" - local out_dir="${7}" - shift 7 + local shso="${4}" + local sym="${5}" + local is_func="${6}" + local doc="${7}" + local out_dir="${8}" + shift 8 local line= local doc_joined='' local sym_upper= @@ -196,7 +210,7 @@ gen_doc() if ${is_func}; then printf '.TH %s 3 "%s" "%s" "%s"\n\n' \ "${sym_upper}" "${date}" "${source}" "${manual}" - gen_doc_func "${sym}" "${doc}" + gen_doc_func "${sym}" "${doc}" "${shso}" fi } >"${out_dir}/${sym}.3" } @@ -206,8 +220,9 @@ parse_docs() local file="${1}" local source="${2}" local manual="${3}" - local out_dir="${4}" - shift 4 + local shso="${4}" + local out_dir="${5}" + shift 5 local date= local line= local doc='' @@ -236,7 +251,7 @@ parse_docs() esac case "${line}" in [!a-zA-Z]*|*[!a-zA-Z0-9_]*) continue;; esac if ${got_doc}; then - gen_doc "${date}" "${source}" "${manual}" \ + gen_doc "${date}" "${source}" "${manual}" "${shso}" \ "${line}" ${is_func} "${doc}" "${out_dir}" if [ -n "${tags}" ]; then if ${is_func}; then @@ -290,11 +305,12 @@ main() local opt= local source='Shell' local manual='Shell Functions' + local shso='' local out_dir='.' local tags='' local f= - while getopts 'hVs:m:d:t:' opt; do + while getopts 'hVs:m:S:d:t:' opt; do case "${opt}" in 'h') help @@ -310,6 +326,9 @@ main() 'm') manual="${OPTARG}" ;; + 'S') + shso="${OPTARG}" + ;; 'd') out_dir="${OPTARG}" ;; @@ -329,7 +348,7 @@ main() exec 3>"${tags}" fi for f in "${@}"; do - parse_docs "${f}" "${source}" "${manual}" "${out_dir}" + parse_docs "${f}" "${source}" "${manual}" "${shso}" "${out_dir}" done if [ -n "${tags}" ]; then exec 3>&- -- cgit v0.9.1