Skip to content

Commit f116f65

Browse files
committed
indent
1 parent aabb9b3 commit f116f65

File tree

1 file changed

+118
-126
lines changed

1 file changed

+118
-126
lines changed

_ref/template.arc

Lines changed: 118 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
(= hpasswords* (table))
44

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>")
78
)
89

910
(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))))))))
1819

1920
(def end-table () (prn "</table>"))
2021

@@ -31,8 +32,7 @@
3132
(if (posmatch "%%INDEX%%" line)
3233
(disp (subst (getlinkindexhtml) "%%INDEX%%" line))
3334
(disp (subst links* "%%LINKS%%" (subst page* "%%TITLE%%" line))))
34-
(prn)
35-
)
35+
(prn))
3636
(close inf)))
3737

3838
(def faketest (input result)
@@ -46,58 +46,57 @@
4646
(def dohtmltest (testcode) (dotestint 'html testcode))
4747

4848
(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))))
8685

8786
(= desc "")
8887

8988
(def intags (tag tags) (if (no tags) nil
9089
(is tag (car tags)) t
91-
(intags tag (cdr tags))))
90+
(intags tag (cdr tags))))
9291

9392

9493
(def op (args)
9594
(with (tag nil tags nil operation nil arglist nil desc nil testlist nil)
9695
(push (pop args) tags)
9796
(= tag (pop args))
9897
(while (in tag 'destructive 'predicate)
99-
(push tag tags)
100-
(= tag (pop args)))
98+
(push tag tags)
99+
(= tag (pop args)))
101100
(= operation tag)
102101
(push operation tags)
103102
(= arglist (pop args))
@@ -115,36 +114,34 @@
115114
(if (intags 'destructive tags) (prn "<img src='destructive.gif' title='Destructive'/>"))
116115
(if (intags 'predicate tags) (prn "<img src='predicate.gif' title='Predicate'/>"))
117116

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> "))
120120
(prn "<span class='args'>" arglist "</span>")
121121
(prn " <div class='desc'>" desc "</div>")
122122
(prn " </td>")
123123
(pr " <td class='arc'>")
124124
(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>")))
134131

135132
(def pair? (x) (is (type x) 'cons))
136133

137134
; all-links* = ((foo.tem item1 item2) (bar.tem item1 ...))
138135
(= all-links* '())
139136
(= update-links* nil)
140137
(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))))))
143140

144141
(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))))))
148145

149146
(def add-anchor1 (link)
150147
(add-index1 current-file*)
@@ -156,40 +153,37 @@
156153
(prn "<a name='" (anchor-esc title) "'></a>")
157154
)
158155

159-
(def newtable (title . contents)
156+
(def newtable (title . contents)
160157
(hdr title)
161158
(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)))))
167164
(start-table title)
168165
(map doit contents)
169-
(end-table)
170-
)
166+
(end-table))
171167

172-
(def page (title . contents)
168+
(def page (title . contents)
173169
(= page* title)
174170
(copy-file "docs/hdr2.html")
175171
(add-anchor1 (coerce title 'string))
176172
(map doit contents)
177-
(copy-file "footer.txt")
178-
)
173+
(copy-file "footer.txt"))
179174

180-
(def top-page (title . contents)
175+
(def top-page (title . contents)
181176
(= page* title)
182177
(= links* "")
183178
(copy-file "docs/hdr2.html")
184179
(map doit contents)
185-
(copy-file "footer.txt")
186-
)
180+
(copy-file "footer.txt"))
187181

188182
(def hdr (msg) (prn "<h2>" msg "</h2>"))
189183
(def text (msg) (prn msg))
190184

191185
; Make the index
192-
(def index ()
186+
(def index ()
193187
(prn "<h2>Index</h2>")
194188
(on links all-links*
195189
(with (filename (htmlname (links 0)) title ((index* (links 0)) 0))
@@ -199,8 +193,7 @@
199193
(prn "<div class=\"sublink\">")
200194
(on link (cdr links)
201195
(prn "<a class=\"sublink\" href=\"" filename "#" (anchor-esc link) "\">" link "</a>"))
202-
(prn "</div>")
203-
)))
196+
(prn "</div>"))))
204197

205198
(= out-file-name* "")
206199
(= out-file* (stdout))
@@ -221,14 +214,14 @@
221214
(is 'template) nil
222215
(is 'file cmd) (do (= out-file-name* (args 0))
223216
(= out-file* (outfile (arg 1))))
224-
(err "Expected a template operation" arg)))))
217+
(err "Expected a template operation" arg)))))
225218

226219

227220
(def triples (xs (o n 3))
228221
(if (or (no xs) (< (len xs) n))
229222
nil
230223
(cons (firstn n xs)
231-
(triples (cdr xs) n))))
224+
(triples (cdr xs) n))))
232225

233226
; Return just the templates from filename
234227
(def gettemplates (filename)
@@ -240,37 +233,36 @@
240233
(if (is (cut str i (+ i (len pat))) pat) (throw i)))
241234
nil))
242235

243-
236+
244237
; Create list of (text link):
245238
; Extract <a href="foo.html">text</a> and convert to (text "foo.tem")
246239
(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)
250243
(when m
251244
(++ m 6)
252245
(withs (n (safematch "\">" line (+ m 1))
253246
o (safematch "<" line (+ m 1))
254247
link (cut line m n)
255248
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))
261254

262255
(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))))))
274266

275267
(def htmllink (href text) (prn "<a href=\"" href "\">" text "</a>"))
276268

@@ -316,35 +308,35 @@ result))
316308
(def alpha (c) (<= #\a c #\z))
317309

318310
(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>"))))))
327319

328320
(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))))))))))
335327

336328
(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)))))))
341333

342334
; Find index of last location <= pos where chr appears in str, or nil
343335
(def rmatch (str chr (o pos 99999))
344336
(let minpos (min pos (- (len str) 1))
345337
(if (< minpos 0) nil
346338
(is (str minpos) chr) minpos
347-
(rmatch str chr (- minpos 1)))))
339+
(rmatch str chr (- minpos 1)))))
348340

349341
; Split string at length n or earlier, splitting at a <
350342
(def splitstring (str (o maxlen 60) (o splitchar #\<))

0 commit comments

Comments
 (0)