|
2 | 2 |
|
3 | 3 | (= hpasswords* (table)) |
4 | 4 |
|
5 | | -(def start-table (hdr) (prn "<p><table class='arc'>") |
6 | | -;(prn "<tr><th class='arc' colspan=2>" hdr "</th></tr>") |
| 5 | +(def start-table (hdr) |
| 6 | + (prn "<p><table class='arc'>") |
| 7 | +; (prn "<tr><th class='arc' colspan=2>" hdr "</th></tr>") |
7 | 8 | ) |
8 | 9 |
|
9 | 10 | (def codelinkencode (str) |
10 | | - (subst "%2f" "/" |
11 | | - (subst "%2b" "+" |
12 | | - (subst "%3c" "<" |
13 | | - (subst "%3e" ">" |
14 | | - (subst "%2a" "*" |
15 | | - (subst "%3f" "?" |
16 | | - (subst "%2f" "%" |
17 | | - str)))))))) |
| 11 | + (subst "%2f" "/" |
| 12 | + (subst "%2b" "+" |
| 13 | + (subst "%3c" "<" |
| 14 | + (subst "%3e" ">" |
| 15 | + (subst "%2a" "*" |
| 16 | + (subst "%3f" "?" |
| 17 | + (subst "%2f" "%" |
| 18 | + str)))))))) |
18 | 19 |
|
19 | 20 | (def end-table () (prn "</table>")) |
20 | 21 |
|
|
31 | 32 | (if (posmatch "%%INDEX%%" line) |
32 | 33 | (disp (subst (getlinkindexhtml) "%%INDEX%%" line)) |
33 | 34 | (disp (subst links* "%%LINKS%%" (subst page* "%%TITLE%%" line)))) |
34 | | - (prn) |
35 | | - ) |
| 35 | + (prn)) |
36 | 36 | (close inf))) |
37 | 37 |
|
38 | 38 | (def faketest (input result) |
|
46 | 46 | (def dohtmltest (testcode) (dotestint 'html testcode)) |
47 | 47 |
|
48 | 48 | (def dotestint (testtype testcode) |
49 | | - (let show nil |
50 | | - (prn "<pre>") |
51 | | - (pr (html-esc ">")) |
52 | | - |
53 | | - (when (caris testcode 'show) |
54 | | - (= show t) |
55 | | - (= testcode (cdr testcode)) |
56 | | - (if (is (type (car testcode)) 'string) (= testcode (car testcode)))) |
57 | | - ;If a string, disp and get obj, else write |
58 | | - (if (is (type testcode) 'string) |
59 | | - (do (disp testcode) (= testcode (sread (instring testcode) 'eof))) |
60 | | - (pr (html-esc (tostring (pprint testcode))))) |
61 | | - |
62 | | - (prn) |
63 | | - |
64 | | - (= sop (outstring)) |
65 | | - (call-w/stdout sop (fn () |
66 | | - (= result (on-err errproc (fn () (eval testcode)))))) |
67 | | - (= stdout-val (inside sop)) |
68 | | - |
69 | | - ; Hack around bad return value |
70 | | - (= sop (outstring)) |
71 | | - (write result sop) |
72 | | - (= result-string (inside sop)) |
73 | | - (if (or (is result-string "#t") |
74 | | - (is result-string "#f") |
75 | | - (is result-string "#<thread>")) |
76 | | - (= result result-string)) |
77 | | - |
78 | | - (if (no (is "" stdout-val)) (spanclass "stdout" (prn (html-esc (splitstring stdout-val 60))))) |
79 | | - (when (and (isnt 'html testtype) (isnt 'err result)) |
80 | | - (spanclass "return" (prn (html-esc result-string)))) |
81 | | - (prn "</pre>") |
82 | | - (when show |
83 | | - (prn "<hr/>") |
84 | | - (prn stdout-val)) |
85 | | - )) |
| 49 | + (let show nil |
| 50 | + (prn "<pre>") |
| 51 | + (pr (html-esc ">")) |
| 52 | + |
| 53 | + (when (caris testcode 'show) |
| 54 | + (= show t) |
| 55 | + (= testcode (cdr testcode)) |
| 56 | + (if (is (type (car testcode)) 'string) (= testcode (car testcode)))) |
| 57 | + ;If a string, disp and get obj, else write |
| 58 | + (if (is (type testcode) 'string) |
| 59 | + (do (disp testcode) (= testcode (sread (instring testcode) 'eof))) |
| 60 | + (pr (html-esc (tostring (pprint testcode))))) |
| 61 | + |
| 62 | + (prn) |
| 63 | + |
| 64 | + (= sop (outstring)) |
| 65 | + (call-w/stdout sop (fn () |
| 66 | + (= result (on-err errproc (fn () (eval testcode)))))) |
| 67 | + (= stdout-val (inside sop)) |
| 68 | + |
| 69 | + ; Hack around bad return value |
| 70 | + (= sop (outstring)) |
| 71 | + (write result sop) |
| 72 | + (= result-string (inside sop)) |
| 73 | + (if (or (is result-string "#t") |
| 74 | + (is result-string "#f") |
| 75 | + (is result-string "#<thread>")) |
| 76 | + (= result result-string)) |
| 77 | + |
| 78 | + (if (no (is "" stdout-val)) (spanclass "stdout" (prn (html-esc (splitstring stdout-val 60))))) |
| 79 | + (when (and (isnt 'html testtype) (isnt 'err result)) |
| 80 | + (spanclass "return" (prn (html-esc result-string)))) |
| 81 | + (prn "</pre>") |
| 82 | + (when show |
| 83 | + (prn "<hr/>") |
| 84 | + (prn stdout-val)))) |
86 | 85 |
|
87 | 86 | (= desc "") |
88 | 87 |
|
89 | 88 | (def intags (tag tags) (if (no tags) nil |
90 | 89 | (is tag (car tags)) t |
91 | | - (intags tag (cdr tags)))) |
| 90 | + (intags tag (cdr tags)))) |
92 | 91 |
|
93 | 92 |
|
94 | 93 | (def op (args) |
95 | 94 | (with (tag nil tags nil operation nil arglist nil desc nil testlist nil) |
96 | 95 | (push (pop args) tags) |
97 | 96 | (= tag (pop args)) |
98 | 97 | (while (in tag 'destructive 'predicate) |
99 | | - (push tag tags) |
100 | | - (= tag (pop args))) |
| 98 | + (push tag tags) |
| 99 | + (= tag (pop args))) |
101 | 100 | (= operation tag) |
102 | 101 | (push operation tags) |
103 | 102 | (= arglist (pop args)) |
|
115 | 114 | (if (intags 'destructive tags) (prn "<img src='destructive.gif' title='Destructive'/>")) |
116 | 115 | (if (intags 'predicate tags) (prn "<img src='predicate.gif' title='Predicate'/>")) |
117 | 116 |
|
118 | | - (if (intags 'nolink tags) (pr "<span class='op'>" operation "</span> ") |
119 | | - (pr "<a class='op' href='http://practical-scheme.net/wiliki/arcxref?" (url-esc operation) "'>" operation "</a> ")) |
| 117 | + (if (intags 'nolink tags) |
| 118 | + (pr "<span class='op'>" operation "</span> ") |
| 119 | + (pr "<a class='op' href='http://practical-scheme.net/wiliki/arcxref?" (url-esc operation) "'>" operation "</a> ")) |
120 | 120 | (prn "<span class='args'>" arglist "</span>") |
121 | 121 | (prn " <div class='desc'>" desc "</div>") |
122 | 122 | (prn " </td>") |
123 | 123 | (pr " <td class='arc'>") |
124 | 124 | (if (no testlist) nil |
125 | | - (no (testlist 0)) nil |
126 | | - (is 'faketest ((testlist 0) 0)) (faketest ((testlist 0) 1) ((testlist |
127 | | - 0) 2)) |
128 | | - (is 'tests ((testlist 0) 0)) (map dotest (cdr:car testlist)) |
129 | | - (is 'htmltests ((testlist 0) 0)) (map dohtmltest (cdr:car testlist)) |
130 | | - (err "Expected tests" operation (car testlist) )) |
131 | | - (prn " </td></tr>") |
132 | | -) |
133 | | - ) |
| 125 | + (no (testlist 0)) nil |
| 126 | + (is 'faketest ((testlist 0) 0)) (faketest ((testlist 0) 1) ((testlist 0) 2)) |
| 127 | + (is 'tests ((testlist 0) 0)) (map dotest (cdr:car testlist)) |
| 128 | + (is 'htmltests ((testlist 0) 0)) (map dohtmltest (cdr:car testlist)) |
| 129 | + (err "Expected tests" operation (car testlist) )) |
| 130 | + (prn " </td></tr>"))) |
134 | 131 |
|
135 | 132 | (def pair? (x) (is (type x) 'cons)) |
136 | 133 |
|
137 | 134 | ; all-links* = ((foo.tem item1 item2) (bar.tem item1 ...)) |
138 | 135 | (= all-links* '()) |
139 | 136 | (= update-links* nil) |
140 | 137 | (def add-index1 (link) |
141 | | - (if update-links* |
142 | | - (= all-links* (+ all-links* (list (list link)))))) |
| 138 | + (if update-links* |
| 139 | + (= all-links* (+ all-links* (list (list link)))))) |
143 | 140 |
|
144 | 141 | (def add-index2 (link) |
145 | | - (if update-links* |
146 | | - (let lastelt (- (len all-links*) 1) |
147 | | - (= (all-links* lastelt) (+ (all-links* lastelt) (list link)))))) |
| 142 | + (if update-links* |
| 143 | + (let lastelt (- (len all-links*) 1) |
| 144 | + (= (all-links* lastelt) (+ (all-links* lastelt) (list link)))))) |
148 | 145 |
|
149 | 146 | (def add-anchor1 (link) |
150 | 147 | (add-index1 current-file*) |
|
156 | 153 | (prn "<a name='" (anchor-esc title) "'></a>") |
157 | 154 | ) |
158 | 155 |
|
159 | | -(def newtable (title . contents) |
| 156 | +(def newtable (title . contents) |
160 | 157 | (hdr title) |
161 | 158 | (when (and (pair? contents) |
162 | | - (pair? (car contents))) |
163 | | - (if (is ((car contents) 0) 'text) |
164 | | - (do (text ((car contents) 1)) (= contents (cdr contents)))) |
165 | | - (if (is ((car contents) 0) 'import) |
166 | | - (do (copy-file ((car contents) 1)) (= contents (cdr contents))))) |
| 159 | + (pair? (car contents))) |
| 160 | + (if (is ((car contents) 0) 'text) |
| 161 | + (do (text ((car contents) 1)) (= contents (cdr contents)))) |
| 162 | + (if (is ((car contents) 0) 'import) |
| 163 | + (do (copy-file ((car contents) 1)) (= contents (cdr contents))))) |
167 | 164 | (start-table title) |
168 | 165 | (map doit contents) |
169 | | - (end-table) |
170 | | - ) |
| 166 | + (end-table)) |
171 | 167 |
|
172 | | -(def page (title . contents) |
| 168 | +(def page (title . contents) |
173 | 169 | (= page* title) |
174 | 170 | (copy-file "docs/hdr2.html") |
175 | 171 | (add-anchor1 (coerce title 'string)) |
176 | 172 | (map doit contents) |
177 | | - (copy-file "footer.txt") |
178 | | - ) |
| 173 | + (copy-file "footer.txt")) |
179 | 174 |
|
180 | | -(def top-page (title . contents) |
| 175 | +(def top-page (title . contents) |
181 | 176 | (= page* title) |
182 | 177 | (= links* "") |
183 | 178 | (copy-file "docs/hdr2.html") |
184 | 179 | (map doit contents) |
185 | | - (copy-file "footer.txt") |
186 | | - ) |
| 180 | + (copy-file "footer.txt")) |
187 | 181 |
|
188 | 182 | (def hdr (msg) (prn "<h2>" msg "</h2>")) |
189 | 183 | (def text (msg) (prn msg)) |
190 | 184 |
|
191 | 185 | ; Make the index |
192 | | -(def index () |
| 186 | +(def index () |
193 | 187 | (prn "<h2>Index</h2>") |
194 | 188 | (on links all-links* |
195 | 189 | (with (filename (htmlname (links 0)) title ((index* (links 0)) 0)) |
|
199 | 193 | (prn "<div class=\"sublink\">") |
200 | 194 | (on link (cdr links) |
201 | 195 | (prn "<a class=\"sublink\" href=\"" filename "#" (anchor-esc link) "\">" link "</a>")) |
202 | | - (prn "</div>") |
203 | | - ))) |
| 196 | + (prn "</div>")))) |
204 | 197 |
|
205 | 198 | (= out-file-name* "") |
206 | 199 | (= out-file* (stdout)) |
|
221 | 214 | (is 'template) nil |
222 | 215 | (is 'file cmd) (do (= out-file-name* (args 0)) |
223 | 216 | (= out-file* (outfile (arg 1)))) |
224 | | - (err "Expected a template operation" arg))))) |
| 217 | + (err "Expected a template operation" arg))))) |
225 | 218 |
|
226 | 219 |
|
227 | 220 | (def triples (xs (o n 3)) |
228 | 221 | (if (or (no xs) (< (len xs) n)) |
229 | 222 | nil |
230 | 223 | (cons (firstn n xs) |
231 | | - (triples (cdr xs) n)))) |
| 224 | + (triples (cdr xs) n)))) |
232 | 225 |
|
233 | 226 | ; Return just the templates from filename |
234 | 227 | (def gettemplates (filename) |
|
240 | 233 | (if (is (cut str i (+ i (len pat))) pat) (throw i))) |
241 | 234 | nil)) |
242 | 235 |
|
243 | | - |
| 236 | + |
244 | 237 | ; Create list of (text link): |
245 | 238 | ; Extract <a href="foo.html">text</a> and convert to (text "foo.tem") |
246 | 239 | (def gettemlinks (filename) |
247 | | - (let result nil |
248 | | - (w/infile inf filename (w/stdin inf (whilet line (readline) |
249 | | - (let m (safematch "href=\"" line) |
| 240 | + (let result nil |
| 241 | + (w/infile inf filename (w/stdin inf (whilet line (readline) |
| 242 | + (let m (safematch "href=\"" line) |
250 | 243 | (when m |
251 | 244 | (++ m 6) |
252 | 245 | (withs (n (safematch "\">" line (+ m 1)) |
253 | 246 | o (safematch "<" line (+ m 1)) |
254 | 247 | link (cut line m n) |
255 | 248 | link2 (subst ".tem" ".html" link)) |
256 | | - (when (and n o (< n o)) |
257 | | - (let text (cut line (+ n 2) o) |
258 | | - (when (and (isnt link link2) (file-exists link2)) |
259 | | - (= result (+ result (list (list text link2))))))))))))) |
260 | | -result)) |
| 249 | + (when (and n o (< n o)) |
| 250 | + (let text (cut line (+ n 2) o) |
| 251 | + (when (and (isnt link link2) (file-exists link2)) |
| 252 | + (= result (+ result (list (list text link2))))))))))))) |
| 253 | + result)) |
261 | 254 |
|
262 | 255 | (def readtop (filename) |
263 | | - ; (index* foo.tem) == (title prev.tem this.tem next.tem) |
264 | | - (= index* (table)) |
265 | | - (let temlinks (gettemlinks filename) |
266 | | - ; pagelist* == ("page1.tem" "page2.tem" ...) |
267 | | - (= pagelist* (map [_ 1] temlinks)) |
268 | | - (each (title link) temlinks |
269 | | - (= (index* link) title)) |
270 | | - (each trip (triples (+ '(nil) pagelist* '(nil))) |
271 | | - (if trip |
272 | | - (= (index* trip.1) (cons (index* trip.1) trip))) |
273 | | - ))) |
| 256 | + ; (index* foo.tem) == (title prev.tem this.tem next.tem) |
| 257 | + (= index* (table)) |
| 258 | + (let temlinks (gettemlinks filename) |
| 259 | + ; pagelist* == ("page1.tem" "page2.tem" ...) |
| 260 | + (= pagelist* (map [_ 1] temlinks)) |
| 261 | + (each (title link) temlinks |
| 262 | + (= (index* link) title)) |
| 263 | + (each trip (triples (+ '(nil) pagelist* '(nil))) |
| 264 | + (if trip |
| 265 | + (= (index* trip.1) (cons (index* trip.1) trip)))))) |
274 | 266 |
|
275 | 267 | (def htmllink (href text) (prn "<a href=\"" href "\">" text "</a>")) |
276 | 268 |
|
@@ -316,35 +308,35 @@ result)) |
316 | 308 | (def alpha (c) (<= #\a c #\z)) |
317 | 309 |
|
318 | 310 | (def getlinkindexhtml () |
319 | | - (tostring |
320 | | - (with (idx (getlinkindex) first nil) |
321 | | - (each (name link) idx |
322 | | - (let newfirst (name 0) |
323 | | - (when (and (alpha newfirst) (isnt first newfirst)) |
324 | | - (= first newfirst) |
325 | | - (prn "<h2>" first "</h2>")) |
326 | | - (prn "<a href='" link "'>" name "</a>")))))) |
| 311 | + (tostring |
| 312 | + (with (idx (getlinkindex) first nil) |
| 313 | + (each (name link) idx |
| 314 | + (let newfirst (name 0) |
| 315 | + (when (and (alpha newfirst) (isnt first newfirst)) |
| 316 | + (= first newfirst) |
| 317 | + (prn "<h2>" first "</h2>")) |
| 318 | + (prn "<a href='" link "'>" name "</a>")))))) |
327 | 319 |
|
328 | 320 | (def getlinkindex () |
329 | | - (mergesort (fn (x y) (< (car x) (car y))) |
330 | | - (accum accfn |
331 | | - (each links all-links* |
332 | | - (let file (+ (subst ".html" ".tem" (car links)) "#") |
333 | | - (each link (cdr links) |
334 | | - (accfn (list link (+ file (codelinkencode link)))))))))) |
| 321 | + (mergesort (fn (x y) (< (car x) (car y))) |
| 322 | + (accum accfn |
| 323 | + (each links all-links* |
| 324 | + (let file (+ (subst ".html" ".tem" (car links)) "#") |
| 325 | + (each link (cdr links) |
| 326 | + (accfn (list link (+ file (codelinkencode link)))))))))) |
335 | 327 |
|
336 | 328 | (def dumplinks () |
337 | | - (w/outfile of "dumplinks" (w/stdout of |
338 | | - (each links all-links* |
339 | | - (each link (cdr links) |
340 | | - (prn (codelinkencode link))))))) |
| 329 | + (w/outfile of "dumplinks" (w/stdout of |
| 330 | + (each links all-links* |
| 331 | + (each link (cdr links) |
| 332 | + (prn (codelinkencode link))))))) |
341 | 333 |
|
342 | 334 | ; Find index of last location <= pos where chr appears in str, or nil |
343 | 335 | (def rmatch (str chr (o pos 99999)) |
344 | 336 | (let minpos (min pos (- (len str) 1)) |
345 | 337 | (if (< minpos 0) nil |
346 | 338 | (is (str minpos) chr) minpos |
347 | | - (rmatch str chr (- minpos 1))))) |
| 339 | + (rmatch str chr (- minpos 1))))) |
348 | 340 |
|
349 | 341 | ; Split string at length n or earlier, splitting at a < |
350 | 342 | (def splitstring (str (o maxlen 60) (o splitchar #\<)) |
|
0 commit comments