#!/bin/sh { excitable="text" "exec" "awk" "-f" "$0" "$@"; } # -*- awk -*- # usage: et | sh BEGIN { 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'" true = 1 ; false = 0 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" ")" printpar() subdocp = false next } /\\$/ { getline nl sub(/\\$/,"") $0 = $0 " " nl } /^\.\.\./ { printpar() docp = !docp docend = $2 ? $2 : dend if (docp) print "unwrap :<<'" docend "'|shexpand" else print docend "\n" next } /^\.\./ && docp { subdocp = true end[++endn] = (match($0,"<<") ? substr($0,RSTART+RLENGTH) : "..") command = substr($0, 3, RSTART ? RSTART - 2 : length) $0 = "$$(" (command ? command : "cat") "<<" end[endn] } /^\./ && docp { specialp = 2 gsub(/"/,"\\\\&") ln = "$$(" substr($1, 2) for (f=2;f<=NF;f++) ln = ln " \"" $f "\"" ln = ln ")" $0 = ln } /^$/ { if (!par) next printpar() } { par = par (par?"\n":"") $0 } { if (--specialp < 0) specialp = 0 } END { if (par) printpar() if (docp) print docend } function printpar() { specialp = specialp || (match(par, /^[ ]*" par "

" shx = shellfix shxwrap print par | shx close(shx) } else print par par = "" }