From 9e3a67830109607a57f58b53b2f6f1e9458fc6c7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 22 Jan 2024 22:20:22 -0600 Subject: Update to use prefix characters --- et | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/et b/et index 0e03aa3..144b10a 100755 --- a/et +++ b/et @@ -3,26 +3,28 @@ # usage: et | sh BEGIN { - xend = xend ? xend : "...end...shexpand..." - dend = dend ? dend : "...end...document..." - # We shell out to sed for this because awk doesn't do capture groups ;-; + dend = ";doc_end;" + # Ask sed to do these b/c awk has no capture groups ;_; shellfix = "sed -E" \ " -e 's/`/\\\\`/g'" \ " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \ " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'" + shxwrap = " -e 's/^/:/'" htmlfix = "sed -E" \ - " -e 's#([^\\\\]|^)&#\\1\\&#g;'" \ - " -e 's#([^\\\\]|^)<#\\1\\<#g;'" \ - " -e 's#([^\\\\]|^)>#\\1\\>#g;'" \ - " -e 's#\\\\([&<>])#\\1#g;'" + " -e 's#([^\\\\]|^)&#\\1\\&#g'" \ + " -e 's#([^\\\\]|^)<#\\1\\<#g'" \ + " -e 's#([^\\\\]|^)>#\\1\\>#g'" \ + " -e 's#\\\\([&<>])#\\1#g'" true = 1 ; false = 0 - print "shexpand()(eval \"$(echo \"cat<<'"xend"'\";cat;echo "xend")\")" - print "shellfix()(" shellfix ")" - print "htmlfix()(" htmlfix ")" + print "#!/bin/sh\n########## generated with excitable text #########" + print "shexpand()(eval \"$(:;(echo 'cat<<.';cat|sed 's/^/,/';echo .)"\ + "|unwrap ,)\")" + print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")" + print "wrap()(sed \"s/^/$1/\")\nunwrap()(sed \"s/^$1//\")" } end[endn] && $0 == end[endn] { - par = par "\n" end[endn--] "\n)" + par = par "\n" end[endn--] "\n" ")" printpar() subdocp = false next @@ -38,10 +40,8 @@ end[endn] && $0 == end[endn] { printpar() docp = !docp docend = $2 ? $2 : dend - if (docp) - print "shexpand<<" docend - else - print docend "\n" + if (docp) print "unwrap :<<'" docend "'|shexpand" + else print docend "\n" next } @@ -56,8 +56,7 @@ end[endn] && $0 == end[endn] { specialp = 2 gsub(/"/,"\\\\&") ln = "$$(" substr($1, 2) - for (f=2;f<=NF;f++) - ln = ln " \"" $f "\"" + for (f=2;f<=NF;f++) ln = ln " \"" $f "\"" ln = ln ")" $0 = ln } @@ -78,12 +77,10 @@ END { function printpar() { specialp = specialp || (match(par, /^[ ]*" par "

" - print par | shellfix - print "" - close(shellfix) - } else - print par + if (!subdocp && !specialp) par = "

" par "

" + shx = shellfix shxwrap + print par | shx + close(shx) + } else print par par = "" } -- cgit 1.4.1-21-gabe81