-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocindex.t
More file actions
472 lines (361 loc) · 13 KB
/
Copy pathdocindex.t
File metadata and controls
472 lines (361 loc) · 13 KB
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#charset "us-ascii"
/*
* Copyright (c) 1999, 2002 by Michael J. Roberts. Permission is
* granted to anyone to copy and use this file for any purpose.
*
* This is a starter T3 source file. This is designed for a project
* that doesn't require any of the standard TADS 3 adventure game
* libraries.
*
* To compile this game in TADS Workbench, open the "Build" menu and
* select "Compile for Debugging." To run the game, after compiling it,
* open the "Debug" menu and select "Go."
*
* This starter file is intended for people who want to use T3 to create
* projects that don't fall into the usual TADS 3 adventure game
* patterns, so it doesn't include any of the standard libraries. If
* you want to create a more typical Interactive Fiction project, you
* might want to create a new project, and select the "introductory" or
* "advanced" option when the New Project Wizard asks you what kind of
* starter game you'd like to create.
*/
#include <tads.h>
#include <file.h>
#define gFile globals.currentFile
#define gAnchor globals.currentAnchor
#define gEntries globals.entries
#define gHeading globals.heading
#define gMainHeading globals.mainHeading
#define gExtension globals.extension
/*
* The main entrypoint - the T3 virtual machine calls this function to
* start the program running. 'args' is a list of strings giving the
* command-line arguments that the user specified, if any.
*/
main(args)
{
parseFiles();
writeIndex();
"All done!\b";
}
parseFiles()
{
local dir = FileName.fromUniversal('docs/manual');
// local dir = new FileName('manual');
// local dir = new FileName(dirPath);
local files = dir.listDir().subset({f: f.getBaseName().endsWith('htm')});
files = files.subset(
{f: globals.excludedFiles.indexOf(f.getBaseName()) == nil
});
for(local f in files)
parseFile(f);
/* Then index the extension documentation */
gExtension = true;
dir = FileName.fromUniversal('extensions/docs');
files = dir.listDir().subset({f: f.getBaseName().endsWith('htm')});
for(local f in files)
parseFile(f);
}
parseFile(sourceFile)
{
gFile = sourceFile.getBaseName();
gAnchor = nil;
"Parsing <<gFile>> \n";
local f = File.openTextFile(sourceFile, FileAccessRead);
local str;
local codeSample = nil;
do
{
str = f.readFile();
if(str != nil)
{
if(str.find('<div class="code">')
|| str.find('<div class="cmdline">'))
codeSample = true;
if(codeSample && str.find('</div>'))
codeSample = nil;
if(!codeSample)
parseLine(str);
}
} while(str != nil);
codeSample = nil;
f.closeFile();
}
parseLine(str)
{
/*
* First look for a new anchor name; if we find one it becomes the current
* anchor name.
*/
local idx = str.find('<a name');
while(idx)
{
local idx2 = str.find('>', idx);
local idx3 = str.find('=', idx);
local anc = str.substr(idx3 + 1, idx2 - idx3 - 1);
anc = anc.findReplace('"', '', ReplaceAll).trim();
anc = anc.findReplace('\'','', ReplaceAll);
gAnchor = anc;
/* if the anchor ends in idx, it's something we want to index */
if(anc.endsWith('idx'))
{
local idx4 = str.find('</a>', idx2);
if(idx4)
{
local ename = str.substr(idx2 + 1, idx4 - idx2 - 1);
/*
* If our ename starts with < we probably enclose another tag,
* which will be indexed below, so we shan't create a
* duplicate entry here. Otherwise, create an index entry for
* the tag. Likewise if we're immediately preceding by an
* opening heading tag, then this entry will be indexed by
* that tag, so we won't crete a duplicat entry here.
*
*/
if(!ename.startsWith('<')
&& !(idx > 4 && str.substr(idx - 4, 2) == '<h'))
gEntries.append(new IndexEntry(ename, gFile, anc, gHeading));
}
}
idx = str.find('<a name', idx2);
}
/*
* For each of the tags we're interested in, go through the current line
* searching for the tags and create a new IndexEntry for each one found.
*/
for(local tag in ['h1', 'h2', 'h3', 'h4', 'h5', 'b', 'strong'])
{
local openTag = '<' + tag + '>';
local closeTag = '</' + tag + '>';
local idx2;
/*
* A line may contain more than one tag of any particular kind, so
* once we've processed one, we need to keep on looking for the next
*/
idx = str.find(openTag);
while(idx)
{
idx2 = str.find(closeTag, idx);
/*
* If the closing tag is missing, we can't meaningfully continue
* to process this kind of tag.
*/
if(idx2 == nil)
break;
local ename = str.substr(idx + openTag.length, idx2 - idx -
openTag.length);
/*
* Reset our starting idx to ensure we find a different tag next
* time round.
*/
idx = idx2;
/*
* If one HTML tag encloses another, we want to strip the enclosed
* tag away from the index entry name
*/
ename = deNest(ename);
/* Note the most recent heading */
local heading = gHeading;
/*
* If we're processing a top-level heading, note that this is the
* most recent main heading.
*/
if(tag == 'h1')
gMainHeading = ename;
if(openTag.startsWith('<h'))
{
/*
* If we're a heading tag, note that our name is the most
* recent heading name.
*/
gHeading = ename;
/*
* And then use the most recent main heading (<h1>) name do
* describe the heading we're under.
*/
heading = gMainHeading;
}
if(!ename.startsWith('>') && !ename.startsWith('/'))
gEntries.append(new IndexEntry(ename, gFile, gAnchor, heading));
idx = str.find(openTag, idx);
}
}
}
/*
* Remove a nested tag sequence from a name included in another tag sequence.
*
* If one HTML tag encloses another, we want to strip the enclosed tag away
* from the index entry name
*/
deNest(ename)
{
if(ename.startsWith('<'))
{
local idx2 = ename.find('>');
ename = ename.substr(idx2 + 1);
idx2 = ename.find('<');
if(idx2)
ename = ename.substr(1, idx2 - 1);
}
return ename;
}
class IndexEntry: object
fileName = nil
anchor = nil
name = nil
entryStr = nil
heading = nil
sortName = ''
construct(name_, file_, anchor_, heading_)
{
local extensionName = '';
name = name_.trim();
fileName = file_;
if(gExtension)
{
fileName = '../../extensions/docs/' + fileName;
extensionName = ' <i>[' + file_.findReplace('.htm','') + ' extension]</i>';
}
anchor = anchor_;
heading = heading_.trim();
local isMainHeading = (name == heading);
/*
* Strip the definine article off the front of the name for the
* purposes of sorting and listing
*/
if(name.toLower.startsWith('the '))
{
name = name.substr(5);
}
entryStr = '<a href = "' + fileName;
if(anchor)
entryStr += ('#' + anchor);
entryStr += ('">' + name + '</a>');
sortName = name;
if(!isMainHeading)
{
entryStr += (' (' + heading + ')');
sortName += heading;
}
entryStr += extensionName;
}
;
writeIndex()
{
gEntries.sort(SortAsc, {a, b: a.sortName.toLower > b.sortName.toLower ? 1 : -1} );
local lastName = nil;
local lastEntry = nil;
local fspec = new FileName('docs/manual', 'manual_idx.html');
local f = File.openTextFile(fspec, FileAccessWrite);
"Writing manual_idx.html\n";
/* Write the HTML file header */
f.writeFile('<html>');
f.writeFile('<head>');
f.writeFile('<title>Index</title>');
f.writeFile('<link rel="stylesheet" href="sysman.css" type="text/css">');
f.writeFile('</head>');
f.writeFile('<body>');
f.writeFile('<div class="topbar"><img src="topbar.jpg" border=0></div>');
f.writeFile('<div class="nav"><a class="nav" href="toc.htm">Table of
Contents</a> | ');
f.writeFile('<a class="nav" href="final.htm">Final Moves</a> > Index');
f.writeFile('<br><span class="navnp"><a class="nav" href="changelog.htm"><i>Prev:</i>
Change Log</a></span>');
f.writeFile('</div>');
f.writeFile('<div class="main">');
f.writeFile('<h1>Adv3Lite Manual Index</h1>');
f.writeFile('<p>');
/*
* First write an index to the index; in other words, go through each
* entry, noting where the first letter of the name changes. Where it
* changes, create a hyperlinked reference to the initial letter.
*/
for(local e in gEntries)
{
if(lastName == nil
|| lastName.substr(1, 1).toLower != e.name.substr(1, 1).toLower)
{
local initial = e.name.substr(1, 1).toUpper();
if(initial == '&')
initial = '<';
f.writeFile('<a href="#' + initial + '">' + initial + '</a> ');
lastName = e.name;
}
}
f.writeFile('<p>');
for(local e in gEntries)
{
if(lastName == nil
|| lastName.substr(1, 1).toLower != e.name.substr(1, 1).toLower)
{
f.writeFile('<p>');
local initial = e.name.substr(1, 1).toUpper();
if(initial == '&')
initial = '<';
f.writeFile('<a name="' + initial + '"><h2>' + initial +
'</h2></a>' );
}
/* Avoid writing duplicate entries */
if(e.entryStr != lastEntry)
{
f.writeFile(e.entryStr + '<br>');
lastEntry = e.entryStr;
}
lastName = e.name;
}
/* Write the HTML file footer */
f.writeFile('</div>');
f.writeFile('<hr class="navb"><div class="navb">');
f.writeFile('<i>adv3Lite Library Manual</i><br>');
f.writeFile('<a class="nav" href="toc.htm">Table of
Contents</a> | ');
f.writeFile('<a class="nav" href="final.htm">Final Moves</a> > Index');
f.writeFile('<br><span class="navnp"><a class="nav" href="changelog.htm"><i>Prev:</i>
Change Log</a></span>');
f.writeFile('</div>');
f.writeFile('</body>');
f.writeFile('</html>');
/* Close the file */
f.closeFile();
}
globals: object
/* List of files that should not be indexed or are not worth indexing */
excludedFiles = [
'changelog.htm',
'action.htm',
'actor.htm',
'conclusion.htm',
'feedback.htm',
'index.htm',
'toc.htm',
'source.htm',
'docs-intro.htm',
'actionref.htm',
'begin.htm',
'core.htm',
'optional.htm'
]
/* The file currently being processed */
currentFile = nil
/* The most recently encountered anchor name */
currentAnchor = nil
/* Vector containing the index entries discovered */
entries = static new Vector(100)
/* The last heading encountered */
heading = nil
/* The last main heading (<h1>) encountered */
mainHeading = nil
/* Are we indexing an extension file? */
extension = nil
;
modify String
trim()
{
local s = self;
while(s.substr(1, 1) == ' ')
s = s.substr(2);
while(s.substr(-1, 1) == ' ')
s = s.substr(1, s.length - 1);
return s;
}
;