makedeb


ivy-calc 0.2.10-2


An APL-like calculator.

Viewing /genmanpage.sh.

View raw.

Click here to go back to the Git tree for ivy-calc.

#!/bin/sh
# Generates `ivyc.1` man page using man macros with `go doc` output.
#
# This script is called in `doc.go` using `go generate` to generate a man page
# formatted with man macros from the documentation. A few additional sections
# such as `NAME` and `SYNOPSIS` are added to comply with man page conventions.
#
# Conversion logic implemented here from godoc output to man macros should not
# be considered compliant, as such it has inexact assumptions such as the use
# of spaces over tabs along with various corner cases that are not handled
# properly like character escaping. The intention here is to come up with
# something that can convert the current content in the documentation. For this
# reason, it is recommended to check the output after generation especially
# when the documentation is changed in a significant way.
#
# This script heavily inspired by the one in "https://github.com/gokcehan/lf"
# under an MIT Licence.
# Copyright (c) 2022 Chris Howey
# Copyright (c) 2016 Gökçehan Kara

out=ivyc.1

echo '.\" Code generated by man.sh DO NOT EDIT.' > $out

cat << END >> $out
.TH IVYC 1
.SH NAME
ivyc \- interpreter for an APL-like language.
.SH SYNOPSIS
.SY ivyc
END
./ivyc -h 2>&1 | grep "  -" | sed 's/^  -/.OP -/' | sed 's/-g\t.*/-g/g' >> $out

cat << END >> $out
.YS
.SH DESCRIPTION
END

go doc | awk '
BEGIN {
    RS = ""
    start = 1
}

# preformatted
/^ / {
    gsub("\\\\", "\\e", $0)
    print ".PP"
    print ".EX"
    print $0
    print ".EE"
    next
}

# heading
/^[^[:punct:]]*$/ {
    print ".SH", toupper($0)
    start = 1
    next
}

# paragraph
{
    gsub("\n", " ", $0)
    gsub("\\\\", "\\e", $0)
    if (start) { start = 0 } else { print ".PP" }
    print $0
}
' >> $out

cat << END >> $out
.SH OPTIONS
END
./ivyc -h 2>&1 | tail -n +3 | sed -E 's/-g\t(.*)/-g\n        \1/' | sed -E 's/-/\\-/g' | \
	sed -E 's/^  \\-(.*)[ \t](.*)$/.HP\n\\fB\\-\1\\fR \\fI\2\\fP/' | \
	sed -E 's/^  \\-(.*)$/.HP\n\\fB\\-\1\\fR/' | \
	sed -E 's/[ \t]{4,}/.IP\n/' >> $out

cat << END >> $out
.SH AUTHOR
.LP
Rob Pike
END