-
Notifications
You must be signed in to change notification settings - Fork 2
/
ngarchiver.d
1514 lines (1329 loc) · 45.8 KB
/
ngarchiver.d
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Program to convert newsgroup postings to html files.
*/
/* Better formatting:
* https://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
* Message Threading:
* https://www.jwz.org/doc/threading.html
*/
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.ctype;
import std.uri;
import std.file;
import std.stdio;
import std.string;
import std.conv;
import std.format;
import std.array;
import std.utf;
import std.outbuffer;
import std.path;
import undead.date;
version=READPHP;
immutable stylesheet = "https://www.digitalmars.com/forum.css";
immutable printsheet = "https://www.digitalmars.com/forum-print.css";
// Do not write html files from before this date
//immutable pivotdate = "Aug 1, 2001";
//immutable pivotdate = "Jan 1, 2014";
//immutable pivotdate = "Feb 1, 2016";
//immutable pivotdate = "Feb 1, 2017";
immutable pivotdate = "Feb 1, 2022";
class Posting
{
string filename;
string[] lines;
string from;
string date;
string[] msg;
string subject;
string newsgroups;
string[] refs;
Posting[] replies; // Postings that reply to this
string boundary;
string msgid;
Posting L,R,U,D;
int nmessages = 1; // number of messages in this thread
int counted;
int written;
int tocwritten;
d_time pdate; // date[] converted to time_t
d_time most_recent_date; // time of most recent reply
string shortdate; // date[] converted to canonical, short form
this(string filename)
{
this.filename = filename;
}
}
File[int] indexfiles; // index files, key type is the year
int[string] msgid2num; // from message id to message number
Posting[] postings;
int main(string[] args)
{
auto year = undead.date.yearFromTime(undead.date.getUTCtime());
if (args.length != 5)
{
writefln("Usage: ngarchiver fromdir todir sitedir ngdir");
/*
* fromdir = directory of where to read the ng postings
* todir = directory of where to write the html files
* sitedir = directory where the html files will reside on the web site
* ngdir = subdirectory to append to fromdir, todir and sitedir
*/
exit(1);
}
auto fromdir = args[1];
auto todir = args[2];
auto sitedir = args[3];
auto ngdir = args[4];
auto fromdirng = std.path.buildPath(fromdir, ngdir);
string todirng;
string sitedirng;
if (ngdir == "D")
{ todirng = todir;
sitedirng = sitedir;
}
else
{ todirng = std.path.buildPath(todir, ngdir);
sitedirng = std.path.buildPath(sitedir, ngdir);
}
writefln("fromdirng = %s", fromdirng);
writefln("todirng = %s", todirng);
writefln("sitedirng = %s", sitedirng);
writefln("Getting file names...");
// Get all the files in directory fromdirng into files[]
string[] files = listdir(fromdirng);
writefln("%s files", files.length);
postings = filesToPostings(files);
writefln("Reading postings...");
readPostings(fromdirng, postings);
string newsgroup;
foreach (size_t n, Posting posting; postings)
{
if (!posting)
continue;
if (posting.lines.length == 0)
continue;
// Parse the file
foreach (size_t i, string line; posting.lines)
{
if (std.string.indexOf(line, "From: ") == 0)
posting.from = line[6 .. line.length];
if (std.string.indexOf(line, "Date: ") == 0)
{ posting.date = line[6 .. line.length];
posting.pdate = undead.date.parse(posting.date);
posting.most_recent_date = posting.pdate;
posting.shortdate = undead.date.toDateString(posting.pdate)[4 .. $];
if (year == undead.date.yearFromTime(posting.pdate))
posting.shortdate = posting.shortdate[0 .. $ - 5];
}
if (std.string.indexOf(line, "Subject: ") == 0)
posting.subject = line[9 .. line.length];
if (std.string.indexOf(line, "Newsgroups: ") == 0)
{ posting.newsgroups = line[12 .. line.length];
// If more than one, pick first one
auto j = std.string.indexOf(posting.newsgroups, ',');
if (j > 0)
posting.newsgroups = posting.newsgroups[0 .. j];
if (!newsgroup && j <= 0)
newsgroup = posting.newsgroups;
}
if (std.string.indexOf(line, "Message-ID: ") == 0)
{ posting.msgid = line[12 .. line.length];
msgid2num[posting.msgid] = cast(int)n;
}
if (std.string.indexOf(line, "References: ") == 0)
{ string refs = line[12 .. line.length];
posting.refs = std.string.split(refs);
// Might be continued on next line(s)
for (auto j = i + 1; j < posting.lines.length; ++j)
{
auto rline = posting.lines[j];
if (rline.length > 2 &&
(rline[0] == ' ' || rline[0] == '\t'))
{
posting.refs ~= std.string.split(rline[1 .. $]);
}
else
break;
}
}
auto b = std.string.indexOf(line, "boundary=");
if (b >= 0)
{ b += 9; // skip over 'boundary='
if (line[b] == '"')
{
++b;
auto e = std.string.indexOf(line[b .. line.length], '"');
if (e >= 0)
posting.boundary = line[b .. b + e];
}
else
posting.boundary = line[b .. $];
}
if (line.length == 0)
{
posting.msg = posting.lines[i + 1 .. posting.lines.length];
break;
}
}
if (posting.refs.length == 0 &&
std.string.indexOf(posting.subject, "Re: ") == 0)
{
/* It's a reply, but there are no references.
* Try to find its antecedent.
*/
//writefln("\n%s %s", n, posting.subject);
for (size_t m = n; m--; )
{
auto p = postings[m];
if (p && p.subject == posting.subject[4 .. $])
{
posting.refs = new string[1];
posting.refs[0] = p.msgid;
//writefln(" found it %s", m);
break;
}
}
}
version (none)
{
writefln("from: %s", posting.from);
foreach (string line; posting.msg)
{
writefln("--> %s", line);
}
}
extractMsg(posting, posting.msg);
}
// Fill in replies[]
foreach (Posting posting; postings)
{
if (!posting)
continue;
int mostrecent = 0;
foreach (rf; posting.refs)
{
auto pn = rf in msgid2num;
if (pn && *pn > mostrecent)
mostrecent = *pn;
}
auto p = postings[mostrecent];
if (p)
{
p.replies ~= posting;
}
}
writefln("Writing HTML files...");
auto fpindex = File(std.path.buildPath(todirng, "index.html"), "w");
header(fpindex, "news.digitalmars.com - " ~ newsgroup, null, null, null, null, amazonDP(postings.length));
indexfiles[year] = fpindex;
auto fpftp = File(std.path.buildPath(todirng, "put.ftp"), "w");
version(none)
{
fpftp.writefln("name");
fpftp.writefln("password");
fpftp.writefln("bin");
}
fpftp.writefln("cd %s", sitedirng);
fpftp.writefln("put index.html");
static pivot = d_time_nan;
if (pivot == d_time_nan)
{
pivot = undead.date.parse(pivotdate);
}
string prev; // previous thread filename
string next; // next thread filename
string prevTitle;
string nextTitle;
for (size_t i = postings.length; i--;)
{
//printf("posting[%d]\n", i);
Posting posting = postings[i];
if (!posting)
continue;
if (posting.refs.length == 0) // if posting is start of a thread
{
// Find [next] posting
next = null;
for (size_t j = i; j--;)
{
Posting posting2 = postings[j];
if (posting2 && posting2.refs.length == 0)
{
next = toHtmlFilename(posting2);
nextTitle = posting2.subject;
break;
}
}
string fname = toHtmlFilename(posting);
posting.nmessages = 1 + countReplies(posting);
if (posting.most_recent_date > pivot)
{ // Write out the html file
auto fp = new OutBuffer();
header(fp, posting.newsgroups ~ " - " ~ posting.subject, prev, next, prevTitle, nextTitle, amazonDP(i));
if (!posting.tocwritten)
{
fp.writefln("<div id=\"PostingTOC\">");
fp.writefln("<ul>");
toTOC(fp, posting, 0);
fp.writefln("</ul>");
fp.writefln("</div>");
}
toHTML(fp, posting, posting);
google(fp);
footer(fp);
auto bytes = fp.toBytes();
auto n = std.path.buildPath(todirng, fname);
// Only write file if it is different - saves the SSD drive
if (!std.file.exists(n) ||
cast(ubyte[])std.file.read(n) != bytes[])
{
//writeln("file is different");
std.file.write(n, bytes);
}
}
prev = fname;
prevTitle = posting.subject;
if (posting.most_recent_date > pivot)
fpftp.writefln("put %s", fname); // append to put.ftp
// Determine year of posting
int pyear = year;
if (postings.length > 1000)
// if lots of posts, split into years
pyear = undead.date.yearFromTime(posting.most_recent_date);
if (!(pyear in indexfiles))
{ // Create new index file
string indexfilename = std.string.format("index%d.html", pyear);
fpindex = File(std.path.buildPath(todirng, indexfilename), "w");
header(fpindex, "news.digitalmars.com - " ~ newsgroup, null, null, null, null, amazonDP(pyear));
indexfiles[pyear] = fpindex;
fpftp.writefln("put %s", indexfilename);
}
// Add posting to index file
fpindex = indexfiles[pyear];
fpindex.writefln("<tt>%s</tt> ", posting.shortdate);
fpindex.writefln("<a href=\"%s\">", fname);
escapeHTML(fpindex, posting.subject);
fpindex.writefln("</a> <small>(%s)</small><br>\n", posting.nmessages);
}
}
writefln("done writing html");
fpftp.writefln("bye");
fpftp.close();
int[] years = indexfiles.keys;
years.sort;
foreach (y1, fp; indexfiles)
{
fp.writefln("<br>Other years:<br>");
foreach_reverse (y; years)
{
if (y1 == y)
fp.writefln("%s ", y);
else if (y == year)
{
fp.writefln("<a href=\"index.html\">%s</a> ", y);
}
else
{
fp.writefln("<a href=\"index%s.html\">%s</a> ", y, y);
}
}
google(fp);
footer(fp);
fp.close();
}
writefln("Done");
return 0;
}
/****************************************************
* Determine which of the files in files[] are postings,
* and return that subset.
* Params:
* files = array of file names
* Returns:
* subset of files[] that are possibly postings
*/
Posting[] filesToPostings(string[] files)
{
Posting[] postings;
postings.length = files.length;
Lfiles:
foreach (filename; files)
{
// Posting filenames are simply numbers, incremented sequentially
if (filename.length > 8)
continue; // more than 99,999,999 articles? No way
if (filename.length > 0 && filename.length == '0')
continue; // no leading '0' in filename
foreach (c; filename)
{
if (!core.stdc.ctype.isdigit(c))
continue Lfiles;
}
auto n = atoi(filename);
if (toString(n) != filename)
continue;
if (n >= postings.length)
postings.length = cast(size_t)(n + 1);
postings[cast(size_t)n] = new Posting(filename);
}
return postings;
}
/**************************************
* Read files in postings, then split into lines[].
* Params:
* fromdirng = path to where the posting files are
* postings = one posting per file
* Output:
* postings[].lines[] are set
*/
void readPostings(string fromdirng, Posting[] postings)
{
foreach (Posting posting; postings)
{
if (!posting)
continue;
std.stdio.writef("%s\r", posting.filename);
auto filebody = cast(string)std.file.read(std.path.buildPath(fromdirng, posting.filename));
if (filebody.length == 0)
continue;
posting.lines = splitlines(filebody);
}
}
/*******************************
* Transitively count up all the replies to p.
*/
int countReplies(Posting p)
{
assert(p);
if (p.counted)
return 0;
p.counted = 1;
//writefln("counting ", p.filename);
// Count all replies
int n = cast(int)p.replies.length;
foreach (reply; p.replies)
{
n += countReplies(reply);
}
return n;
}
/*******************************
* Write p to table of contents
*/
void toTOC(R)(ref R fp, Posting p,int depth)
{
assert(p);
if (p.tocwritten)
return;
p.tocwritten = 1;
//writefln("TOC Writing ", p.filename);
try
{
fp.writefln("<li>");
fp.writefln("<a href=\"#N%s\">", p.filename);
/* Strip "" and email address from p.from
*/
auto from = p.from;
if (from.length > 4)
{
if (from[0] == '"')
{
auto i = lastIndexOf(from, '"');
if (i > 1)
from = from[1 .. i];
}
else if (from[$ - 1] == '>')
{
auto i = indexOf(from, '<');
if (i > 0)
{
if (from[i - 1] == ' ')
--i;
from = from[0 .. i];
}
}
}
escapeHTML(fp, from);
fp.writefln("</a>");
int totalLines, quotedLines;
auto firstline = messageStats(p.msg, totalLines, quotedLines);
fp.writefln(" (%d/%d)", totalLines - quotedLines, totalLines);
fp.writefln(" %s", p.shortdate);
if (firstline.length > 72)
fp.writefln(" <small>%s...</small>", firstline[0 .. 72]);
else
fp.writefln(" <small>%s</small>", firstline);
fp.writefln("</li>");
}
catch (Exception o)
{
writefln("error writing posting %s %s", p.filename, o);
}
// Append all replies
bool ol;
Posting U;
foreach (posting; p.replies)
{
if (posting.tocwritten)
continue;
if (!ol)
{ ol = true;
fp.writefln("<ul>");
}
if (!p.R)
p.R = posting;
posting.L = p;
posting.U = U;
toTOC(fp, posting, depth + 1);
if (U)
U.D = posting;
U = posting;
}
if (ol)
fp.writefln("</ul>");
}
/***************************************
* Write out p and all its descendents to fp.
*
* Params:
* pstart = posting that is the start of this thread
*/
void toHTML(R)(ref R fp, Posting p, Posting pstart)
{
assert(p);
if (p.written)
return;
p.written = 1;
//writefln("Writing ", p.filename);
try
{
fp.writef( `<div id="Posting">`);
scope (success) fp.writef( "</div>");
{
fp.writef( "<div id=\"PostingHeading\">");
scope (success) fp.writefln("</div>");
fp.writef( `<a name="N%s">`, p.filename);
scope (success) fp.writef( "</a>");
if (p.U)
fp.writef( "<a href=\"#N%s\"><img src=\"https://www.digitalmars.com/blue-up.png\" border=0 alt=\"prev sibling\"></a> ", p.U.filename);
else
fp.writef( "<img src=\"https://www.digitalmars.com/grey-up.png\" border=0> ");
if (p.D)
fp.writef( "<a href=\"#N%s\"><img src=\"https://www.digitalmars.com/blue-down.png\" border=0 alt=\"next sibling\"></a> ", p.D.filename);
//fp.writef( "<a href=\"#N%s\">↓</a> ", p.D.filename);
else
fp.writef( "<img src=\"https://www.digitalmars.com/grey-down.png\" border=0> ");
if (p.L)
fp.writef( "<a href=\"#N%s\"><img src=\"https://www.digitalmars.com/blue-left.png\" border=0 alt=\"parent\"></a> ", p.L.filename);
else
fp.writef( "<img src=\"https://www.digitalmars.com/grey-left.png\" border=0> ");
if (p.R)
fp.writef( "<a href=\"#N%s\"><img src=\"https://www.digitalmars.com/blue-right.png\" border=0 alt=\"reply\"></a> ", p.R.filename);
else
fp.writef( "<img src=\"https://www.digitalmars.com/grey-right.png\" border=0> ");
escapeHTML(fp, p.from);
version (READPHP)
{
fp.writef(
" <a href=\"https://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=%s&artnum=%s%s",
p.newsgroups,
p.filename,
"\"> writes</a>:");
}
else
{
fp.writef(
" <a href=\"https://www.digitalmars.com/drn-bin/wwwnews?%s/%s%s",
std.uri.encodeComponent(p.newsgroups),
p.filename,
"\"> writes</a>:");
}
}
{
fp.writefln(`<pre class="PostingBody">`);
scope (success) fp.writefln("</pre>");
void writeQuote(size_t first, size_t last)
{
// Remove leading blank lines
while (first <= last)
{
if (p.msg[first].length)
break;
first++;
}
// Remove trailing blank lines
while (first <= last)
{
if (p.msg[last].length)
break;
last--;
}
if (first > last)
return;
bool quote = false;
int quotefirst;
int quotelast;
foreach (i, ref line; p.msg[first .. last + 1])
{
if (line.length && line[0] == '>')
{
if (!quote)
{ quote = true;
quotefirst = cast(int)i;
}
line = line[1 .. $];
}
else if (line.length >= 2 && line[0] == ' ' && line[1] == '>')
{
if (!quote)
{ quote = true;
quotefirst = cast(int)i;
}
line = line[2 .. $];
}
else
{
if (quote)
{
fp.writefln("<pre class=\"PostingQuote\">");
writeQuote(first + quotefirst, first + i - 1);
fp.writefln("</pre>");
quote = false;
if (line.length == 0)
continue; // no blank line needed after quoted text
}
auto line2 = line;
while (line2.length > 80)
{ // Wrap long lines
auto j = std.string.lastIndexOf(line2[0..80], ' ');
if (j < 20)
{
j = std.string.indexOf(line2[20..$], ' ');
if (j == -1 || j == line2.length - 1)
break;
}
writeLine(fp, line2[0 .. j]);
fp.writefln("");
line2 = line2[j + 1 .. $];
}
writeLine(fp, line2);
fp.writefln("");
}
}
if (quote)
{
fp.writefln("<pre class=\"PostingQuote\">");
writeQuote(quotefirst + first, last);
fp.writefln("</pre>");
}
}
if (p.msg.length)
writeQuote(0, p.msg.length - 1);
}
fp.writef( `<div id="PostingFooting">`);
fp.writefln(" %s", p.shortdate);
fp.writefln("</div>");
}
catch (Exception o)
{
writefln("error writing posting %s %s", p.filename, o);
}
// Append all replies
foreach (posting; p.replies)
{
if (posting.written)
continue;
toHTML(fp, posting, pstart);
d_time t = undead.date.parse(posting.date);
if (t > pstart.most_recent_date)
pstart.most_recent_date = t;
}
}
/*******************************
* Rewrites msg[] to be subset of lines
* that form the message body.
*/
void extractMsg(Posting p, ref string[] msg)
{
if (!msg.length)
return;
int first = int.max;
int last = -1;
if (p.boundary.length)
{ // Only do the first section
int state;
foreach (int i, string line; msg)
{
if (line.length > 2 && line[2 .. line.length] == p.boundary)
{ if (state)
break;
state++;
}
else if (state)
{
if (i < first)
first = i;
if (i > last)
last = i;
}
}
}
else
{
foreach (int i, string line; msg)
{
// Look for 'begin OOO filename', and ignore it
if (line.length > 9 &&
line[0 .. 6] == "begin " &&
isdigit(line[6]))
{
if (first == int.max)
{
msg = msg[0 .. 0];
return;
}
}
if (i < first)
first = i;
if (i > last)
last = i;
}
}
foreach (i; first .. last + 1)
{
string line = msg[i];
if (std.string.indexOf(line, "Content-Type: ") == 0)
++first;
else if (std.string.indexOf(line, "Content-Transfer-Encoding: ") == 0)
++first;
else
break;
}
msg = msg[first .. last + 1];
}
/*****************************************
* Get message stats.
*/
string messageStats(string[] msg, out int totalLines, out int quotedLines)
{
string firstline;
foreach (line; msg)
{
if (line.length == 0)
continue;
++totalLines;
if (line[0] == '>' ||
(line.length > 1 && line[0] == ' ' && line[1] == '>'))
{
if (line[0] == '>' && line.length > 1 ||
line.length > 2)
{
++quotedLines;
if (totalLines - quotedLines <= 2)
firstline = null;
}
else
--totalLines; // blank line, do not count it
}
else if (!firstline)
firstline = line;
}
assert(quotedLines <= totalLines);
assert(totalLines <= msg.length);
return firstline;
}
void header(R)(ref R fp, string title, string prev, string next, string prevTitle, string nextTitle, string dp)
{
if (prevTitle.length == 0)
prevTitle = "previous topic";
if (prevTitle.length == 0)
prevTitle = "next topic";
fp.writefln(`
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>`);
escapeHTML(fp, title);
fp.writefln(`
</title>
<link rel="stylesheet" type="text/css" href="%s" />
<link rel="stylesheet" type="text/css" href="%s" media="print" />
</head>
<body>
<div id="heading">
<a href="https://www.digitalmars.com/"><img src="https://www.digitalmars.com/dmlogo.gif" BORDER=0 WIDTH=270 HEIGHT=53 ALT="www.digitalmars.com"></a>
<a href="https://www.digitalmars.com/" title="Digital Mars"><img src="https://www.digitalmars.com/home.png" border=0></a>
<a href="https://www.digitalmars.com/advancedsearch.html" title="Search Digital Mars web site"><img src="https://www.digitalmars.com/search.png" border=0></a>
<a href="https://www.digitalmars.com/NewsGroup.html" title="News Groups"><img src="https://www.digitalmars.com/news.png" border=0></a>
<a href="https://www.digitalmars.com/d/" title="D Programming Language"><img src="https://www.digitalmars.com/d.png" border=0></a>
<a href="https://www.digitalmars.com/download/freecompiler.html" title="C/C++ compilers">C & C++</a>
<a href="https://www.digitalmars.com/dscript/" title="DMDScript">DMDScript</a>
`, stylesheet, printsheet);
if (prev || next)
{
fp.writefln(" <a href=\"index.html\" title=\"topic index\"><img src=\"https://www.digitalmars.com/blue-index.png\" border=0></a>");
if (prev)
{ fp.writef( `<a href="%s" title="`, prev);
escapeHTML(fp, prevTitle);
fp.writefln(`"><img src="https://www.digitalmars.com/blue-left.png" border=0></a>`);
}
else
fp.writefln("<img src=\"https://www.digitalmars.com/grey-left.png\" border=0>");
if (next)
{ fp.writef( `<a href="%s" title="`, next);
escapeHTML(fp, nextTitle);
fp.writefln(`"><img src="https://www.digitalmars.com/blue-right.png" border=0></a>`);
}
else
fp.writefln("<img src=\"https://www.digitalmars.com/grey-right.png\" border=0>");
}
fp.writefln("%s%s%s%s%s", `
</div>
<div id="navigation">
<div class="navblock">
<form method="get" action="https://www.google.com/search">
<div style="text-align:center">
<input id="q" name="q" size="10" value="Search" onFocus='if(this.value == "Search"){this.value="";}'>
<input type="hidden" id="domains" name="domains" value="www.digitalmars.com">
<input type="hidden" id="sitesearch" name="sitesearch" value="www.digitalmars.com/d/archives">
<input type="hidden" id="sourceid" name="sourceid" value="google-search">
<input type="submit" id="submit" name="submit" value="Go">
</div>
</form>
</div>
<div class="navblock">
<h2>D Programming</h2>
<ul>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D">digitalmars.D</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/announce">digitalmars.D.announce</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/learn">digitalmars.D.learn</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/ldc">digitalmars.D.ldc</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/bugs">digitalmars.D.bugs</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/dtl">digitalmars.D.dtl</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/ide">digitalmars.D.ide</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/debugger">digitalmars.D.debugger</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/internals">digitalmars.D.internals</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/D/dwt">digitalmars.D.dwt</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/dips/discussion">digitalmars.dips.discussion</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/dips/ideas">digitalmars.dips.ideas</a></li>
<li><a href="https://www.digitalmars.com/d/archives/D/gnu">D.gnu</a></li>
<li><a href="https://www.digitalmars.com/d/archives/">D</a></li>
</ul>
</div>
<div class="navblock">
<h2>C/C++ Programming</h2>
<ul>
<li><a href="https://www.digitalmars.com/d/archives/c++">c++</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/announce">c++.announce</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/atl">c++.atl</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/beta">c++.beta</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/chat">c++.chat</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/command-line">c++.command-line</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/dos">c++.dos</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/dos/16-bits">c++.dos.16-bits</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/dos/32-bits">c++.dos.32-bits</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/idde">c++.idde</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/mfc">c++.mfc</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/rtl">c++.rtl</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/stl">c++.stl</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/stl/hp">c++.stl.hp</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/stl/port">c++.stl.port</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/stl/sgi">c++.stl.sgi</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/stlsoft">c++.stlsoft</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/windows">c++.windows</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/windows/16-bits">c++.windows.16-bits</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/windows/32-bits">c++.windows.32-bits</a></li>
<li><a href="https://www.digitalmars.com/d/archives/c++/wxwindows">c++.wxwindows</a></li>
</ul>
</div>
<div class="navblock">
<h2>Other</h2>
<ul>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/empire">digitalmars.empire</a></li>
<li><a href="https://www.digitalmars.com/d/archives/digitalmars/DMDScript">digitalmars.DMDScript</a></li>
<li><a href="https://www.digitalmars.com/d/archives/electronics">electronics</a></li>
</ul>
</div>
<div class="navblock">
<script type="text/javascript"><!--
google_ad_client = "pub-5628673096434613";
google_ad_width = 120;
google_ad_height = 90;
google_ad_format = "120x90_0ads_al_s";
google_ad_channel ="7651800615";
google_color_border = "336699";
google_color_bg = "C6C8EB";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript" src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<hr>
<center>
<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=tf_til&ad_type=product_link&tracking_id=classicempire&marketplace=amazon®ion=US&placement=`,
dp,
`&asins=`,
dp,
`&linkId=GPBMDJNW4AUOBDFQ&show_border=true&link_opens_in_new_window=true"></iframe>
</center>
</div>
</div>
<div id="sidebar">
<!-- Google ad -->
<script type="text/javascript"><!--
google_ad_client = "pub-5628673096434613";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="7651800615";
google_page_url = document.location;