File: html.cpp

package info (click to toggle)
doc%2B%2B 3.2-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 1,844 kB
  • ctags: 1,925
  • sloc: cpp: 16,762; lex: 2,938; makefile: 278; java: 273; yacc: 139; perl: 20; sh: 17
file content (1484 lines) | stat: -rw-r--r-- 38,120 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
/*************************************************************************

    DOC++, a C++ (and C) documentation system for LaTeX and HTML

	    Copyright (C) 1996  Roland Wunderling,
				Malte Zoeckler


    DOC++ is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation. This program
    is distributed WITHOUT ANY WARRANTY; without even the implied
    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    If you intend to use DOC++ commercially on a regular basis you
    must contact the authors for an appropriate donation.

 *************************************************************************/


#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <iostream.h>
#include <iostream.h>

#include <sys/types.h>
#include <sys/stat.h>

#include "doc.h"
#include "java.h"
#include "gifs.h"
#include "classgraph.hh"
#include "McHashTable.h"
#include "McSorter.h"

#ifdef __BORLANDC__
#include <dir.h>
#endif
#ifdef __VISUALC__
#include <direct.h>
#endif

#define max(a,b) ((a)>(b) ? (a) : (b))

static McString banner;
static char *HTML_SUFFIX="html";

static McString indexHeader("<html><head><TITLE>Table of Contents</TITLE>"
			    "</head><BODY>\n");
static McString indexFooter("<I><A HREF=\"HIER.html\"> hierarchy of classes</A></I><P>");

static McString hierHeader("<html><head><TITLE>Hierarchy ClassDoc</TITLE></head>\n<BODY>\n");
static McString hierFooter("<I><A HREF=\"aindex.html\"> alphabetic index</A></I><P>");

static McString pageHeader("<body>\n");
static McString pageFooter("<I><A HREF=\"aindex.html\"> alphabetic index</A></I>  <I><A HREF=\"HIER.html\"> hierarchy of classes</A></I><P>");


int makedir(const char *d, int perm)
{
#ifdef __BORLANDC__
return mkdir(d);
#else
#ifdef __VISUALC__
return _mkdir(d);
#else
return mkdir(d,perm);
#endif
#endif
}

#define myisalnum(c) ((c>='a' && c<='z')||(c>='A' && c<='Z')||\
		      (c>='0' && c<='9')||c=='_'||c=='.'||c=='-')

char *makeFileName(const char* str)
{
    static McHashTable<char *,int> files(1);
    McString s,ls;
    int l=strlen(str);
    static int cnt=0;
    if (shortFilenames){
	s="f";
	cnt++;
	char buf[40];
	sprintf(buf,"%d",cnt);
	s+=buf;
    } else {
	for (int i=0 ; i<l ; i++){
	    if (myisalnum(str[i])){
	      char c=str[i];
	      s+=c;
	      if (c>='A' && c<='Z')
		c+=(((int)'a')-'A');
	      ls+=c;
	    }
	}
	char *tmp=strdup(ls);
	int *val=files.insert(tmp);	
	if (verb)
	    printf("Inserted %s, got %p (=%d)\n",(const char *)s,val,*val);	
	if (*val>1) {
	    free(tmp);
	    s+='.';
	    char buf[40];
	    sprintf(buf,"%d",*val);
	    s+=buf;
	}
	(*val)++;
    }
    s+=".";
    s+=HTML_SUFFIX;
    return strdup((const char *)s) ;
}

int subEntryIsToBeDocumented(Entry *entry)
{
    int toBeDocumented = 0;
    if (entry->protection!=PRIV || withPrivate) {
	if (entry->retrn.length()  ||
	    entry->param.size() || entry->author.length() ||
	    entry->see.size()   || entry->version.length())
	    toBeDocumented = 1;
	if (entry->doc.length() > entry->memo.length() || 
	    (entry->doc.length() == entry->memo.length() &&
	     entry->doc == (const char *)entry->memo))
	    toBeDocumented = 1;
    
	if (alwaysPrintDocSection)
	    toBeDocumented = 1;
    }

    return toBeDocumented;
}


/// Writes classgraphs. Either as text-graphs or as java-graphs.
class ClassGraphWriter
{
public:
    static void writeJava(FILE *f,Entry *e,int directOnly=1);
    static void writeText(FILE *f,Entry *e);
    static void write(FILE *f,Entry *e);
	static void writeImplements(FILE *f,Entry *e);
};


/// This class writes members.
class MemberWriter
{
protected:
    McString heading;
    int first;
    FILE *f;
    virtual char* startString() {return "<DL>";};
    virtual char* endString() {return "</DL>";};
    virtual void showSubMembers(Entry *);
    struct ListEntry {
	Entry* entry;
	int links;
	int withSub;
    };
    McDArray<ListEntry> list;
    virtual void writeMember(Entry *e, int links,int withSub=1);
    class EntryCompare {
    public:
	operator()(const ListEntry& l1,const ListEntry& l2) {
	    return stricmp(l1.entry->name,l2.entry->name);
	}
    };
public:
    virtual void sort() {
	EntryCompare comp;
	if (list.size())
	    ::sort((ListEntry *)list,list.size(),comp);
    }
    virtual void startList(FILE *f,char *heading,int withLinks);
    virtual void addMember(Entry *e, int links,int withSub=1) {
	ListEntry le;
	le.entry=e;
	le.links=links;
	le.withSub=withSub;
	list.append(le);
    }
    virtual void endList();
};

class MemberWriterTable : public MemberWriter
{
protected:
    virtual char* startString() {
	if (withBorders)
	    return "<TABLE BORDER>"; else  return "<TABLE>";
    };
    virtual char* endString() {return "</TABLE>";};
    virtual void writeMember(Entry *e, int links,int withSub=1);
public:
};

class SortedList : public MemberWriter
{
protected:
    struct ListEntry {
	char *string;
	char *name;
    };
    McDArray<ListEntry> list;
public:
    virtual void sort() {
	EntryCompare comp;
	if (list.size()>1)
	    ::sort((ListEntry *)list,list.size(),comp);
    }
    class EntryCompare {
    public:
	operator()(const ListEntry& l1,const ListEntry& l2) {
	    return stricmp(l1.name,l2.name);
	}
    };
    void addString(const char *name,const char *string);
    void write(FILE *f);
    ~SortedList();
};

void SortedList::write(FILE *f)
{
    for (int i=0 ; i<list.size() ; i++)
	fprintf(f,"%s",list[i].string);
}

void SortedList::addString(const char *name,const char *string)
{
    ListEntry le;
    le.string=strdup(string);
    le.name=strdup(name);
    list.append(le);
}

SortedList::~SortedList()
{
    for (int i=0 ; i<list.size() ; i++){
	if (list[i].string)
	    free(list[i].string);
	if (list[i].name)
	    free(list[i].name);
    }
}

void MemberWriter::showSubMembers(Entry *e)
{
    fprintf(f,"\n%s\n",startString());
    for (Entry *tmp=e->sub ; tmp ; tmp=tmp->next){
	writeMember(tmp,1);
    }
    fprintf(f,"\n%s\n",endString());
}

void printRefLabel(FILE *f,Entry *entry) 
{
    fprintf(f, "\n<A NAME=\"%s\">\n<A NAME =\"DOC.",(const char *)entry->name);
    entry->dumpNumber( f ) ;
    fprintf( f, "\">\n");
}

void MemberWriter::writeMember(Entry *entry,int link, int withSub)
{
    if (first) {
	fprintf(f,"%s\n%s",startString(),(const char *)heading);	
	first=0;
    }

    if (!subEntryIsToBeDocumented(entry) && link) 
	printRefLabel(f,entry);

    fprintf(f,"<DT>");
    if ( subEntryIsToBeDocumented(entry) && link) {
	fprintf( f, "<A HREF=\"#DOC." ) ;
	entry->dumpNumber( f ) ;
	fprintf( f, "\"> <IMG BORDER=0 SRC=icon1.gif></A> " ) ;
    } else if (entry->section!=MANUAL_SEC){
	fprintf(f,"<IMG SRC=icon2.gif> ");
    } else 
	fprintf(f,"<P>");
   
    char *args=entry->hargs;
    char *type=entry->htype;
    
    fprintf(f,"%s ",type); 
    fprintf(f,"<B>%s</B>",entry->hname);
    
    if (link)
	fprintf(f,"%s </B>\n <DD><I>%s</I>\n",
		args,
		(entry->hmemo));
    else
	fprintf(f,"%s\n",args);
    if (entry->sub && withSub)
	showSubMembers(entry);
}

void MemberWriter::startList(FILE *file,char *head,int)
{
    f=file;
    heading=head;
    first=1;
    list.resize(0);
}

void MemberWriter::endList()
{
    if (sortEntries) {
	sort();
    }
    for (int i=0 ; i<list.size() ; i++)
	writeMember(list[i].entry,list[i].links,list[i].withSub);
    
    if (!first)
	fprintf(f,"%s",endString());
}

void MemberWriterTable::writeMember(Entry *entry,int link, int /*withSub*/)
{
    if (first) {
	fprintf(f,"%s\n%s",startString(),(const char *)heading);	
	first=0;
    }
    fprintf(f,"<TR>");
    fprintf(f,"<TD VALIGN=top>");

    if (!subEntryIsToBeDocumented(entry) && link) 
	printRefLabel(f,entry);

    if (subEntryIsToBeDocumented(entry) && link) {
	fprintf( f, "<A HREF=\"#DOC." ) ;
	entry->dumpNumber( f ) ;
	fprintf( f, "\"> <IMG BORDER=0 SRC=icon1.gif></A> " ) ;
    } else if (entry->section!=MANUAL_SEC){
	fprintf(f,"<IMG SRC=icon2.gif> ");
    } else fprintf(f,"<P>");
    
    char *args=entry->hargs;
    char *type=entry->htype;
    
    fprintf(f,"%s",type); 
    fprintf(f,"</TD><TD>");
    fprintf(f,"<B>%s</B> %s<br>",entry->hname,args);
    
    if (link)
	fprintf(f,"\n<I>%s</I>\n",(entry->hmemo));
    if (entry->sub )
	showSubMembers(entry);
    fprintf(f,"</TD></TR>");  
}


void ClassGraphWriter::writeJava(FILE *f,Entry *entry,int directOnly)
{
    ClassGraph	cg( entry, 0 );
    ClassGraph*	cls = &cg ;
    cg.addBases() ;

    if (directOnly)
	cg.addDirectChilds() ;
    else
	cg.addAllChilds() ;

    McString classes,before,after,indent;
    char first=1;
    int numLines=0,longest=0;
    for( cls = cg.firstLine ; cls ; cls = cls->nextLine ){
	numLines++;    
	if (first)
	    first=0;
	else {
	    classes+=",";
	    before +=",";
	    after  +=",";
	    indent +=",";
	}
	if (cls->entry){
	    if (longest<cls->entry->name.size())
		longest=cls->entry->name.size();
	    
	    if (cls->entry->section==CLASS_SEC)
		classes+="C";
	    else
		classes+="I";
	    classes+=cls->entry->name;
	    classes+=",M";
	    classes+=cls->entry->fileName;
	} else {
	    if (longest<cls->name.size())
		longest=cls->name.size();
	    classes+="M"+cls->name;
	    classes+=",M";
	}
	before+="M"+cls->before;
	after+="M"+cls->after;
	char buf[20];
	sprintf(buf,"%d",cls->indent);
	indent+=buf;
    }
    
    fprintf(f,"<APPLET CODE=\"ClassGraph.class\" WIDTH=600 HEIGHT=%d>\n",
	    numLines*30+5);
    fprintf(f,"<param name=classes value=\"%s\">\n",(const char *)classes);
    fprintf(f,"<param name=before value=\"%s\">\n",(const char *)before);
    fprintf(f,"<param name=after value=\"%s\">\n",(const char *)after);
    fprintf(f,"<param name=indent value=\"%s\">\n",(const char *)indent);
    fprintf(f,"<param name=arrowdir value=");
    if (upArrows)
	fprintf(f,"\"up\">\n");
    else
	fprintf(f,"\"down\">\n");

  fprintf(f,"</APPLET>\n");    
}

void ClassGraphWriter::writeText(FILE *f,Entry *e)
{
    int i;
    for (i=0 ; i<max(1,e->baseclasses.size()) ; i++){
	if (i < e->baseclasses.size() && e->baseclasses[i]->section == INTERFACE_SEC) {
	    if (i==0) {
		fprintf(f,"<H3> %s</h3>\n",e->hname);
	    }
	    continue;
	}
	fprintf(f,"<H3> %s\n",e->hname);
	Entry* c=e ;
	while (c->baseclasses.size()>0){
	    if (c==e) c=c->baseclasses[i]; else  c=c->baseclasses[0];
	    if (c)
		fprintf(f,"&lt <A HREF=\"%s\"> %s </A>\n",(const char*)(c->fileName),
			(const char*)(c->hname));
	    else
		fprintf(f,"&lt %s </A>\n",(const char*)(c->name));  
	}
	fprintf(f,"</h3>\n");	
    }
}

void ClassGraphWriter::write(FILE *f,Entry *e)
{
    if (javaGraphs)
	writeJava(f,e);
    else 
	writeText(f,e);
}

void ClassGraphWriter::writeImplements(FILE *f,Entry *e)
{
    int i,first=1;
    for (i=0 ; i<e->baseclasses.size() ; i++){
		if (e->baseclasses[i]->section != INTERFACE_SEC)
			continue;

		if (first) 
				fprintf(f,"<hr>\n <h2> Implements:</h2>\n");
		first=0;

		Entry* c=e->baseclasses[i];
			if (i>0)
				fprintf(f,", ");
			if (c)
				fprintf(f,"<A HREF=\"%s\"> %s </A>",(const char*)(c->fileName),
					(const char*)(c->hname));
		
    }
}

void copyright(FILE *f)
{
  fprintf (f,"<hr>\n") ;
  if (banner.length()<=0 && ownBanner==0){
      fprintf (f,"<A HREF=\"http://www.zib.de/Visual/software/doc++/index.html\">"
	       "<IMG BORDER=0 ALIGN=RIGHT SRC=logo.gif></A>\n");
      fprintf (f,"<P Align=Center><I>this page has been generated automatically by doc++</I>\n");
      fprintf (f,"<P Align=Center><I>(c)opyright by <A HREF=\"http://www.zib.de/zoeckler/\"> Malte  Z&ouml;ckler</A>, "
	       "<A HREF=\"mailto:wunderling@zib.de\"> Roland Wunderling </A>"
	       "<br>contact: <A HREF=\"mailto:doc++@zib.de\"> doc++@zib.de</a></I>");
  } else {
      fprintf (f,"%s\n",(const char *)banner);
      fprintf(f,"<P Align=right><I>generated by <A HREF=\"http://www.zib.de/Visual/software/doc++/index.html\">doc++</A></I>");
  }
  fprintf (f,"\n</BODY>\n");
}

extern char *strToHtml(const char *in,char *dest=0, Entry* ct=0,int withLinks=0);
extern char *seeToHtml(const char *in, Entry* ct=0);

void	entry2link( McString& u, Entry* ref,const char *linkname)
{
    Entry *globref = ref ;
    if (globref!=root)
      while( globref->parent != root && !globref->fileName.length())
	globref = globref->parent ;
    if( ref->fileName.length()) {
	u+="<!1><A HREF=\"" ; 
	u+=ref->fileName ; 
	u+="\">" ; 
	if (linkname)
	  u+=linkname;
	else
	  u+=ref->hname ;
	u+="</A>";
    } else if (globref){
	u+="<!2><A HREF=\""+globref->fileName+"#DOC." ;
	ref->dumpNumber( u ) ;
	u+="\">" ;
	if (linkname)
	    u+=linkname;
	else
	    u+=ref->hname ;
	u+="</A>";
    }
}  


void writeTOCentry(McString &out,Entry *e,int memo)
{ 
    McString link;
    if (e->fileName.length()){
	link= "<A HREF=\"";
	link+=(const char *)(e->fileName);
	link+="\">";
	link+=(const char *)(e->hname);
	link+="</A>";
    } else {
	entry2link(link,e,(const char *)(e->hname));
    }
    out+=link;
    if (memo){
	if (e->memo.length()) {
	    out+=" <I>";
	    out+=(const char*)e->hmemo;
	    out+="</I>\n";
    } else
	out+='\n';    
    }
}
 
void writeTOCentry(FILE *f,Entry *e,int memo)
{ 
    McString out;
    writeTOCentry(out,e,memo);
    fprintf(f,"%s",(const char *)out);
}

void writeTOCentry(SortedList& l,Entry *e,int memo)
{ 
    McString out("<LI>");
    writeTOCentry(out,e, memo);
    l.addString(e->name,(const char *)out);
}

void writeHIERentry(FILE *f,Entry *k,int memo)
{
    fprintf(f,"<LI>");
    writeTOCentry(f,k,memo);
    if( k->pubChilds.size() || k->proChilds.size() ){
	fprintf(f,"<UL>\n");
	int i ;
	for (i=0 ; i<k->pubChilds.size() ; i++){
	    writeHIERentry(f,k->pubChilds[i],memo);
	}
	for (i=0 ; i<k->proChilds.size() ; i++){
	    writeHIERentry(f,k->proChilds[i],memo);
	}
	fprintf(f,"</UL>\n");
    }
}


struct {
    int sec;
    const char *name;
} toc_sections[]={
    { MANUAL_SEC, "General"},
    { PACKAGE_SEC, "Packages"},
    { CLASS_SEC, "Classes"},
    { INTERFACE_SEC, "Interfaces"},
    { FUNCTION_SEC, "Functions, Macros"},
    { VARIABLE_SEC, "Variables"},
    { MACRO_SEC, "Macros"},
    { UNION_SEC, "Enums, Unions, Structs"},
    {0,0}
};

void writeTOCRec(SortedList& list,FILE *f,Entry *root,int section,int& first)
{    
    if (root->section == toc_sections[section].sec && root->name.length()){
	if (first){
	    fprintf(f,"<H2>%s</H2>\n",toc_sections[section].name);
	    fprintf(f,"<UL>\n");
	    first=0;
	}
	if (root->section==MANUAL_SEC || root->section==PACKAGE_SEC) {
	  fprintf(f,"<LI>\n");
	  writeTOCentry(f,root,1);
	} else 
	  writeTOCentry(list,root,1);
    }
    if ((root->section==MANUAL_SEC || root->section==PACKAGE_SEC)
	&& root->sublist.size()){

	int lastfirst=first;
	if (toc_sections[section].sec==MANUAL_SEC || 
	    toc_sections[section].sec==PACKAGE_SEC) {
	    if (!lastfirst)
		fprintf(f,"<UL>\n");
	}
	for (int i=0 ; i<root->sublist.size() ; i++){
	    writeTOCRec(list,f,root->sublist[i],section,first);
	}
	if (!lastfirst)
	    if (toc_sections[section].sec==MANUAL_SEC || 
		toc_sections[section].sec==PACKAGE_SEC)
		fprintf(f,"</UL>\n");
    }
}

void writeTOC(FILE *f)
{
    
    int *index=new int[root->sublist.size()+1];
    
    //fprintf(f,"<html><head><TITLE>Table of Contents</TITLE></head>\n");


    fprintf(f,"%s",(const char *) indexHeader);
    fprintf(f,"\n<H1>Table of contents</H1>\n");    
    int first=1;
    for (int k=0 ; toc_sections[k].name ; k++){
	first=1;
	SortedList list;
	writeTOCRec(list,f,root,k,first);
	list.sort();
	list.write(f);
	if (!first)
	    fprintf(f,"</UL>\n");
    }
    //fprintf(f,"<I><A HREF=\"HIER.%s\"> hierarchy of classes</A></I><P>",HTML_SUFFIX);
    fprintf(f,"%s",(const char *) indexFooter);
    copyright(f);
}


void writeHIERrec(FILE *f,Entry* root)
{
    for (int i=0 ; i<root->sublist.size() ; i++){
	if (root->sublist[i]->baseclasses.size()==0)
	    if ( root->sublist[i]->isClass() 
		&&  root->sublist[i]->proBaseclasses.size() == 0
		&&  root->sublist[i]->pubBaseclasses.size() == 0 ){
		writeHIERentry(f,root->sublist[i],0);
	    }
	writeHIERrec(f,root->sublist[i]);
  }
}

void writeHIER(FILE *f)
{
  //fprintf(f,"<html><head><TITLE>Hierarchy ClassDoc</TITLE></head>\n");
  fprintf(f,"%s",(const char *) hierHeader);
    
  fprintf(f,"<H1>Hierarchy of classes</H1>\n");
  fprintf(f,"<UL>\n");
  writeHIERrec(f,root);
  fprintf(f,"</UL>\n");
  //fprintf(f,"<I><A HREF=\"aindex.%s\"> alphabetic index</A></I><P>",
  //HTML_SUFFIX);

  fprintf(f,"%s",(const char *) hierFooter);
  
  copyright(f);
}

void writeHIERrecJava(FILE *f,Entry *root)
{
    for (int i=0 ; i<root->sublist.size() ; i++){
	if (root->sublist[i]->baseclasses.size()==0)
	    if (root->sublist[i]->isClass()
		&&  root->sublist[i]->proBaseclasses.size() == 0
		&&  root->sublist[i]->pubBaseclasses.size() == 0 ){
		ClassGraphWriter::writeJava(f,root->sublist[i],0);
	    }
	writeHIERrecJava(f,root->sublist[i]);
  }
}

void writeHIERjava(FILE *f)
{
    fprintf(f,"<html><head><TITLE>Hierarchy ClassDoc</TITLE></head>\n");
    fprintf(f,"<H1>Hierarchy of classes</H1>\n");
    fprintf(f,"<UL>\n");
    writeHIERrecJava(f,root);
    fprintf(f,"</UL>\n");
    fprintf(f,"<I><A HREF=\"aindex.%s\"> alphabetic index</A></I><P>",HTML_SUFFIX);
    copyright(f);
}


/** This class keeps track of overloading relationships. Insert mebers
  using addMember. It returns NULL in case this is a new Member, != 0 
  otherwise.*/

class MemberList {
    McHashTable<char *,Entry *> list;
public:
    MemberList() : list((Entry*) NULL) {}
    /** Add a new member. Returns NULL, if no compatible member 
      has yet occurred.*/
  Entry *addMember(Entry *e,Entry *father) {
      McString signature;
      signature=e->name;
      if (e->language==LANG_JAVA) {
	signature+=e->args;
      }
      char *tmp=strdup((const char *)signature);
	Entry **val=list.insert(tmp);
	if (*val==0) {
	    *val=father;
	    return(0);
	} else {
	    if (verb) printf("Member %s was there\n",tmp);
	    free (tmp);
	}
	return (*val);
    }
};

void showSubMembers(FILE *f,Entry *entry);
extern int withPrivate;
extern int showFilenames;

void showMembers( Entry *k,FILE *f,int links,MemberList *ignore=0)
{
    static struct {
	char *heading;
	int protection;
	int secMask;
    } sections[] = {{"<DT><h3>Public Classes</h3><DD>",PUBL,CLASS_SEC|UNION_SEC},
		    {"<DT><h3>Public Fields</h3><DD>",PUBL,VARIABLE_SEC},
		    {"<DT><h3>Public Methods</h3><DD>",PUBL,FUNCTION_SEC},
		    {"<DT><h3>Public</h3><DD>",PUBL,
		     ~(CLASS_SEC|VARIABLE_SEC| FUNCTION_SEC |UNION_SEC)},
		    {"<DT><h3>Protected Classes</h3><DD>",PROT,CLASS_SEC|UNION_SEC},
		    {"<DT><h3>Protected Fields</h3><DD>",PROT,VARIABLE_SEC},
		    {"<DT><h3>Protected Methods</h3><DD>",PROT,FUNCTION_SEC},
		    {"<DT><h3>Protected</h3><DD>",PROT,
		     ~(CLASS_SEC|VARIABLE_SEC| FUNCTION_SEC |UNION_SEC)},
		    {"<DT><h3>Private Fields</h3><DD>",PRIV,VARIABLE_SEC},
		    {"<DT><h3>Private Methods</h3><DD>",PRIV,FUNCTION_SEC},
		    {"<DT><h3>Private</h3><DD>",PRIV,
		     ~(CLASS_SEC|VARIABLE_SEC| FUNCTION_SEC |UNION_SEC)},
		    {0,0,0}};

    int first;
    first=1;
    fprintf(f,"\n<DL>\n");
    Entry* tmp ;
    MemberWriter *memberWriter;
    if (withTables && links){
	memberWriter=new MemberWriterTable();
    } else {
	memberWriter=new MemberWriter();
    }
    for (int i=0 ; sections[i].heading ; i++){
	if (withPrivate || sections[i].protection!=PRIV) {
	    memberWriter->startList(f,sections[i].heading,links);
	    for( tmp = k->sub ; tmp ; tmp = tmp->next ) {
		if (tmp->protection==sections[i].protection && 
		    (tmp->section&sections[i].secMask)){
		    if (links || (strcmp(tmp->name,k->name)!=0
				  && (((const char *)tmp->name)[0]!='~' || 
				      strcmp(&((const char *)tmp->name)[1],k->name)!=0))){
			int ignoreThisOne = 0;		  
			if (ignore) {
			    Entry* othersFather=ignore->addMember(tmp,k);
			    if (othersFather!=0 && othersFather != k)
				ignoreThisOne=1;
			}
			if (!ignoreThisOne || links)
			    memberWriter->addMember(tmp,links);
		    }
		}
	    }
	}
	memberWriter->endList();
    }

    /*
    memberWriter->startList(f,"<DT><h3>public members:</h3><DD>",links);
    for( tmp = k->sub ; tmp ; tmp = tmp->next ) {
	if (tmp->protection==PUBL){
	    if (links || (strcmp(tmp->name,k->name)!=0
			  && (((const char *)tmp->name)[0]!='~' || 
			      strcmp(&((const char *)tmp->name)[1],k->name)!=0))){
		if ((ignore && ignore->addMember(tmp)==0) || ignore==0)
		    memberWriter->addMember(tmp,links);
	    }
	}
    }
    memberWriter->endList();
    
    memberWriter->startList(f,"<DT><h3>protected members:</h3><DD>",links);
    for( tmp = k->sub ; tmp ; tmp = tmp->next ) {
	if (links || (strcmp(tmp->name,k->name)!=0
		      && (((const char *)tmp->name)[0]!='~' || 
			  strcmp(&((const char *)tmp->name)[1],k->name)!=0))){
	    if (tmp->protection==PROT){
		if ((ignore && ignore->addMember(tmp)==0) || ignore==0)
		    memberWriter->addMember(tmp,links);
	    }
	}
    }
    memberWriter->endList();
    
    memberWriter->startList(f,"<DT><h3>private members:</h3><DD>",links);
    if (withPrivate && links){
	if (!first)  fprintf(f,"</DL>\n");  first=1;
	for( tmp = k->sub ; tmp ; tmp = tmp->next ){
	    if (tmp->protection==PRIV){
		if ((ignore && ignore->addMember(tmp)==0) || ignore==0)
		    memberWriter->addMember(tmp,links);
	    }
	}
    }
    memberWriter->endList();*/ 
    delete memberWriter;
    fprintf(f,"</DL>\n"); 
}

void writeInherited(struct Entry *k,FILE *f,MemberList *list=0)
{
  int i;
  showMembers(k,f,0,list);
  for (i=0 ; i<k->baseclasses.size() ; i++){
    fprintf(f,"<hr><H3>Inherited from <A HREF = \"%s\"> %s:</A></h3>\n",
	    (const char *)((k->baseclasses)[i]->fileName),
	    (const char *)((k->baseclasses)[i]->hname));
    writeInherited((k->baseclasses)[i],f,list);
  }
}

/* This function writes the @-fields (except @memo, @name) of the
   specified entry */
void writeTags(FILE *f,Entry *entry)
{
    fprintf( f, "<DL>");    
    
    if (entry->exception.size()) {
	fprintf(f,"<DT><B>Throws:</B><DD>");
	for (int i=0 ; i<entry->exception.size() ; i++) {
	    int k=0;
	    McString s;
	    while (k<entry->exception[i]->length() && (myisalnum((*entry->exception[i])[k]) 
						       || (*entry->exception[i])[k]=='_'))
		s+=(*entry->exception[i])[k++];
	    fprintf(f,"<B>%s</B> ",strToHtml((const char *)s,0,entry,1));
	    while (k<entry->exception[i]->length())
		fprintf(f,"%c",(*entry->exception[i])[k++]);
	    fprintf(f,"<br>");
	}
    }
    if (entry->retrn.length()) {
	fprintf(f,"<DT><B>Returns:</B><DD>%s\n", (const char *)entry->retrn);
    }
    if (entry->param.size()) {
	fprintf(f,"<DT><B>Parameters:</B><DD>");
	for (int k=0 ; k<entry->param.size() ; k++) {
	  
	    int i=0;
	    fprintf(f,"<B>");
	    while (i<entry->param[k]->length() && 
		   (myisalnum((*entry->param[k])[i]) || 
		    (*entry->param[k])[i]=='_'))
		fprintf(f,"%c",(*entry->param[k])[i++]);
	    fprintf(f,"</B> - ");

	    while (i<entry->param[k]->length())
		fprintf(f,"%c",(*entry->param[k])[i++]);
	    fprintf(f,"<br>");
	}
    }
    if (entry->author.length()) {
	fprintf(f,"<DT><B>Author:</B><DD>%s\n", (const char *)entry->author);
    }
    if (entry->version.length()) {
	fprintf(f,"<DT><B>Version:</B><DD>%s\n", (const char *)entry->version);
    }
    if (entry->see.size()) {
	fprintf(f,"<DT><B>See Also:</B><DD>");
	for (int k=0 ; k<entry->see.size() ; k++) {
	    if (entry->see[k]->length())
		fprintf(f,"%s<br>",seeToHtml(*entry->see[k],entry));
	}
    }
    
    fprintf( f, "</DL><P>");    
}

void writeDoc(FILE *f,Entry *entry)
{  
    if (entry->ownPage)
	return;
    int toBeDocumented = subEntryIsToBeDocumented(entry);
    
    if (toBeDocumented) {
	char *args=(entry->hargs);
	char *type=(entry->htype);
	printRefLabel(f,entry ) ;
	fprintf( f, "<DT>");
	fprintf( f, "<IMG BORDER=0 SRC=icon2.gif><TT><B> %s %s",
		 type,
		 (char *)(entry->hname));
	fprintf( f, "%s", args);	
	fprintf( f, "</B></TT>\n");

	if (entry->doc.length()>0)
	    fprintf( f, "<DD>%s\n",(char *)(entry->hdoc));
	else if (entry->memo.length()>0)
	    fprintf( f, "<DD>%s\n",(char *)(entry->hmemo));

	writeTags(f,entry);
    }
    if (entry->sub){
	fprintf(f,"<DL>\n");
	for (Entry *tmp=entry->sub ; tmp ; tmp=tmp->next){
	    writeDoc(f,tmp);
	}
	fprintf(f,"</DL>\n");
    }
}


void writeHeader( Entry *e,FILE *f)
{
    fprintf(f,"<html><head><TITLE>%s</TITLE></head>\n",
	    (char *)(e->hname));
    
    fprintf(f,"%s",(const char *) pageHeader);    
    if (showFilenames && e->section!=PACKAGE_SEC && e->section!=MANUAL_SEC)
	fprintf(f,"In file %s:",(const char *) e->file);
    
    if (e->section == PACKAGE_SEC) {
	McString tmp;
	e->getPackage(tmp);
	fprintf(f,"<H2>package %s</H2>",(char *)tmp);
    } else {
	fprintf(f,"<H2><A HREF =\"#DOC.DOCU\" > <IMG BORDER=0 SRC=down.gif></A>");
	if (e->language==LANG_JAVA) {
	    McString tmp;
	    e->getPackage(tmp);
	    fprintf(f," %s %s.%s",e->htype,(const char *)tmp,e->hname);
        } else
	    fprintf(f," %s %s",e->htype,e->hname);

	fprintf(f," %s </H2>", (const char*)(e->hargs) );
    }
    if (e->memo.length()>1) {
	fprintf(f,"<BLOCKQUOTE>\n%s\n</BLOCKQUOTE>\n",
		(e->hmemo));
    }
}

void writeManPage( Entry *e,FILE *f)
{
  int i;
  Entry *c;
  MemberList list;
  writeHeader(e,f);  
  if (verb)
      printf ("Page for %s\n",(const char *)e->name);  
  if (e->isClass()){ // Is it really a class ?
      // the Inheritance:
      int numChilds = e->pubChilds.size()+e->proChilds.size()+
	  e->priChilds.size();
      int numParents=0;
	  if (e->language==LANG_JAVA)
		numParents = 	e->pubBaseclasses.size()+
			e->proBaseclasses.size() + e->otherPubBaseclasses.size()+
			e->otherProBaseclasses.size();
	  else
          numParents = 	e->pubBaseclasses.size()+e->priBaseclasses.size()+
			e->proBaseclasses.size() + e->otherPubBaseclasses.size()+
			e->otherPriBaseclasses.size()+  e->otherProBaseclasses.size();
	  
	  if (numParents || numChilds || trivialGraphs) {
	    	  fprintf(f,"<hr>\n <h2> Inheritance:</h2>\n");
		  ClassGraphWriter::write(f,e);
	    if (e->language==LANG_JAVA && e->implements.size()) {
		      ClassGraphWriter::writeImplements(f,e);
	    }
      }      
      // the members 
      if (e->sub){
	  fprintf(f,"<hr>\n");  
	  showMembers(e,f,1,&list);
      }
  } else { // This is not a class
      if (e->sub){
	  MemberWriter memberWriter;
	  fprintf(f,"\n<hr>\n");
	  memberWriter.startList(f," ",1);
	  for (Entry *tmp=e->sub; tmp ; tmp=tmp->next){
	      memberWriter.addMember(tmp,1);
	  }
	  memberWriter.endList();
      }
  }
  if (e->isClass()){ // Is it really a class ?
      if (showInherited)
	  for (i=0 ; i<e->baseclasses.size() ; i++){
	      fprintf(f,"<hr><H3>Inherited from <A HREF=\"%s\">"
		      "%s:</A></h3>\n",
		      (const char *)((e->baseclasses)[i]->fileName),
		      (const char *)((e->baseclasses)[i]->hname));
	      writeInherited((e->baseclasses)[i],f,&list);
	  }
  }
  // the documentation: 
  fprintf(f,"<A NAME=\"DOC.DOCU\">\n");
  fprintf(f,"<hr>\n <h2> Documentation </h2>\n");
  
  fprintf(f,"<BLOCKQUOTE>\n");
  if (e->doc.length()>1)
    fprintf(f,"%s\n\n", (e->hdoc));
  else if (e->memo.length()>1) 
    fprintf(f,"%s\n\n", (e->hmemo));  
  fprintf(f,"</BLOCKQUOTE>\n");

  //int doc_count=0;
  fprintf(f,"<DL>\n");
  {
    for (Entry *tmp=e->sub; tmp ; tmp=tmp->next){
      writeDoc(f,tmp);
    } 
  }
  fprintf(f,"</DL>\n");
  

  // the children:
  if (e->isClass()){ // Is it really a class ?
    if( e->pubChilds.size() || e->proChilds.size() )
    {
      fprintf(f,"<hr>\n<DL><DT><B>Direct child classes:\n</B><DD>");
      c=e;
      for ( i=0 ; i<c->pubChilds.size() ; i++){
	fprintf(f,"<A HREF=\"%s\"> %s </A><br>\n",(const char *)c->pubChilds[i]->fileName,
		(const char *)c->pubChilds[i]->hname);
      }
      for ( i=0 ; i<c->proChilds.size() ; i++){
	fprintf(f,"<A HREF=\"%s\"> %s </A><br>\n",(const char *)c->proChilds[i]->fileName,
		(const char *)c->proChilds[i]->hname);
      }
      fprintf(f,"</DL>\n");
    } else
      fprintf(f,"<hr>\n <DL><DT><B>This class has no child classes."
	      "</B></DL>\n");
  }
  
  writeTags(f,e);
  /*
  fprintf(f,"<DL>\n");
  if (e->author.length()) {
    fprintf(f,"<DT><B>Author:</B><DD>%s\n", (const char *)e->author);
  }
  if (e->version.length()) {
    fprintf(f,"<DT><B>Version:</B><DD>%s\n", (const char *)e->version);
  }
  fprintf(f,"</DL>\n");
  
  if (e->see.size()) {
	fprintf(f,"\n<DL><DT><B>See Also:</B>\n<DD>");
	for (int k=0 ; k<e->see.size() ; k++) {
	    if (e->see[k]->length())
		fprintf(f,"%s<br>\n",seeToHtml(*e->see[k],e));
	}
	fprintf(f,"</DD></DL>\n");
  }*/

    fprintf(f,"%s",(const char *) pageFooter);

  copyright(f);
}



FILE *myOpen(const char *dir,const char *name)
{
  char buf[200];
  sprintf(buf,"%s%c%s",dir,PATH_DELIMITER,name);
  FILE *f=fopen(buf,"wb");
  if (!f){
    printf("Cannot open file %s\n",buf);
    exit(-1);
  }
  return f;
}

void makeHtmlNames(Entry* entry)
{
    //  static int cnt;
    Entry*  tmp ;  
    entry->hname=strToHtml(entry->name, 0, entry,0);
    if (entry->section==EMPTY_SEC)
	entry->section=PACKAGE_SEC;
    //printf("Name for %s is %s\n",(const char *)entry->name,(const char *)entry->hname);
    if (entry->sub){
	for( tmp = entry->sub ; tmp ; tmp = tmp->next )
	    makeHtmlNames(tmp);
    }
}

void makeFileNames(Entry* entry)
{
    Entry*  tmp ;  
    
    if (entry->ownPage){
	McString file;
	if (entry->language==LANG_JAVA) {
	    McString pack;
	    if (entry->section==PACKAGE_SEC)
		file = "package-";
	    entry->getPackage(pack);
	    if (pack.length()) {
		file+=pack;
		if (entry->section!=PACKAGE_SEC)
		    file+='.'; 
	    }
	}
	if (entry->language!=LANG_JAVA || entry->section!=PACKAGE_SEC)
	    file+=entry->name;
	entry->fileName=makeFileName(file);
    }
    
    if (entry->sub){
	for( tmp = entry->sub ; tmp ; tmp = tmp->next )
	    makeFileNames(tmp);
    }
}

void decideAboutOwnPages(Entry* entry)
{
    Entry*  tmp ;  

    if (entry->section == EMPTY_SEC)
	entry->section = MANUAL_SEC;

    if (entry->sub || entry->doc.length()>1 || entry->isClass())
	entry->ownPage=1;
    
    if (entry->sub && (entry->section==MANUAL_SEC || entry->section==PACKAGE_SEC)){
	for( tmp = entry->sub ; tmp ; tmp = tmp->next )
	    decideAboutOwnPages(tmp);
    }
}

void makeHtml(Entry* entry)
{
    //static int cnt;
    Entry*  tmp ;
    int i;
    entry->hmemo=strToHtml(entry->memo, 0, entry,0);
    entry->hdoc =strToHtml(entry->doc, 0, entry,0);
    
    entry->hargs =strToHtml(entry->args, 0, entry ,1);
    entry->htype =strToHtml(entry->type, 0, entry ,1);
    
    entry->author =strToHtml(entry->author, 0, entry ,0);
    entry->version =strToHtml(entry->version, 0, entry ,0);
    entry->retrn =strToHtml(entry->retrn, 0, entry ,0);
    for (i=0 ; i<entry->param.size() ; i++)
	*entry->param[i] = strToHtml(*entry->param[i], 0, entry ,0);

    for (i=0 ; i<entry->exception.size() ; i++)
	*entry->exception[i] = strToHtml(*entry->exception[i], 0, entry ,0);

    if (entry->sub){
	for( tmp = entry->sub ; tmp ; tmp = tmp->next )
	    makeHtml(tmp);
    }
}

void writePageSub(FILE *f,Entry *tmp)
{
    if (withTables){
	  fprintf(f,"<TR>");
	  fprintf(f,"<TD VALIGN=top>");
    } else {
	fprintf( f, "<DT>\n");
    }

    McString htype,hargs;

    if (tmp->fileName.length()){
      // no type, args      
    } else {
	htype = tmp->htype;
	hargs = tmp->hargs;
    }
    
    fprintf( f, "<IMG BORDER=0 SRC=icon1.gif>");

    if (1 || tmp->section!=MANUAL_SEC){
	if (withTables)
	    fprintf(f,"%s </TD><TD>",(const char *)htype);
	else 
	    fprintf(f,"%s ",(const char *)htype);
    }
	
    if (tmp->fileName.length()){	
	fprintf( f, "<A HREF=%s><B>%s</B></A> ",
		 (const char *)tmp->fileName,
		 (const char *)tmp->hname) ;
    } else {
	fprintf( f, "<B>%s</B>",
		 (const char *)tmp->hname) ;
    }
    if (withTables && (tmp->section==MANUAL_SEC &&0))
	fprintf(f,"</TD><TD>");
    
    if (1 || tmp->section!=MANUAL_SEC)
	fprintf( f, "%s", (const char *)hargs) ;

    if (withTables){
	fprintf(f,"<br>");
	if (tmp->hmemo)
	    fprintf(f,"\n<I>%s</I>\n",(const char *) tmp->hmemo);    
	fprintf(f,"</TD></TR>");
    } else {
	if (tmp->hmemo)
	    fprintf(f,"\n <DD><I>%s</I>\n",(const char *) tmp->hmemo);    
    }
}

void writeManPageRec(const char *dir, Entry *e)
{
    if (verb)
	printf("in writeManPageRec %s\n",(const char *)e->name);
    if (e->fileName.length()){
	char buf[80];
	sprintf(buf,"%s",(const char *)(e->fileName));
	FILE *f=myOpen(dir,buf);
	if (!f){
	    printf("Cannot open %s for writing !\n",buf);
	    return;
	}
	if (e->section!=MANUAL_SEC && e->section!=PACKAGE_SEC){
	    writeManPage(e,f);
	} else {
	    writeHeader(e,f);
	    if (e->sub){
		if (withTables)
		    fprintf(f,"\n<TABLE>\n");
		else
		    fprintf(f,"\n<hr>\n<DL>\n");
		for (Entry *tmp=e->sub; tmp ; tmp=tmp->next){
		    writePageSub(f,tmp);
		}
		if (withTables)
		    fprintf(f,"\n</TABLE>\n");
		else
		    fprintf(f,"</DL>\n");
	    }
	    
	    fprintf(f,"<A NAME=\"DOC.DOCU\">\n");
	    //fprintf(f,"<hr>\n <h2> Documentation </h2>\n");
  
	    if (e->doc.length()>1){
		fprintf(f,"<BLOCKQUOTE>\n%s\n</BLOCKQUOTE>\n",
			(e->hdoc));
	    } else if (e->memo.length()>1) {
		fprintf(f,"<BLOCKQUOTE>\n%s\n</BLOCKQUOTE>\n",
			(e->hmemo));
	    }

	    writeTags(f,e);

	    /*fprintf(f,"<DL>\n");
	  if (e->author.length()) {
	    fprintf(f,"<DT><B>Author:</B><DD>%s\n", (const char *)e->author);
	  }
	  if (e->version.length()) {
	    fprintf(f,"<DT><B>Version:</B><DD>%s\n", (const char *)e->version);
	  }

	  fprintf(f,"</DL>\n");
	    if (e->see.size()) {
	      fprintf(f,"\n<DL><DT><B>See Also:</B>\n<DD>");
	      for (int k=0 ; k<e->see.size() ; k++) {
		if (e->see[k]->length())
		  fprintf(f,"%s<br>\n",seeToHtml(*e->see[k],e));
	      }
	      fprintf(f,"</DD></DL>\n");
	    }*/
	    fprintf(f,"%s",(const char *) pageFooter);

	    copyright(f);
	}
	fclose(f);
    }
    if ((e->section==MANUAL_SEC || e->section==PACKAGE_SEC)
	&& e->sub){
	for (Entry *tmp=e->sub; tmp ; tmp=tmp->next){
	    if (verb)
		printf("doing sub %s\n",(const char *)tmp->name);
	    writeManPageRec(dir,tmp);
	}
    }
}


void dumpFile(const char *dir,const char *name,const unsigned char *data,int size)
{
  FILE *f=myOpen(dir,name);
  fwrite(data,1,size,f);
  fclose(f);
}

void readTemplates()
{
  FILE *f;
  int c;
  if (f=fopen("indexHeader.inc","r")) {
    indexHeader=" ";
    while ((c=fgetc(f)) != EOF) indexHeader+=c;
    fclose(f);
  }
  if (f=fopen("indexFooter.inc","r")) {
    indexFooter=" ";
    while ((c=fgetc(f)) != EOF) indexFooter+=c;
    fclose(f);
  }
  if (f=fopen("hierHeader.inc","r")) {
    hierHeader=" ";
    while ((c=fgetc(f)) != EOF) hierHeader+=c;
    fclose(f);
  }
  if (f=fopen("hierFooter.inc","r")) {
    hierFooter=" ";
    while ((c=fgetc(f)) != EOF) hierFooter+=c;
    fclose(f);
  }
  if (f=fopen("classHeader.inc","r")) {
    pageHeader=" ";
    while ((c=fgetc(f)) != EOF) pageHeader+=c;
    fclose(f);
  }
  if (f=fopen("classFooter.inc","r")) {
    pageFooter=" ";
    while ((c=fgetc(f)) != EOF) pageFooter+=c;
    fclose(f);
  }

}

void doHTML(char *dir,Entry*)
{
    FILE *f;
    Entry *tmp;

    if( makedir( dir,0755) != 0 ) {
	if( errno == EEXIST ) {
	    FILE *exist = fopen(dir,"a");
	    if( exist ) {
		printf("file exists %s\n", dir) ;
		fclose( exist ) ;
		//exit( -1 ) ;
	    }
	} else {
	    printf("Could not create directory %s\n",dir); 
	    //exit(-1) ;
	}
    }
    
    if (shortFilenames){
	HTML_SUFFIX=strdup("htm");
    }

    printf("converting DOC++ to HTML ...");
    
    decideAboutOwnPages(root);
    makeFileNames(root);
    
    if (root->name.length() && root->section == MANUAL_SEC){
	root->fileName="index.";
	root->fileName+=HTML_SUFFIX;
    } else if (root->sublist.size()==1
	       && root->sublist[0]->section == MANUAL_SEC){
	root->sublist[0]->fileName="index.";
	root->sublist[0]->fileName+=HTML_SUFFIX;
    }
    
    if (root->section==EMPTY_SEC)
	root->section=MANUAL_SEC;
    for( tmp = root ; tmp ; tmp = tmp->next )
	makeHtmlNames(tmp);
    for( tmp = root ; tmp ; tmp = tmp->next )
	makeHtml(tmp);
    
  /*  for( tmp = root ; tmp ; tmp = tmp->next )
      makeLinks(tmp);*/
    printf(" done\n");
    
    readTemplates();
    printf("writing files.\n");
    dumpFile(dir,"logo.gif",logo,sizeof(logo));
    dumpFile(dir,"icon1.gif",blueBall,sizeof(blueBall));
    dumpFile(dir,"icon2.gif",greyBall,sizeof(greyBall));
    dumpFile(dir,"down.gif",down,sizeof(down));
    
    if (ownBanner){
	FILE *in=fopen(ownBanner,"r");
	if (!in && strcmp("none",ownBanner) && strlen(ownBanner)>1){
	    printf("Warning: Can't open %s, producing no banner.\n",
		    ownBanner);
	} else {	  
	    int	c ;
	    while ( (c = fgetc(in)) != EOF )
		banner += (char) c ;
	    fclose(in);
	}
    }
  
    if (javaGraphs){
	dumpFile(dir,"ClassGraph.class",ClassGraph_class,sizeof(ClassGraph_class));
	dumpFile(dir,"ClassGraphPanel.class",ClassGraphPanel_class,sizeof(ClassGraphPanel_class));
	dumpFile(dir,"ClassLayout.class",ClassLayout_class,sizeof(ClassLayout_class));
	dumpFile(dir,"NavigatorButton.class",NavigatorButton_class,sizeof(NavigatorButton_class));    
  }


  char buf[40];

  {
      sprintf(buf,"index.%s",HTML_SUFFIX);
      f=myOpen(dir,buf);
      writeTOC(f);
      fclose(f);      
  }

  sprintf(buf,"HIER.%s",HTML_SUFFIX);
  f=myOpen(dir,buf);
  writeHIER(f);
  fclose(f);  

  sprintf(buf,"HIERjava.%s",HTML_SUFFIX);
  f=myOpen(dir,buf);
  writeHIERjava(f);
  fclose(f);  

  sprintf(buf,"aindex.%s",HTML_SUFFIX);
  f=myOpen(dir,buf);
  writeTOC(f);
  fclose(f);
  writeManPageRec(dir,root);
}      
      
static void	dumpEntry (FILE* out, Entry* entry,int)
{
  Entry*	tmp ;

  if (entry->sub){
    for( tmp = entry->sub ; tmp ; tmp = tmp->next )
      dumpEntry(out,tmp,0);
  }
}

void	usermanHTML(char*, Entry* root)
{
    if( root->name.length() )
	dumpEntry (out, root,1) ;
    else
	for( root=root->sub ; root ; root=root->next )
	    dumpEntry (out, root,1) ;
}