about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xet45
1 files changed, 21 insertions, 24 deletions
diff --git a/et b/et index 0e03aa3..144b10a 100755 --- a/et +++ b/et
@@ -3,26 +3,28 @@
3# usage: et <file> | sh 3# usage: et <file> | sh
4 4
5BEGIN { 5BEGIN {
6 xend = xend ? xend : "...end...shexpand..." 6 dend = ";doc_end;"
7 dend = dend ? dend : "...end...document..." 7 # Ask sed to do these b/c awk has no capture groups ;_;
8 # We shell out to sed for this because awk doesn't do capture groups ;-;
9 shellfix = "sed -E" \ 8 shellfix = "sed -E" \
10 " -e 's/`/\\\\`/g'" \ 9 " -e 's/`/\\\\`/g'" \
11 " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \ 10 " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \
12 " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'" 11 " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'"
12 shxwrap = " -e 's/^/:/'"
13 htmlfix = "sed -E" \ 13 htmlfix = "sed -E" \
14 " -e 's#([^\\\\]|^)&#\\1\\&amp;#g;'" \ 14 " -e 's#([^\\\\]|^)&#\\1\\&amp;#g'" \
15 " -e 's#([^\\\\]|^)<#\\1\\&lt;#g;'" \ 15 " -e 's#([^\\\\]|^)<#\\1\\&lt;#g'" \
16 " -e 's#([^\\\\]|^)>#\\1\\&gt;#g;'" \ 16 " -e 's#([^\\\\]|^)>#\\1\\&gt;#g'" \
17 " -e 's#\\\\([&<>])#\\1#g;'" 17 " -e 's#\\\\([&<>])#\\1#g'"
18 true = 1 ; false = 0 18 true = 1 ; false = 0
19 print "shexpand()(eval \"$(echo \"cat<<'"xend"'\";cat;echo "xend")\")" 19 print "#!/bin/sh\n########## generated with excitable text #########"
20 print "shellfix()(" shellfix ")" 20 print "shexpand()(eval \"$(:;(echo 'cat<<.';cat|sed 's/^/,/';echo .)"\
21 print "htmlfix()(" htmlfix ")" 21 "|unwrap ,)\")"
22 print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")"
23 print "wrap()(sed \"s/^/$1/\")\nunwrap()(sed \"s/^$1//\")"
22} 24}
23 25
24end[endn] && $0 == end[endn] { 26end[endn] && $0 == end[endn] {
25 par = par "\n" end[endn--] "\n)" 27 par = par "\n" end[endn--] "\n" ")"
26 printpar() 28 printpar()
27 subdocp = false 29 subdocp = false
28 next 30 next
@@ -38,10 +40,8 @@ end[endn] && $0 == end[endn] {
38 printpar() 40 printpar()
39 docp = !docp 41 docp = !docp
40 docend = $2 ? $2 : dend 42 docend = $2 ? $2 : dend
41 if (docp) 43 if (docp) print "unwrap :<<'" docend "'|shexpand"
42 print "shexpand<<" docend 44 else print docend "\n"
43 else
44 print docend "\n"
45 next 45 next
46} 46}
47 47
@@ -56,8 +56,7 @@ end[endn] && $0 == end[endn] {
56 specialp = 2 56 specialp = 2
57 gsub(/"/,"\\\\&") 57 gsub(/"/,"\\\\&")
58 ln = "$$(" substr($1, 2) 58 ln = "$$(" substr($1, 2)
59 for (f=2;f<=NF;f++) 59 for (f=2;f<=NF;f++) ln = ln " \"" $f "\""
60 ln = ln " \"" $f "\""
61 ln = ln ")" 60 ln = ln ")"
62 $0 = ln 61 $0 = ln
63} 62}
@@ -78,12 +77,10 @@ END {
78function printpar() { 77function printpar() {
79 specialp = specialp || (match(par, /^[ ]*</)) 78 specialp = specialp || (match(par, /^[ ]*</))
80 if (docp) { 79 if (docp) {
81 if (!subdocp && !specialp) 80 if (!subdocp && !specialp) par = "<p>" par "</p>"
82 par = "<p>" par "</p>" 81 shx = shellfix shxwrap
83 print par | shellfix 82 print par | shx
84 print "" 83 close(shx)
85 close(shellfix) 84 } else print par
86 } else
87 print par
88 par = "" 85 par = ""
89} 86}