aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-25 20:55:51 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-25 20:55:51 +0200
commit34460ca715b295cc73c3f2bba4156c7f072ce122 (patch)
tree0f48082cd99ea6b08560960bd012596b9b092cfe
parent9883caf849fd28c2038f7af50e122276b7e2d330 (diff)
downloadliberty-34460ca715b295cc73c3f2bba4156c7f072ce122.tar.gz
liberty-34460ca715b295cc73c3f2bba4156c7f072ce122.tar.xz
liberty-34460ca715b295cc73c3f2bba4156c7f072ce122.zip
asciiman: improve command escaping
-rw-r--r--tools/asciiman.awk14
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/asciiman.awk b/tools/asciiman.awk
index da32db8..6db5695 100644
--- a/tools/asciiman.awk
+++ b/tools/asciiman.awk
@@ -32,7 +32,7 @@ function expand(s, attr) {
function escape(s) {
gsub(/\\/, "\\\\", s)
gsub(/-/, "\\-", s)
- gsub(/[.]/, "\\.", s)
+ sub(/^[.']/, "\\\\\\&&", s)
return s
}
@@ -80,9 +80,6 @@ function inline(line) {
line = escape(expand(line))
- # Enable double-spacing after the end of a sentence.
- gsub(/\\[.][[:space:]]+/, ".\n", s)
-
# Strip empty URL descriptions, otherwise useful for demarking the end.
while (match(line, /[^[:space:]]+\[\]/)) {
line = substr(line, 1, RSTART + RLENGTH - 3) \
@@ -118,6 +115,15 @@ function inline(line) {
substr(line, RSTART + RLENGTH)
}
+ # Enable double-spacing after the end of a sentence.
+ gsub(/[.][[:space:]]+/, ".\n", line)
+ gsub(/[!][[:space:]]+/, "!\n", line)
+ gsub(/[?][[:space:]]+/, "?\n", line)
+
+ # Quote commands resulting from that, as well as from expand().
+ gsub(/\n[.]/, "\n\\\\\\&.", line)
+ gsub(/\n[']/, "\n\\\\\\&'", line)
+
sub(/[[:space:]]+[+]$/, "\n.br", line)
print line
}