summaryrefslogtreecommitdiffstats
path: root/genman.txr
blob: 6ef0404b527091355f0f7aa1128a7fb3c69febd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
@# This requires a hacked version of man2html
@# See here: http://www.kylheku.com/cgit/man
@(bind closedtxt " <TT>[+]</TT>")
@(bind opentxt " <TT>[-]</TT>")
@(bind xpnall "[expand all]")
@(bind clpsall "[collapse all]")
@(bind closed t)
@(do
   (defvarl symhash (hash))
   (defvarl tagmap (hash))
   (defvarl tochash (hash))
   (defvarl dupe-hashes (hash))
   (defvarl dupe-titles (hash))
   (defvarl direct (hash))
   (defvarl disamb (hash))
   (defvarl dist-counter 0)
   (defvarl colli (hash-props))

   (defun hash-title (title)
     (let* ((ti title)
            (cntr 0)
            (defs (build (while-match `@nil<tt>@ttitem</tt>@rest` ti
                           (add ttitem)
                           (set ti rest)))))
       (set title (if defs
                    (car defs)
                    (downcase-str title))
            ti title)
       (while* [dupe-titles title]
         (set title `T-@(inc cntr)-@ti`))
       (set [dupe-titles title] t)
       (let* ((h (crc32 title))
              (h (+ h (or [colli title] 0)))
              (existing [dupe-hashes h]))
         (when existing
           (unless (equal title existing)
             (error "~a ~a hash collision!" existing title)))
         (set [dupe-hashes h] title)
         (format nil "N-~,08X" h))))

   (defun toc-tag (sec)
     `TOC-@sec`)

   (defun process-ambiguities (hash)
     (let ((rhash (hash)))
       (dohash (sym tags hash)
         (let ((shash (fmt "S-~,08X" (crc32 sym))))
           (if [rhash shash]
             (error "~a ~a hash collision" sym [rhash shash])
             (set [rhash shash] sym))
           (set [hash sym] shash)
           (if (null (cdr tags))
             (push shash [direct (car tags)])
             (set [disamb shash] (reverse tags))))))))
Content-type: text/html
@(skip 15)
<h1>TXR</h1>
@(skip)Updated: @YEAR-@MONTH-@DAY<br><a href="#index">Index</a>
@(bind TIME @(make-time-utc (int-str YEAR) (int-str MONTH) (int-str DAY)
                            0 0 0 nil))
@(bind VERSION nil)
@(collect :vars (BODY))
@  (some)
@    (cases)
<a name="@tag">&nbsp;</a>
@      (some)
<h@level>@sec @title</h@level>
@      (or)
<h@level>@sec @title
</h@level>
@      (end)
@      (bind newtag @(hash-title title))
@      (do (set [tagmap tag] newtag))
@      (output :into BODY)
<a name="@newtag">&nbsp;</a>
<h@level><a href="#@(toc-tag sec)" onclick="tocjump('@(toc-tag sec)')">@sec</a> @title</h@level>
@      (end)
@      (cat BODY "\n")
@    (or)
@BODY
@    (end)
@  (and)
<b>TXR</b> - text processing language (version @ver)
@    (set VERSION ver)
@  (end)
@(until)
<hr>
<a name="index">&nbsp;</a><h2>Index</h2>
@(end)
<hr>
@(collect :vars (TOC))
@  (some)
@    (cases)
@      (cases)
<dt><a href="#@tag">@num @rest</a><dd>
@      (or)
<dt><a href="#@tag">@num @rest
</a><dd>
@      (end)
@      (bind TOC `<dt><a name="@(toc-tag num)" class="tocanchor">@num</a> <a href="#@[tagmap tag]">@rest</a></dt>`)
@    (or)
<a name="index">@(skip)
@      (output :into TOC)
<h2>Contents</h2>
<noscript>
<h3>Please turn on Javascript to use the collapsible contents.</h3>
</noscript>
<a href="#/" onclick="toggleall(this)">@xpnall</a>
@      (end)
@    (or)
@TOC
@    (end)
@  (and)
<dt><a href="@nil">@nil TXR LISP</a><dd>
@  (and)
<dt><a href="#@tag">@(coll :vars (sym))<tt>@sym</tt>@(end)
@    (do (let ((n-tag [tagmap tag]))
           (mapdo (do pushnew n-tag [symhash (html-decode @1)]) sym)
           (set [tochash n-tag] rest)))
@  (and)
<dt><a href="#@tag">@num @nil
@    (maybe)
</a><dd>
@    (end)
<dl>
@    (cat TOC)
@    (bind pos @(car (search-regex TOC #/<\/dt/)))
@    (bind id @(gensym))
@    (do (set [TOC pos..pos]
              `<a href="#/" onclick="toggle(this, '@id')" class="toggle">@(if closed closedtxt opentxt)</a>`))
@    (output :into TOC)
@TOC
<dd><dl id="@id" class="tocsec"@(if closed " style=\"display: none\"")>
@    (end)
@  (end)
@(until)
This document was created by
@(end)
@(flatten TOC)
@(do (process-ambiguities symhash))
@(set BODY @(let ((inside-tt nil)
                  (inside-syntax nil))
              (mapcar (do cond
                        ((equal @1 "<tt>") (set inside-tt t) @1)
                        ((equal @1 "</tt>") (set inside-tt nil)
                                            (set inside-syntax nil)
                                            @1)
                        ((equal @1 "<dt>Syntax:<dd>") (set inside-syntax t) @1)
                        ((or (and inside-tt (not inside-syntax))
                             (match-regex @1 #/<dt><tt>/))
                          (regsub #/@?[\(\[][^ )&]+/
                                  (do let* ((at (if (eql [@1 0] #\@)
                                                 (pop @1)))
                                            (tok [@1 1..:])
                                            (bkt [@1 0])
                                            (tag [symhash (html-decode tok)]))
                                    (if tag
                                      `@at@bkt<a href="#@tag">@tok</a>`
                                      `@at@1`)) @1))
                        ((starts-with "<a name=" @1)
                         (match @(with `<a name="@tag">@rest`
                                       shash [direct tag])
                           @1
                           (join (collect-each ((sh shash))
                                   `<a name="@sh">&nbsp;</a>\n`)
                                 @1)))
                        ((search-regex @1 #/<h[1-9]>/) @1)
                        (t (regsub #/<tt>.%<\/tt>/
                             (do let* ((tok [@1 4 -5])
                                       (tend (break-str tok ") "))
                                       pfx sym sfx tag)
                               (cond
                                 ((match-str tok "@(")
                                  (set pfx "@("
                                       sym [tok 2 tend]
                                       sfx [tok tend .. :]
                                       tag [symhash (html-decode sym)]))
                                 (t (set tag [symhash (html-decode tok)]
                                         sym tok)))
                               (if tag
                                 `<tt>@pfx<a href="#@tag">@sym</a>@sfx</tt>`
                                 @1))
                             @1)))
                      BODY)))
@(bind (d-tag n-tag) @(transpose (hash-pairs disamb)))
@(output)
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>Manpage for TXR @VERSION</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
.disambiguations dl {
  margin-bottom: 2048px;
}
dl.items dd:-moz-only-whitespace::after {
  content: "\00A0";
}
dl.items dd:empty:after {
  content: "\00A0";
}
dl.items dd {
  overflow: auto;
  min-width: calc(100% - 3em);
  margin-left: 3em;
  margin-bottom: 1ex;
}
dl.items dt {
  float: left;
  padding-right: 1ex;
}
kbd {
  background-color: #eee;
  border-radius: 3px;
  border: 1px solid #b4b4b4;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .2), 0 2px 0 0 rgba(255, 255, 255, .7) inset;
  color: #333;
  display: inline-block;
  font-weight: 700;
  line-height: 1;
  padding: 2px 4px;
  white-space: nowrap;
}
</style>
<script type="text/javascript">
var xpanded = false;
function toggle(link, id) {
  var e = document.getElementById(id);
  if (e.style.display == '') {
    e.style.display = 'none';
    link.innerHTML = '@closedtxt';
  } else {
    e.style.display = '';
    link.innerHTML = '@opentxt';
  }
}
function toggleall(link) {
  var toc = document.getElementsByClassName("TOC");
  var dls = toc[0].getElementsByClassName("tocsec");
  var atoggles = toc[0].getElementsByClassName("toggle");
  var ndisp = xpanded ? 'none' : '';
  var nhtml = xpanded ? '@closedtxt' : '@opentxt'

  for (var i = 0; i < dls.length; i++)
    dls[i].style.display = ndisp;

  for (var i = 0; i < atoggles.length; i++)
    atoggles[i].innerHTML = nhtml;

  link.innerHTML = xpanded ? '@xpnall' : '@clpsall';

  xpanded = !xpanded;
}
function tocjump(hash) {
  var toc = document.getElementsByClassName("TOC");
  var tanch = toc[0].getElementsByClassName("tocanchor");

  for (var i = 0; i < tanch.length; i++) {
     var ta = tanch[i];

     if (ta.name == hash) {
       for (var e = ta.parentNode; e !== null; e = e.parentElement) {
         if (e.tagName == "DL") {
           var dt = e.previousElementSibling;
           e.style.display = '';
           if (dt !== null) {
             var atoggles = dt.getElementsByClassName("toggle");
             if (atoggles.length > 0)
               atoggles[0].innerHTML = '@opentxt';
           }
         }
       }
     }
  }
}
</script>
</head><body>
<h2>Manpage for <a href="#@[tagmap "lbAB"]">TXR </a>@VERSION</h2>
<h2>@(time-string-utc TIME "%b %d, %Y")</h2>
<p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHJwYJKoZIhvcNAQcEoIIHGDCCBxQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYBQLZSe0xgg+h5deucBW3W3vj5kgJXsNm+Cmidp8krGwBTXBJJ4b6qreIdiArKKEVD6Lohb0f+267KtCvu28j/Kf6MlVfdsdI0p36jvqjisRGF/wtiJuHs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ZP1LXChvsENZklGuhgZSkgZEwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAgV86VpqAWuXvX6Oro4qJ1tYVIT5DgWpE692Ag422H7yRIr/9j/iKG4Thia/Oflx4TdL+IFJBAyPK9v6zZNZtBgPBynXb048hsP16l2vi0k5Q2JKiPDsEfBhGI+HnxLXEaUWAcVfCsQFvd2A1sxRr67ip5y2wwBelUecP3AjJ+YcxggGaMIIBlgIBATCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTEyMDMxMDEwMzczNFowIwYJKoZIhvcNAQkEMRYEFFrxlUHVygBbXOOpW9sAA30sKa+lMA0GCSqGSIb3DQEBAQUABIGAnn2T3mTtic58GXWIZSnV/PruTSwnEpyfVDVDBLyBNIPVabV0a2ra0HQZfHKxvMZNAPN2bpcBLPMubDZEWCcw6XdkOKPyZ9aJ7PEv5i7t6tg3MRR62YwroREHQVedCcRInnBFExQMOrZe/hTY75Xydk9yuIST4VbMO0CuttVz4aE=-----END PKCS7-----
">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</p>
<div class="toc">
@(repeat)
@TOC
@(end)
</div>
@(repeat)
@BODY
@(first)
@(end)
<div class="disambiguations">
@(repeat)
<a name="@{d-tag}">
  <p>Topics matching <tt>@(hash-revget symhash d-tag)</tt>:
  <dl>
@ (repeat :counter (n 1))
    <dt><a href="#@{n-tag}">@n:</a> @[tochash n-tag]</dt>
@ (end)
  </dl>
</a>
@(end)
</div>
</body>
</html>
@(end)
@(do (let ((ignames '("*-1" "*-2" "*-20"
                      "*0" "*1" "*2" "*99"
                      "*n" "*r" "*v"
                      "--args" "--eargs" "-C"
                      ".."
                      "TXR_COMPAT"
                      "buf-get-" "buf-put-"))
           (imgsyms (hash-list (append-each* ((entry [remove-if (op equal "pub")
                                                                (package-alist)
                                                                car])
                                              (pkg-name [mapcar car entry])
                                              (pkg [mapcar cdr entry]))
                                 (let ((fn (casequal pkg-name
                                             (("usr" "keyword")
                                              (fun tostringp))
                                             (t (opip tostringp
                                                      (join-with ":" pkg-name))))))
                                   (mapcar fn (package-symbols pkg)))))))
       (each ((sym ignames))
         (del [symhash sym]))
       (let ((missing (hash-diff symhash imgsyms)))
         (dohash (sym val missing)
           (format *stderr* "~a: missing from image\n" sym)))))