aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-10-09 18:43:37 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-10-09 18:43:37 +0200
commit29bf109a51951e9c6d94bd2fedffb405bead849c (patch)
treeb8b7a3ed5bea6957cbaa74e45d970ef55c1dfa66 /tools
parent0e86ffe7c30a4d52eea35856b792567ca1040f56 (diff)
downloadliberty-29bf109a51951e9c6d94bd2fedffb405bead849c.tar.gz
liberty-29bf109a51951e9c6d94bd2fedffb405bead849c.tar.xz
liberty-29bf109a51951e9c6d94bd2fedffb405bead849c.zip
asciiman: improve attribute handling
Diffstat (limited to 'tools')
-rw-r--r--tools/asciiman.awk45
1 files changed, 24 insertions, 21 deletions
diff --git a/tools/asciiman.awk b/tools/asciiman.awk
index b46c7a0..4b5ee54 100644
--- a/tools/asciiman.awk
+++ b/tools/asciiman.awk
@@ -20,21 +20,17 @@ function fatal(message) {
exit 1
}
-function haveattribute(name) {
- return name in Attrs || ("asciidoc-" name) in ENVIRON
+BEGIN {
+ for (name in ENVIRON)
+ if (match(name, /^asciidoc-/))
+ Attrs[substr(name, RSTART + RLENGTH)] = ENVIRON[name]
}
-function getattribute(name) {
- if (!(name in Attrs) && ("asciidoc-" name) in ENVIRON)
- Attrs[name] = ENVIRON["asciidoc-" name]
- return Attrs[name]
-}
-
-function expand(s, attr, v) {
- while (match(s, /[{][^{}]*[}]/)) {
- attr = substr(s, RSTART + 1, RLENGTH - 2)
- if (haveattribute(attr))
- v = v substr(s, 1, RSTART - 1) getattribute(attr)
+function expand(s, attrname, v) {
+ while (match(s, /[{][^{}]+[}]/)) {
+ attrname = substr(s, RSTART + 1, RLENGTH - 2)
+ if (attrname in Attrs)
+ v = v substr(s, 1, RSTART - 1) Attrs[attrname]
else
v = v substr(s, 1, RSTART + RLENGTH - 1)
s = substr(s, RSTART + RLENGTH)
@@ -49,13 +45,20 @@ function escape(s) {
return s
}
-function readattribute(line, attrname, attrvalue) {
- if (match(line, /^:[^:]*: /)) {
+function readattribute(line, attrname) {
+ if (match(line, /^:[^:]+:$/)) {
+ Attrs[substr(line, RSTART + 1, RLENGTH - 2)] = ""
+ } else if (match(line, /^:[^:]+!:$/)) {
+ delete Attrs[substr(line, RSTART + 1, RLENGTH - 3)]
+ } else if (match(line, /^:![^:]+:$/)) {
+ delete Attrs[substr(line, RSTART + 2, RLENGTH - 3)]
+ } else if (match(line, /^:[^:]+: /)) {
attrname = substr(line, RSTART + 1, RLENGTH - 3)
- attrvalue = substr(line, RSTART + RLENGTH)
- Attrs[attrname] = expand(attrvalue)
- return 1
+ Attrs[attrname] = expand(substr(line, RSTART + RLENGTH))
+ } else {
+ return 0
}
+ return 1
}
NR == 1 {
@@ -80,9 +83,9 @@ NR == 1 {
# Requesting tbl(1), even though we currently do not support tables.
print "'\\\" t"
printf ".TH \"%s\" \"%s\" \"\" \"%s\"",
- toupper(name), section, getattribute("mansource")
- if (getattribute("manmanual"))
- printf " \"%s\"", getattribute("manmanual")
+ toupper(name), section, Attrs["mansource"]
+ if ("manmanual" in Attrs)
+ printf " \"%s\"", Attrs["manmanual"]
print ""
# Hyphenation is indeed rather annoying, in particular with long links.