From 0f3ed1457571ff8c42fc99e77ea18854afa877b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Fri, 30 Sep 2022 18:13:01 +0200 Subject: asciiman: support attribute passing --- tools/asciiman.awk | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/asciiman.awk b/tools/asciiman.awk index ddb1093..c2dbe5f 100644 --- a/tools/asciiman.awk +++ b/tools/asciiman.awk @@ -6,13 +6,13 @@ # This is not intended to produce great output, merely useful output. # As such, input documents should restrict themselves as follows: # -# - Attributes cannot be passed on the command line. # - In-line formatting sequences must not overlap, # cannot be escaped, and cannot span lines. # - Heading underlines must match in byte length exactly. # - Only a small subset of syntax is supported overall. # # Also beware that the output has only been tested with GNU troff. +# Attributes can be passed via environment variables starting with "asciidoc-". function fatal(message) { print ".\\\" " FILENAME ":" FNR ": fatal error: " message @@ -20,11 +20,18 @@ function fatal(message) { exit 1 } -function expand(s, attr) { +function getattribute(name) { + if (!(name in Attrs) && ("asciidoc-" name) in ENVIRON) + Attrs[name] = ENVIRON["asciidoc-" name] + return Attrs[name] +} + +function expand(s, attr, v) { # TODO: This should not expand unknown attribute names. while (match(s, /[{][^{}]*[}]/)) { - attr = substr(s, RSTART + 1, RLENGTH - 2) - s = substr(s, 1, RSTART - 1) Attrs[attr] substr(s, RSTART + RLENGTH) + s = substr(s, 1, RSTART - 1) \ + getattribute(substr(s, RSTART + 1, RLENGTH - 2)) \ + substr(s, RSTART + RLENGTH) } return s } @@ -66,7 +73,11 @@ NR == 1 { # Requesting tbl(1), even though we currently do not support tables. print "'\\\" t" - print ".TH \"" toupper(name) "\" \"" section "\"" + printf ".TH \"%s\" \"%s\" \"\" \"%s\"", + toupper(name), section, getattribute("mansource") + if (getattribute("manmanual")) + printf " \"%s\"", getattribute("manmanual") + print "" # Hyphenation is indeed rather annoying, in particular with long links. print ".nh" -- cgit v1.2.3