From c4e330cc69b45eef2450dd3b45dc2267d3e469fe Mon Sep 17 00:00:00 2001 From: merakor Date: Fri, 12 Mar 2021 10:46:26 +0000 Subject: tool2man.sh: Add script to generate manual pages for 'contrib' scripts FossilOrigin-Name: fd62ce6e6025574475ba55ce2c623e5b0fe5c4da90bafc6a2ddaa4a47a9cc951 --- tools/tool2man.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 tools/tool2man.sh diff --git a/tools/tool2man.sh b/tools/tool2man.sh new file mode 100755 index 0000000..82e4807 --- /dev/null +++ b/tools/tool2man.sh @@ -0,0 +1,52 @@ +#!/bin/sh -e +# Convert 'contrib' scripts to manual pages. + +# This script basically converts some of the comments inside scripts to manual +# page format. The intention behind this utility is to generate manual pages for +# contrib scripts without much hassle. + +case "$1" in + --help|-h|'') + printf 'usage: %s [file]\n' "${0##*/}" >&2 + exit 1 +esac + +out() { printf '%s\n' "$@"; } + +file=$1 +filename=${file##*/} +date=$(date "+%b %d, %Y") +docstr=$(sed -n '2s/# //p' $file) + +out \ + ".Dd $date" \ + ".Dt $filename 1" \ + ".Sh NAME" \ + ".Nm $filename" \ + ".Nd $docstr" + +while read -r line; do + case $line in + '###'*:) + line=${line%:} + out ".Ss ${line#'### '}" + ;; + '##'*:) + line=${line%:} + out ".Sh ${line#'## '}" + ;; + '##'|'###') + out ".Pp" + ;; + '##'*) + line=${line#'##'} + line=${line#'#'} + line=${line# } + out "$line" + ;; + esac +done < "$file" + +out ".Sh AUTHOR" ".An Cem Keylan Aq Mt cem@ckyln.com" +out ".Sh LICENSE" "See LICENSE for copyright information." +out ".Sh SEE ALSO" ".Xr cpt 1" -- cgit v1.2.3