From d165d39c08ebc8be6ef3662022196758ef580f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 30 Jan 2021 13:22:38 +0000 Subject: Move aux files to root directory --- aux/emcollect | 18 ----- aux/emparse | 218 ---------------------------------------------------------- em | 4 +- emcollect | 18 +++++ emparse | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mkfile | 4 +- 6 files changed, 240 insertions(+), 240 deletions(-) delete mode 100755 aux/emcollect delete mode 100755 aux/emparse create mode 100755 emcollect create mode 100755 emparse diff --git a/aux/emcollect b/aux/emcollect deleted file mode 100755 index 55434ac..0000000 --- a/aux/emcollect +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/awk -f - -# aux/emcollect -- collect hyperlink references in em source - -function collect(line) { - left = $0 - right = $0 - sub("^ \\[", "", left) - sub("\\].*$", "", left) - sub("^ \\[[0-9a-z]\\]+ ", "", right) - printf "%s=%s\n", left, right -} - -BEGIN { expectblock = 1 } - -/^$/ { expectblock = 1; getline } -expectblock && /^ \[[0-9a-z]\]+ / { block = "nl"; expectblock = 0 } -block = "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { collect($0); next } diff --git a/aux/emparse b/aux/emparse deleted file mode 100755 index 5fb9397..0000000 --- a/aux/emparse +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/awk -f - -# aux/emparse -- parse em source - -BEGIN { - expectblock = 1 - itemlevel = 1 - linktext = ENVIRON["linktext"] - if (!linktext) linktext = "link" -} -END { breakblock() } - -/^$/ { breakblock(); getline } -expectblock && /^ / { newblock("table") } -expectblock && /^ - / { newblock("ul") } -expectblock && /^ [0-9a-z]+\. / { newblock("ol") } -expectblock && /^ \[[0-9a-z]\]+ / { newblock("nl") } -expectblock && /^ .*: / { newblock("dl") } -expectblock && /^ / { newblock("pre") } -expectblock && /^---$/ { expectblock = 0; printf "
\n"; next } -expectblock && /^= .* =$/ { heading(1, $0); next } -expectblock && /^== .* ==$/ { heading(2, $0); next } -expectblock && /^=== .* ===$/ { heading(3, $0); next } -expectblock && /^==== .* ====$/ { heading(4, $0); next } -expectblock && /^===== .* =====$/ { heading(5, $0); next } -expectblock && /^====== .* ======$/ { heading(6, $0); next } -expectblock { newblock("p") } - -openblock == "pre" { sub("^ ", ""); escape(); printf "%s\n", $0; next } - -openblock == "ul" && /^ - / { item(1, "ul", line) } -openblock == "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) } -openblock == "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { next } # hyperlink reference -openblock == "nl" && /^ \[[0-9a-z]\]+ / { item(1, "nl", line) } # text reference -openblock == "dl" && /^ .*: / { term(line) } - -(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) } -(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(2, "ol", line) } -(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) } -(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(3, "ol", line) } -(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) } -(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(4, "ol", line) } -(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) } -(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(5, "ol", line) } -(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) } -(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(6, "ol", line) } - -{ format($0) } # inline formatting - -function format(line) { - escape(line) - n = split(line, w, "[ ]") - for (i = 0; i <= n; i++) { - if (w[i] == "") continue; - - if (match(w[i], "^\\[[0-9a-z]+\\]$")) - w[i] = ref(substr(w[i], 2, RLENGTH-2)) - else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$")) - w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH) - else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$")) - w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1) - - if (!openformat) { - if (match(w[i], "^`")) { - w[i] = "" substr(w[i], 2) - openformat = "tt" - } else if (match(w[i], "^\\*")) { - w[i] = "" substr(w[i], 2) - openformat = "i" - } else if (match(w[i], "^_")) { - w[i] = "" substr(w[i], 2) - openformat = "b" - } else if (match(w[i], "^\\(`")) { - w[i] = "(" substr(w[i], 3) - openformat = "tt" - } else if (match(w[i], "^\\(\\*")) { - w[i] = "(" substr(w[i], 3) - openformat = "i" - } else if (match(w[i], "^\\(_")) { - w[i] = "(" substr(w[i], 3) - openformat = "b" - } - } - - if (openformat) { - orig = w[i] - if (match(w[i], "`$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "\\*$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "_$")) - w[i] = substr(w[i], 1, RSTART-1) "" - else if (match(w[i], "`[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_[.,:;?!)]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "`\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "\\*\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - else if (match(w[i], "_\\)[.,:;?!]$")) - w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) - if (w[i] != orig) openformat = "" - } - - printf "%s", w[i] - if (i < n) printf " " - } - printf "\n" -} - -function opentag(name) { - if (name == "nl") printf "
    \n" - else printf "<%s>\n", name -} - -function closetag(name) { - if (name == "nl") printf "
\n" - else printf "\n", name -} - -function newblock(name) { - opentag(name) - openblock = name - expectblock = 0 -} - -function breakblock() { - if (openformat) { - printf "", openformat - printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" - } - if (openitem) { - printf "\n" - while (itemlevel-- > 1) - closetag(openblock) - itemlevel = 1 - } - if (opendef) printf "\n" - if (openblock) closetag(openblock) - openitem = 0 - opendef = 0 - openblock = 0 - openformat = "" - itemlevel = 1 - delete leveltype - expectblock = 1 -} - -function heading(level, line) { - sub("^=* ", "", line) - sub(" =*$", "", line) - escape(line) - printf "%s\n", level, line, level - # should inline formatting be supported in headings? -} - -function item(level, type, line) { - if (openitem) printf "" - openitem = 1 - if (type != "nl") { - for (; itemlevel < level; itemlevel++) { - printf "<%s>\n", type - leveltype[itemlevel+1] = type - } - for (; itemlevel > level; itemlevel--) { - printf "\n", leveltype[itemlevel] - leveltype[itemlevel] = "" - } - } - if (type == "ul") { - sub("^ +- ", "") - printf "
  • " - } - if (type == "ol") { - match($0, "[0-9a-z]+\.") - v = substr($0, RSTART, RLENGTH-1) - sub("^ +[0-9a-z]+\. ", "") - printf "
  • ", v - } - if (type == "nl") { - match($0, "\\[[0-9a-z]+\\]") - v = substr($0, RSTART+1, RLENGTH-2) - sub("^ +\\[[0-9a-z]+\\] ", "") - printf "
  • ", v, v - } -} - -function term(line, t) { # t is a local variable - if (opendef) printf "" - opendef = 1 - t = $0 - sub("^ ", "", t) - sub(": .*$", "", t) - sub("^ [^:]+: ", "") - escape(t) - printf "
    %s
    ", t -} - -function ref(v) { - if (ENVIRON["ref" v] != "") - return "(" linktext ")" - return "[" v "]" -} - -function escape(s) { - if (s == "") { - gsub("&", "\\&") - gsub("<", "\\<") - gsub(">", "\\>") - } else { - gsub("&", "\\&", s) - gsub("<", "\\<", s) - gsub(">", "\\>", s) - } -} diff --git a/em b/em index f2118a3..62d6d26 100755 --- a/em +++ b/em @@ -12,11 +12,11 @@ if not if(~ $#linktext 0) linktext=link hrefs=`' -'{aux/emcollect $file} +'{emcollect $file} for(href in $hrefs){ parts=`'= '{echo $href} ref$parts(1)=$parts(2) } -aux/emparse $file +emparse $file diff --git a/emcollect b/emcollect new file mode 100755 index 0000000..55434ac --- /dev/null +++ b/emcollect @@ -0,0 +1,18 @@ +#!/bin/awk -f + +# aux/emcollect -- collect hyperlink references in em source + +function collect(line) { + left = $0 + right = $0 + sub("^ \\[", "", left) + sub("\\].*$", "", left) + sub("^ \\[[0-9a-z]\\]+ ", "", right) + printf "%s=%s\n", left, right +} + +BEGIN { expectblock = 1 } + +/^$/ { expectblock = 1; getline } +expectblock && /^ \[[0-9a-z]\]+ / { block = "nl"; expectblock = 0 } +block = "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { collect($0); next } diff --git a/emparse b/emparse new file mode 100755 index 0000000..5fb9397 --- /dev/null +++ b/emparse @@ -0,0 +1,218 @@ +#!/bin/awk -f + +# aux/emparse -- parse em source + +BEGIN { + expectblock = 1 + itemlevel = 1 + linktext = ENVIRON["linktext"] + if (!linktext) linktext = "link" +} +END { breakblock() } + +/^$/ { breakblock(); getline } +expectblock && /^ / { newblock("table") } +expectblock && /^ - / { newblock("ul") } +expectblock && /^ [0-9a-z]+\. / { newblock("ol") } +expectblock && /^ \[[0-9a-z]\]+ / { newblock("nl") } +expectblock && /^ .*: / { newblock("dl") } +expectblock && /^ / { newblock("pre") } +expectblock && /^---$/ { expectblock = 0; printf "
    \n"; next } +expectblock && /^= .* =$/ { heading(1, $0); next } +expectblock && /^== .* ==$/ { heading(2, $0); next } +expectblock && /^=== .* ===$/ { heading(3, $0); next } +expectblock && /^==== .* ====$/ { heading(4, $0); next } +expectblock && /^===== .* =====$/ { heading(5, $0); next } +expectblock && /^====== .* ======$/ { heading(6, $0); next } +expectblock { newblock("p") } + +openblock == "pre" { sub("^ ", ""); escape(); printf "%s\n", $0; next } + +openblock == "ul" && /^ - / { item(1, "ul", line) } +openblock == "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) } +openblock == "nl" && /^ \[[0-9a-z]\]+ [^ ]+$/ { next } # hyperlink reference +openblock == "nl" && /^ \[[0-9a-z]\]+ / { item(1, "nl", line) } # text reference +openblock == "dl" && /^ .*: / { term(line) } + +(openblock == "ul" || openblock == "ol") && /^ -/ { item(2, "ul", line) } +(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(2, "ol", line) } +(openblock == "ul" || openblock == "ol") && /^ -/ { item(3, "ul", line) } +(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(3, "ol", line) } +(openblock == "ul" || openblock == "ol") && /^ -/ { item(4, "ul", line) } +(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(4, "ol", line) } +(openblock == "ul" || openblock == "ol") && /^ -/ { item(5, "ul", line) } +(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(5, "ol", line) } +(openblock == "ul" || openblock == "ol") && /^ -/ { item(6, "ul", line) } +(openblock == "ul" || openblock == "ol") && /^ [0-9a-z]+\./ { item(6, "ol", line) } + +{ format($0) } # inline formatting + +function format(line) { + escape(line) + n = split(line, w, "[ ]") + for (i = 0; i <= n; i++) { + if (w[i] == "") continue; + + if (match(w[i], "^\\[[0-9a-z]+\\]$")) + w[i] = ref(substr(w[i], 2, RLENGTH-2)) + else if (match(w[i], "^\\[[0-9a-z]+\\][.,:;?!)]$")) + w[i] = ref(substr(w[i], 2, RLENGTH-3)) substr(w[i], RLENGTH) + else if (match(w[i], "^\\[[0-9a-z]+\\]\\)[.,:;?!]$")) + w[i] = ref(substr(w[i], 2, RLENGTH-4)) substr(w[i], RLENGTH-1) + + if (!openformat) { + if (match(w[i], "^`")) { + w[i] = "" substr(w[i], 2) + openformat = "tt" + } else if (match(w[i], "^\\*")) { + w[i] = "" substr(w[i], 2) + openformat = "i" + } else if (match(w[i], "^_")) { + w[i] = "" substr(w[i], 2) + openformat = "b" + } else if (match(w[i], "^\\(`")) { + w[i] = "(" substr(w[i], 3) + openformat = "tt" + } else if (match(w[i], "^\\(\\*")) { + w[i] = "(" substr(w[i], 3) + openformat = "i" + } else if (match(w[i], "^\\(_")) { + w[i] = "(" substr(w[i], 3) + openformat = "b" + } + } + + if (openformat) { + orig = w[i] + if (match(w[i], "`$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "\\*$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "_$")) + w[i] = substr(w[i], 1, RSTART-1) "" + else if (match(w[i], "`[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_[.,:;?!)]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "`\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "\\*\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + else if (match(w[i], "_\\)[.,:;?!]$")) + w[i] = substr(w[i], 1, RSTART-1) "" substr(w[i], RSTART+1) + if (w[i] != orig) openformat = "" + } + + printf "%s", w[i] + if (i < n) printf " " + } + printf "\n" +} + +function opentag(name) { + if (name == "nl") printf "
      \n" + else printf "<%s>\n", name +} + +function closetag(name) { + if (name == "nl") printf "
    \n" + else printf "\n", name +} + +function newblock(name) { + opentag(name) + openblock = name + expectblock = 0 +} + +function breakblock() { + if (openformat) { + printf "", openformat + printf "(%s:%d) warning: open <%s> closed at block break\n", ARGV[1], NR, openformat > "/dev/stderr" + } + if (openitem) { + printf "
  • \n" + while (itemlevel-- > 1) + closetag(openblock) + itemlevel = 1 + } + if (opendef) printf "\n" + if (openblock) closetag(openblock) + openitem = 0 + opendef = 0 + openblock = 0 + openformat = "" + itemlevel = 1 + delete leveltype + expectblock = 1 +} + +function heading(level, line) { + sub("^=* ", "", line) + sub(" =*$", "", line) + escape(line) + printf "%s\n", level, line, level + # should inline formatting be supported in headings? +} + +function item(level, type, line) { + if (openitem) printf "" + openitem = 1 + if (type != "nl") { + for (; itemlevel < level; itemlevel++) { + printf "<%s>\n", type + leveltype[itemlevel+1] = type + } + for (; itemlevel > level; itemlevel--) { + printf "\n", leveltype[itemlevel] + leveltype[itemlevel] = "" + } + } + if (type == "ul") { + sub("^ +- ", "") + printf "
  • " + } + if (type == "ol") { + match($0, "[0-9a-z]+\.") + v = substr($0, RSTART, RLENGTH-1) + sub("^ +[0-9a-z]+\. ", "") + printf "
  • ", v + } + if (type == "nl") { + match($0, "\\[[0-9a-z]+\\]") + v = substr($0, RSTART+1, RLENGTH-2) + sub("^ +\\[[0-9a-z]+\\] ", "") + printf "
  • ", v, v + } +} + +function term(line, t) { # t is a local variable + if (opendef) printf "" + opendef = 1 + t = $0 + sub("^ ", "", t) + sub(": .*$", "", t) + sub("^ [^:]+: ", "") + escape(t) + printf "
    %s
    ", t +} + +function ref(v) { + if (ENVIRON["ref" v] != "") + return "(" linktext ")" + return "[" v "]" +} + +function escape(s) { + if (s == "") { + gsub("&", "\\&") + gsub("<", "\\<") + gsub(">", "\\>") + } else { + gsub("&", "\\&", s) + gsub("<", "\\<", s) + gsub(">", "\\>", s) + } +} diff --git a/mkfile b/mkfile index 63a45ce..117228b 100644 --- a/mkfile +++ b/mkfile @@ -6,5 +6,5 @@ README.html: README install: cp em /rc/bin/em - cp aux/emcollect /rc/bin/aux/emcollect - cp aux/emparse /rc/bin/aux/emparse + cp emcollect /rc/bin/emcollect + cp emparse /rc/bin/emparse -- cgit v1.2.3