asciiman: improve attribute handling
This commit is contained in:
		@@ -20,21 +20,17 @@ function fatal(message) {
 | 
				
			|||||||
	exit 1
 | 
						exit 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function haveattribute(name) {
 | 
					BEGIN {
 | 
				
			||||||
	return name in Attrs || ("asciidoc-" name) in ENVIRON
 | 
						for (name in ENVIRON)
 | 
				
			||||||
 | 
							if (match(name, /^asciidoc-/))
 | 
				
			||||||
 | 
								Attrs[substr(name, RSTART + RLENGTH)] = ENVIRON[name]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getattribute(name) {
 | 
					function expand(s,   attrname, v) {
 | 
				
			||||||
	if (!(name in Attrs) && ("asciidoc-" name) in ENVIRON)
 | 
						while (match(s, /[{][^{}]+[}]/)) {
 | 
				
			||||||
		Attrs[name] = ENVIRON["asciidoc-" name]
 | 
							attrname = substr(s, RSTART + 1, RLENGTH - 2)
 | 
				
			||||||
	return Attrs[name]
 | 
							if (attrname in Attrs)
 | 
				
			||||||
}
 | 
								v = v substr(s, 1, RSTART - 1) Attrs[attrname]
 | 
				
			||||||
 | 
					 | 
				
			||||||
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)
 | 
					 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			v = v substr(s, 1, RSTART + RLENGTH - 1)
 | 
								v = v substr(s, 1, RSTART + RLENGTH - 1)
 | 
				
			||||||
		s = substr(s, RSTART + RLENGTH)
 | 
							s = substr(s, RSTART + RLENGTH)
 | 
				
			||||||
@@ -49,13 +45,20 @@ function escape(s) {
 | 
				
			|||||||
	return s
 | 
						return s
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function readattribute(line,    attrname, attrvalue) {
 | 
					function readattribute(line,    attrname) {
 | 
				
			||||||
	if (match(line, /^:[^:]*: /)) {
 | 
						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)
 | 
							attrname = substr(line, RSTART + 1, RLENGTH - 3)
 | 
				
			||||||
		attrvalue = substr(line, RSTART + RLENGTH)
 | 
							Attrs[attrname] = expand(substr(line, RSTART + RLENGTH))
 | 
				
			||||||
		Attrs[attrname] = expand(attrvalue)
 | 
						} else {
 | 
				
			||||||
		return 1
 | 
							return 0
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
NR == 1 {
 | 
					NR == 1 {
 | 
				
			||||||
@@ -80,9 +83,9 @@ NR == 1 {
 | 
				
			|||||||
	# Requesting tbl(1), even though we currently do not support tables.
 | 
						# Requesting tbl(1), even though we currently do not support tables.
 | 
				
			||||||
	print "'\\\" t"
 | 
						print "'\\\" t"
 | 
				
			||||||
	printf ".TH \"%s\" \"%s\" \"\" \"%s\"",
 | 
						printf ".TH \"%s\" \"%s\" \"\" \"%s\"",
 | 
				
			||||||
		toupper(name), section, getattribute("mansource")
 | 
							toupper(name), section, Attrs["mansource"]
 | 
				
			||||||
	if (getattribute("manmanual"))
 | 
						if ("manmanual" in Attrs)
 | 
				
			||||||
		printf " \"%s\"", getattribute("manmanual")
 | 
							printf " \"%s\"", Attrs["manmanual"]
 | 
				
			||||||
	print ""
 | 
						print ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Hyphenation is indeed rather annoying, in particular with long links.
 | 
						# Hyphenation is indeed rather annoying, in particular with long links.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user