aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-03-12 10:46:26 +0000
committermerakor <cem@ckyln.com>2021-03-12 10:46:26 +0000
commitc4e330cc69b45eef2450dd3b45dc2267d3e469fe (patch)
treebaa4bc9fbc673b2eaa1bf3c3824f96ba6e056f2f
parent5055ae35c777fe7c3e0126ddb180797d0e815a2f (diff)
downloadcpt-c4e330cc69b45eef2450dd3b45dc2267d3e469fe.tar.gz
tool2man.sh: Add script to generate manual pages for 'contrib' scripts
FossilOrigin-Name: fd62ce6e6025574475ba55ce2c623e5b0fe5c4da90bafc6a2ddaa4a47a9cc951
-rwxr-xr-xtools/tool2man.sh52
1 files changed, 52 insertions, 0 deletions
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"