summaryrefslogtreecommitdiffstats
path: root/src/util.cpp
blob: 6b4578d94fdfb5c94fd89c98aad31c27f0da4b51 (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
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
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
/******************************************************************************
 *
 * $Id$
 *
 * Copyright (C) 1997-1999 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * All output generated with Doxygen is not covered by this license.
 *
 */

#include <stdlib.h>
#include <qregexp.h>
#include <qstring.h>
#include <ctype.h>
#include "util.h"
#include "message.h"
#include "classdef.h"
#include "filedef.h"
#include "doxygen.h"
#include "scanner.h"
#include "outputlist.h"
#include "defargs.h"
#include "language.h"
#include "config.h"

// an inheritance tree of depth of 100000 should be enough for everyone :-)
const int maxInheritanceDepth = 100000; 

bool isId(char c)
{
  return c=='_' || isalnum(c);
}


// try to determine if this files is a source or a header file by looking
// at the extension (5 variations are allowed in both upper and lower case)
// If anyone knows or uses another extension please let me know :-)
int guessSection(const char *name)
{
  QString n=((QString)name).lower();
  if (n.right(2)==".c"   ||
      n.right(3)==".cc"  ||
      n.right(4)==".cxx" ||
      n.right(4)==".cpp" ||
      n.right(4)==".c++"
     ) return Entry::SOURCE_SEC;
  if (n.right(2)==".h"   ||
      n.right(3)==".hh"  ||
      n.right(4)==".hxx" ||
      n.right(4)==".hpp" ||
      n.right(4)==".h++"
     ) return Entry::HEADER_SEC;
  return 0;
}


//QString resolveDefines(const char *n)
//{
//  return n;
//  if (n)
//  {
//    Define *def=defineDict[n]; 
//    if (def && def->nargs==0 && !def->definition.isNull())
//    {
//      return def->definition;
//    }
//    return n;
//  }
//  return 0;
//}

QString resolveTypedefs(const QString &n)
{
  QString *subst=typedefDict[n];
  if (subst && !subst->isNull())
  {
    return *subst;
  }
  else
  {
    return n;
  }
}

ClassDef *getClass(const char *name)
{
  if (!name) return 0;
  //QString key=resolveTypedefs(resolveDefines(name));
  //Define *def=defineDict[key];
  //if (def && def->nargs==0 && def->definition.length()>0) // normal define
  //  key=def->definition; // use substitution
  
  return classDict[resolveTypedefs(name)];
}

QString removeRedundantWhiteSpace(const QString &s)
{
  if (s.length()==0) return s;
  QString result;
  uint i;
  for (i=0;i<s.length();i++)
  {
    char c=s.at(i);
    if (c!=' ' ||
	(i!=0 && i!=s.length()-1 && isId(s.at(i-1)) && isId(s.at(i+1)))
       )
    {
      if ((c=='*' || c=='&') && 
	  result.length()>0 && isId(result.at(result.length()-1))
	 ) result+=' ';
      result+=c;
    }
  }
  return result;
}  

void writeTemplatePrefix(OutputList &ol,ArgumentList *al)
{
  ol.docify("template<");
  Argument *a=al->first();
  while (a)
  {
    ol.docify(a->type);
    ol.docify(a->name);
    if (a->defval.length()!=0)
    {
      ol.docify(" = ");
      ol.docify(a->defval);
    } 
    a=al->next();
    if (a) ol.docify(", ");
  }
  ol.docify("> ");
  bool latexEnabled = ol.isEnabled(OutputGenerator::Latex);
  bool manEnabled   = ol.isEnabled(OutputGenerator::Man);
  if (latexEnabled) ol.disable(OutputGenerator::Latex);
  if (manEnabled)   ol.disable(OutputGenerator::Man);
  ol.lineBreak();
  if (latexEnabled) ol.enable(OutputGenerator::Latex);
  if (manEnabled)   ol.enable(OutputGenerator::Man);
}

QString addTemplateNames(const QString &s,const QString &n,const QString &t)
{
  //printf("addTemplateNames(%s)\n",s.data());
  QString result;
  QString clRealName=n;
  int p=0,i;
  if ((i=clRealName.find('<'))!=-1)
  {
    clRealName=clRealName.left(i); // strip template specialization
  }
  while ((i=s.find(clRealName,p))!=-1)
  {
    result+=s.mid(p,i-p);
    uint j=clRealName.length()+i;
    if (s.length()==j || (s.at(j)!='<' && !isId(s.at(j))))
    { // add template names
      //printf("Adding %s+%s\n",clRealName.data(),t.data());
      result+=clRealName+t; 
    }
    else 
    { // template names already present
      //printf("Adding %s\n",clRealName.data());
      result+=clRealName;
    }
    p=i+clRealName.length();
  }
  result+=s.right(s.length()-p);
  //printf("result=%s\n",result.data());
  return result;
}

static void linkifyText(OutputList &ol,const char *clName,const char *name,const char *text)
{
  //printf("class %s name %s Text: %s\n",clName,name,text);
  QRegExp regExp("[a-z_A-Z0-9:<>]+");
  QString txtStr=text;
  OutputList result(&ol);
  int matchLen;
  int index=0;
  int newIndex;
  int skipIndex=0;
  // read a word from the text string
  while ((newIndex=regExp.match(txtStr,index,&matchLen))!=-1)
  {
    // add non-word part to the result
    result.docify(txtStr.mid(skipIndex,newIndex-skipIndex)); 
    // get word from string
    QString word=txtStr.mid(newIndex,matchLen);
    ClassDef *cd=0;
    FileDef *fd=0;
    MemberDef *md=0;

    // check if `word' is a documented class name
    if (word.length()>0 && word!=name && word!=clName)
    {
      if ((cd=getClass(word)))
      {
        // add link to the result
        if (cd->isVisible())
        {
          result.writeObjectLink(cd->getReference(),cd->classFile(),0,word);
        }
        else
        {
          result.docify(word);
        }
      }
      else if (getDefs(word,clName,0,md,cd,fd) && md->hasDocumentation())
      {
        if (cd && cd->isVisible() && !md->isFunction()) // word is a member of cd
        {
          result.writeObjectLink(cd->getReference(),
                  cd->classFile(),md->anchor(),word);
        }
        else if (fd && fd->hasDocumentation()) // word is a global in file fd
        {
          result.writeObjectLink(fd->getReference(),
                  fd->diskName(),md->anchor(),word);
        }
        else // add word to the result
        {
          result.docify(word);
        }
      }
      else // add word to the result
      {
        result.docify(word);
      }
    }
    else // add word to the result
    {
      result.docify(word);
    }
    // set next start point in the string
    skipIndex=index=newIndex+matchLen;
  }
  // add last part of the string to the result.
  result.docify(txtStr.right(txtStr.length()-skipIndex));
  //printf("linkify: %s\n",result.data());
  ol+=result; 
}

static void writeDefArgumentList(OutputList &ol,ClassDef *cd,
                                 const QString &scopeName,MemberDef *md)
{
  ArgumentList *argList=md->argumentList();
  if (argList==0) return; // member has no function like argument list
  ol.docify(" ("); // start argument list
  Argument *a=argList->first();
  QString cName;
  if (cd && cd->templateArguments())
  {
    cName=cd->getTemplateNameString(); 
  }
  while (a)
  {
    QRegExp re(")(");
    int vp;
    if ((vp=a->type.find(re))!=-1) // argument type is a function pointer
    {
      QString n=a->type.left(vp);
      if (cName.length()>0) n=addTemplateNames(n,cd->name(),cName);
      linkifyText(ol,scopeName,md->name(),n);
    }
    else // non-function pointer type
    {
      QString n=a->type;
      if (cName.length()>0) n=addTemplateNames(n,cd->name(),cName);
      linkifyText(ol,scopeName,md->name(),n);
    }
    if (a->name.length()>0) // argument has a name
    { 
      ol.docify(" ");
      ol.disable(OutputGenerator::Man);
      ol.startEmphasis();
      ol.enable(OutputGenerator::Man);
      ol.docify(a->name);
      ol.disable(OutputGenerator::Man);
      ol.endEmphasis();
      ol.enable(OutputGenerator::Man);
    }
    if (vp!=-1) // write the part of the argument type 
                // that comes after the name
    {
      linkifyText(ol,scopeName,md->name(),a->type.right(a->type.length()-vp));
    }
    if (a->defval.length()>0) // write the default value
    {
      QString n=a->defval;
      if (cName.length()>0) n=addTemplateNames(n,cd->name(),cName);
      ol.docify(" = ");
      linkifyText(ol,scopeName,md->name(),n); 
    }
    a=argList->next();
    if (a) ol.docify(", "); // there are more arguments
  }
  ol.docify(")"); // end argument list
  if (argList->constSpecifier)
  {
    ol.docify(" const");
  }
  if (argList->volatileSpecifier)
  {
    ol.docify(" volatile");
  }
}

QString argListToString(ArgumentList *al)
{
  QString result;
  if (al==0) return result;
  Argument *a=al->first();
  result+="(";
  while (a)
  {
    result+= a->type+" "+a->name;
    a = al->next();
    if (a) result+=","; 
  }
  result+=")";
  if (al->constSpecifier) result+=" const";
  if (al->volatileSpecifier) result+=" volatile";
  return result;
}
          
static void writeLink(OutputList &ol,ClassDef *cd,NamespaceDef *nd,
                      FileDef *fd,MemberDef *md,const char *name)
{
  if (nd)
    ol.writeObjectLink(0 /*TODO: references */,nd->namespaceFile(),md->anchor(),name);
  else if (fd) 
    ol.writeObjectLink(fd->getReference(),fd->diskName(),md->anchor(),name);
  else    
    ol.writeObjectLink(cd->getReference(),cd->classFile(),md->anchor(),name);
}

static void warnForUndocumentedMember(MemberDef *md)
{
  ClassDef *cd=md->memberClass();
  FileDef *fd=md->getFileDef();
  if (cd)
  {
    if (!md->hasDocumentation() && md->name() && md->name()[0]!='@') 
      warn("Warning: Member %s of class %s is not documented\n",
        md->name().data(),cd->name().data());
  }
  else if (fd)
  {
    if (!md->hasDocumentation() && md->name() && md->name()[0]!='@') 
      warn("Warning: Member %s of file %s is not documented\n",
        md->name().data(),fd->name().data());
  }
}

static bool manIsEnabled;

void startTitle(OutputList &ol)
{
  ol.startTitleHead();
  manIsEnabled=ol.isEnabled(OutputGenerator::Man);
  if (manIsEnabled) ol.disable(OutputGenerator::Man);
}

void endTitle(OutputList &ol,const char *name)
{
  if (manIsEnabled) ol.enable(OutputGenerator::Man); 
  ol.endTitleHead(name);
}

void writeQuickLinks(OutputList &ol,bool compact,bool ext)
{
  bool manEnabled = ol.isEnabled(OutputGenerator::Man);
  bool texEnabled = ol.isEnabled(OutputGenerator::Latex);
  QString extLink,absPath;
  if (ext) { extLink="_doc:"; absPath="/"; }
  if (manEnabled) ol.disable(OutputGenerator::Man);
  if (texEnabled) ol.disable(OutputGenerator::Latex);
  if (compact) ol.startCenter(); else ol.startItemList();
  if (documentedGroups>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"modules.html");
    parseDoc(ol,0,0,theTranslator->trModules());
    ol.endQuickIndexItem();
  } 
  if (documentedNamespaces>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"namespaces.html");
    parseDoc(ol,0,0,theTranslator->trNamespaces());
    ol.endQuickIndexItem();
  }
  if (hierarchyClasses>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"hierarchy.html");
    parseDoc(ol,0,0,theTranslator->trClassHierarchy());
    ol.endQuickIndexItem();
  } 
  if (annotatedClasses>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"annotated.html");
    parseDoc(ol,0,0,theTranslator->trCompoundList());
    ol.endQuickIndexItem();
  } 
  if (documentedFiles>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"files.html");
    parseDoc(ol,0,0,theTranslator->trFileList());
    ol.endQuickIndexItem();
  } 
  if (includeFiles.count()>0 && verbatimHeaderFlag)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"headers.html");
    parseDoc(ol,0,0,theTranslator->trHeaderFiles());
    ol.endQuickIndexItem();
  } 
  if (documentedMembers>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"functions.html");
    parseDoc(ol,0,0,theTranslator->trCompoundMembers());
    ol.endQuickIndexItem();
  } 
  if (documentedFunctions>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"globals.html");
    parseDoc(ol,0,0,theTranslator->trFileMembers());
    ol.endQuickIndexItem();
  } 
  if (pageList.count()>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"pages.html");
    parseDoc(ol,0,0,theTranslator->trRelatedPages());
    ol.endQuickIndexItem();
  } 
  if (exampleList.count()>0)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem(extLink,absPath+"examples.html");
    parseDoc(ol,0,0,theTranslator->trExamples());
    ol.endQuickIndexItem();
  } 
  if (searchEngineFlag)
  {
    if (!compact) ol.writeListItem();
    ol.startQuickIndexItem("_cgi:","");
    parseDoc(ol,0,0,theTranslator->trSearch());
    ol.endQuickIndexItem();
  } 
  if (compact) 
  {
    ol.endCenter(); 
    ol.writeRuler();
  }
  else 
  {
    ol.endItemList();
  }
  if (manEnabled) ol.enable(OutputGenerator::Man);
  if (texEnabled) ol.enable(OutputGenerator::Latex);
}

void startFile(OutputList &ol,const char *name,const char *title,bool external)
{
  ol.startFile(name,title,external);
  if (!noIndexFlag) writeQuickLinks(ol,TRUE,external);
}

void endFile(OutputList &ol,bool external)
{
  bool latexEnabled = ol.isEnabled(OutputGenerator::Latex);
  bool manEnabled   = ol.isEnabled(OutputGenerator::Man);
  if (latexEnabled) ol.disable(OutputGenerator::Latex);
  if (manEnabled)   ol.disable(OutputGenerator::Man);
  ol.writeFooter(0,external); // write the footer
  if (footerFile.length()==0)
  {
    parseDoc(ol,0,0,theTranslator->trGeneratedAt(
              dateToString(TRUE),
              projectName
             ));
  }
  ol.writeFooter(1,external); // write the link to the picture
  if (footerFile.length()==0)
  {
    parseDoc(ol,0,0,theTranslator->trWrittenBy());
  }
  ol.writeFooter(2,external); // end the footer
  if (latexEnabled) ol.enable(OutputGenerator::Latex);
  if (manEnabled)   ol.enable(OutputGenerator::Man);
  ol.endFile();
}


static void writeMemberDef(OutputList &ol, ClassDef *cd, NamespaceDef *nd,
                           FileDef *fd, MemberDef *md)
{
  int i,l;
  bool hasDocs=md->hasDocumentation();
  if ((!hasDocs && hideMemberFlag) || 
      (hideMemberFlag && 
       md->documentation().isEmpty() && 
       !briefMemDescFlag && 
       !repeatBriefFlag
      )
     ) return;
  QString type=md->typeString();
  QRegExp r("@[0-9]+");
  if ((i=r.match(type,0,&l))==-1 || !md->enumUsed())
  {
    // strip `static' keyword from type
    if (type.left(7)=="static ") type=type.right(type.length()-7);
    // strip `friend' keyword from type
    if (type.left(7)=="friend ") type=type.right(type.length()-7);
    
    if (genTagFile.length()>0)
    {
      tagFile << md->name() << " " << md->anchor() << " \""
              << md->argsString() << "\"\n";
    }
      
    QString cname;
    if (cd)      cname=cd->name(); 
    else if (nd) cname=nd->name();
    else if (fd) cname=fd->name();

    // If there is no detailed description we need to write the anchor here.
    if (!md->detailsAreVisible() && !extractAllFlag)
    {
      ol.writeDoxyAnchor(cname,md->anchor(),md->name());
      ol.addToIndex(md->name(),cname);
      ol.addToIndex(cname,md->name());
      ol.docify("\n");
    }
    
    ol.startMemberItem();

    // write type
    if (i!=-1)
    {
      QString newType = type.left(i) + " { ... } " +
        type.right(type.length()-i-l);
      type = newType;
      ol.docify(type);
    }
    else
    {
      ol.docify(type);
    }
    QString name=md->name().copy();
    if (type.length()>0) ol.writeString(" ");

    // write name
    if ( extractAllFlag ||
         (md->briefDescription().isEmpty() || !briefMemDescFlag) && 
         (!md->documentation().isEmpty() || 
               (!md->briefDescription().isEmpty() && 
                !briefMemDescFlag &&
                repeatBriefFlag
               )
         )
       )
    {
      //printf("writeLink %s->%d\n",name.data(),md->hasDocumentation());
      writeLink(ol,cd,nd,fd,md,name);
    }
    else // there is a brief member description and brief member 
         // descriptions are enabled or there is no detailed description.
    {
      ol.writeBoldString(name);
    }

    if (md->argsString()) 
    {
      ol.writeString(" ");
      ol.docify(md->argsString());
    }
    
    if (md->excpString())
    {
      ol.writeString(" ");
      ol.docify(md->excpString());
    }

    ol.endMemberItem();

    // write brief description
    if (!md->briefDescription().isEmpty() && briefMemDescFlag)
    {
      ol.startMemberDescription();
      parseDoc(ol,cname,md->name(),md->briefDescription());
      if (!md->documentation().isEmpty()) 
      {
        ol.disableAllBut(OutputGenerator::Html);
        ol.endEmphasis();
        ol.docify(" ");
        ol.startTextLink(0,md->anchor());
        //ol.writeObjectLink(0,0,md->anchor()," More...");
        parseDoc(ol,0,0,theTranslator->trMore());
        ol.endTextLink();
        ol.startEmphasis();
        ol.enableAll();
      }
      ol.endMemberDescription();
      ol.newParagraph();
    }
  }
  warnForUndocumentedMember(md);
}


// write a list in HTML of all members of a certain category
// cd!=0 => ml is a list of class members
// fd!=0 => ml is a list of file `members'
void writeMemberDecs(OutputList &ol,ClassDef *cd,NamespaceDef *nd, FileDef *fd,
                 const char *title, const char *subtitle,MemberList *ml)
{
  ml->countDecMembers();
  if (ml->totalCount()==0) return;
  if (title) 
  {
    ol.startMemberHeader();
    parseDoc(ol,0,0,title);
    ol.endMemberHeader();
  }
  if (subtitle) ol.writeString(subtitle);
  

  if (!fd && !nd) ol.startMemberList();
  MemberDef *md;

  if (fd && ml->defineCount()>0)
  {
    ol.startMemberHeader();
    parseDoc(ol,0,0,theTranslator->trDefines());
    ol.endMemberHeader();
    ol.startMemberList();
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()); ++mli )
    {
      if (md->isDefine() && 
          (md->argsString() || md->hasDocumentation() || extractAllFlag)
         ) 
        writeMemberDef(ol,cd,nd,fd,md);
    }
    ol.endMemberList();
  }
  
  if ((fd || nd) && ml->protoCount()>0)
  {
    ol.startMemberHeader();
    parseDoc(ol,0,0,theTranslator->trFuncProtos());
    ol.startMemberList();
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()); ++mli )
    {
      if (md->isPrototype()) writeMemberDef(ol,cd,nd,fd,md);
    }
    ol.endMemberList();
  }
  
  if (ml->typedefCount()>0)
  {
    if (fd || nd) 
    {
      ol.startMemberHeader();
      parseDoc(ol,0,0,theTranslator->trTypedefs());
      ol.endMemberHeader();
      //ol.writeMemberHeader("Typedefs");
      ol.startMemberList();
    }
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()) ; ++mli )
    {
      if (md->isTypedef()) writeMemberDef(ol,cd,nd,fd,md);
    }
    if (fd || nd) ol.endMemberList();
  }
 
  // write enums 
  if (ml->enumCount()>0)
  {
    if (fd || nd) 
    {
      ol.startMemberHeader();
      parseDoc(ol,0,0,theTranslator->trEnumerations());
      ol.endMemberHeader();
      ol.startMemberList();
    }
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()) ; ++mli )
    {
      bool hasDocs=md->hasDocumentation();
      QString type=md->typeString();
      type=type.stripWhiteSpace();
      if (md->isEnumerate() && (hasDocs || !hideMemberFlag)) 
      {
        // see if there are any documented enum values
        // we need this info to decide if we need to generate a link.
        QList<MemberDef> *fmdl=md->enumFieldList();
        int documentedEnumValues=0;
        if (fmdl)
        {
          MemberDef *fmd=fmdl->first();
          while (fmd)
          {
            if (fmd->hasDocumentation()) documentedEnumValues++;
            fmd=fmdl->next();
          }
        }
        if (documentedEnumValues>0) md->setDocumentedEnumValues(TRUE);

        if (!hideMemberFlag ||                // do not hide undocumented members or
            !md->documentation().isEmpty() || // member has detailed descr. or
            documentedEnumValues>0 ||         // member has documented enum vales.
            briefMemDescFlag ||               // brief descr. is shown or
            repeatBriefFlag                   // brief descr. is repeated.
           )
        {
          OutputList typeDecl(&ol);
          QString name=md->name().copy();
          int i=name.findRev("::");
          if (i!=-1) name=name.right(name.length()-i-2); // strip scope
          if (name[0]!='@') // not an anonymous enum
          {
            if (extractAllFlag ||
                (md->briefDescription().isEmpty() || !briefMemDescFlag) &&
                (!md->documentation().isEmpty() || documentedEnumValues>0 ||
                 (!md->briefDescription().isEmpty() && 
                  !briefMemDescFlag &&
                  repeatBriefFlag
                 )
                )
               )
            {
              if (genTagFile.length()>0)
                tagFile << md->name() << " " << md->anchor() 
                  << " \"" << md->argsString() << "\"";
              writeLink(typeDecl,cd,nd,fd,md,name);
            }
            else
            {
              typeDecl.writeBoldString(name);
            }
            typeDecl.writeChar(' ');
          }

          typeDecl.docify("{ ");
          if (fmdl)
          {
            MemberDef *fmd=fmdl->first();
            while (fmd)
            {
              if (fmd->hasDocumentation())
              {
                if (genTagFile.length()>0)
                  tagFile << fmd->name() << " " << fmd->anchor() 
                    << " \"" << fmd->argsString() << "\"";
                writeLink(typeDecl,cd,nd,fd,fmd,fmd->name());
              }
              else
                typeDecl.writeBoldString(fmd->name());
              fmd=fmdl->next();
              if (fmd) typeDecl.writeString(", ");
              typeDecl.disable(OutputGenerator::Man);
              typeDecl.writeString("\n"); // to prevent too long lines in LaTeX
              typeDecl.enable(OutputGenerator::Man);
            }
          }
          typeDecl.docify(" }");
          md->setEnumDecl(typeDecl);
          int enumVars=0;
          MemberListIterator vmli(*ml);
          MemberDef *vmd;
          if (name[0]=='@') // anonymous enum => append variables
          {
            for ( ; (vmd=vmli.current()) ; ++vmli)
            {
              QString vtype=vmd->typeString();
              if ((vtype.find(name))!=-1) enumVars++;
            }
          }
          if (enumVars==0) // no variable of this enum type
          {
            ol.startMemberItem();
            ol.writeString("enum ");
            ol+=typeDecl;
            ol.endMemberItem();
            //QString brief=md->briefDescription();
            //brief=brief.stripWhiteSpace();
            if (!md->briefDescription().isEmpty() && briefMemDescFlag)
            {
              ol.startMemberDescription();
              parseDoc(ol,cd?cd->name().data():0,
                  md->name().data(),md->briefDescription());
              if (!md->documentation().isEmpty() || documentedEnumValues>0)
              {
                ol.disableAllBut(OutputGenerator::Html);
                ol.endEmphasis();
                ol.docify(" ");
                ol.startTextLink(0,md->anchor());
                //ol.writeObjectLink(0,0,md->anchor()," More...");
                parseDoc(ol,0,0,theTranslator->trMore());
                ol.endTextLink();
                ol.startEmphasis();
                ol.enableAll();
              }
              ol.endMemberDescription();
              ol.disable(OutputGenerator::Man);
              ol.newParagraph();
              ol.enable(OutputGenerator::Man);
            }
          }
          warnForUndocumentedMember(md);
        }
      } // md->isEnumerate()
    } // enum loop
    if (fd || nd) ol.endMemberList();
  } // write enums
 
  // write functions
  if (ml->funcCount()>0)
  {
    if (fd || nd) 
    {
      ol.startMemberHeader();
      parseDoc(ol,0,0,theTranslator->trFunctions());
      ol.endMemberHeader();
      ol.startMemberList();
    }
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()) ; ++mli )
    {
      if ( md->isFunction() || md->isSignal() || 
           md->isSlot()) 
        writeMemberDef(ol,cd,nd,fd,md);
    }
    if (fd || nd) ol.endMemberList();
  }
  
  if (ml->friendCount()>0)
  {
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()) ; ++mli )
    {
      if ( md->isFriend()) 
      {
        QString type=md->typeString();
        //printf("Friend: type=%s name=%s\n",type.data(),md->name().data());
        if (md->hasDocumentation() && type!="friend class")
        {
          writeMemberDef(ol,cd,nd,fd,md);
        }
        else // friend is undocumented as a member but it is a class, 
             // so generate a link to the class if that is documented.
        {
          ClassDef *cd=getClass(md->name());
          if (md->hasDocumentation()) // friend is documented
          {
            ol.startMemberItem();
            ol.docify("class ");
            ol.writeObjectLink(0,0,md->anchor(),md->name());
            ol.endMemberItem();
          }
          else if (cd && cd->isVisibleExt()) // class is documented
          {
            ol.startMemberItem();
            ol.docify("class ");
            ol.writeObjectLink(cd->getReference(),cd->classFile(),0,cd->name());
            ol.endMemberItem();
          }
          else if (!hideMemberFlag) // no documentation
          {
            ol.startMemberItem();
            ol.docify("class ");
            ol.writeBoldString(md->name());
            ol.endMemberItem();
          }
        }
      }
    }
  }

  // write variables
  if (ml->varCount()>0)
  {
    if (fd || nd) 
    {
      ol.startMemberHeader();
      parseDoc(ol,0,0,theTranslator->trVariables());
      ol.endMemberHeader();
      ol.startMemberList();
    }
    MemberListIterator mli(*ml);
    for ( ; (md=mli.current()) ; ++mli )
    {
      if (md->isVariable()) writeMemberDef(ol,cd,nd,fd,md);
    }
    if (fd || nd) ol.endMemberList();
  }
 
  if (!fd && !nd) { ol.endMemberList(); ol.writeChar('\n'); }
}

// compute the HTML anchors for a list of members
void setAnchors(char id,MemberList *ml)
{
  int count=0;
  MemberDef *md=ml->first();
  while (md)
  {
    QString anchor;
    anchor.sprintf("%c%d",id,count++);
    //printf("Member %s anchor %s\n",md->name(),anchor.data());
    md->setAnchor(anchor);
    md=ml->next();
  }
}

void writeMemberDocs(OutputList &ol,MemberList *ml,const char *scopeName,
                         MemberDef::MemberType m)
{
  MemberListIterator mli(*ml);
  MemberDef *md;
  for ( ; (md=mli.current()) ; ++mli)
  {
    bool hasDocs = md->detailsAreVisible();
    //     !md->documentation().isEmpty() ||          // member has a detailed description
    //     (md->memberType()==MemberDef::Enumeration && // or member is an enum and
    //      md->hasDocumentedEnumValues()             // one of its values is documented
    //     ) ||                                       // or 
    //     (!md->briefDescription().isEmpty() &&      // member has brief description and
    //      !briefMemDescFlag &&                      // brief description not shown earlier and
    //      repeatBriefFlag                           // brief description should be repeated.
    //     );
    if (md->memberType()==m &&                      // filter member type
        (extractAllFlag || hasDocs) 
       )
    {
      if (extractAllFlag && !hasDocs) 
      {
        ol.disable(OutputGenerator::Latex); // Latex cannot insert a pagebreak 
                                            // if there are a lot of empty sections,
                                            // so we disable LaTeX for all empty 
                                            // sections even if extractAllFlag is enabled
      }
      QString cname;
      NamespaceDef *nd=md->getNamespace();
      ClassDef     *cd=md->memberClass();
      FileDef      *fd=md->getFileDef();
      if (cd)      cname=cd->name(); 
      else if (nd) cname=nd->name();
      else if (fd) cname=fd->name();
      // get member name
      QString doxyName=md->name().copy();
      // prepend scope if there is any (TODO: prepend namespace scope as well)
      if (scopeName) doxyName.prepend((QString)scopeName+"::");
      
      QString def = md->definition();
      if (md->isEnumerate()) def.prepend("enum ");
      MemberDef *smd;
      if (md->isEnumValue() && def[0]=='@') def = def.right(def.length()-2);
      int i=0,l,dummy;
      QRegExp r("@[0-9]+");
      if (md->isEnumerate() && r.match(def,0,&l)!=-1) continue;
      if (md->isEnumValue() && (smd = md->getEnumScope()) 
          && r.match(smd->name(),0,&dummy)==-1) continue;
      if ((md->isVariable() || md->isTypedef()) && (i=r.match(def,0,&l))!=-1)
      {
        // find enum type an insert it in the definition
        MemberListIterator vmli(*ml);
        MemberDef *vmd;
        bool found=FALSE;
        for ( ; (vmd=vmli.current()) && !found ; ++vmli)
        {
          if (vmd->isEnumerate() && def.mid(i,l)==vmd->name())
          {
            ol.startMemberDoc(cname,md->name(),md->anchor());
            ol.writeDoxyAnchor(cname,md->anchor(),doxyName);
            linkifyText(ol,scopeName,md->name(),def.left(i));
            ol+=*vmd->enumDecl();
            linkifyText(ol,scopeName,md->name(),def.right(def.length()-i-l));
            found=TRUE;
          }
        }
        if (!found) // anonymous compound
        {
          ol.startMemberDoc(cname,md->name(),md->anchor());
          ol.writeDoxyAnchor(cname,md->anchor(),doxyName);
          linkifyText(ol,scopeName,md->name(),def.left(i));
          ol.docify(" { ... } ");
          linkifyText(ol,scopeName,md->name(),def.right(def.length()-i-l));
        }
      }
      else
      {
        ol.startMemberDoc(cname,md->name(),md->anchor());
        ol.writeDoxyAnchor(cname,md->anchor(),doxyName);
        ArgumentList *al=0;
        if (cd && (!md->isRelated() || !md->templateArguments()) && 
            (al=cd->templateArguments())) // class template prefix
        {
          writeTemplatePrefix(ol,al);
        }
        if (al && md->templateArguments()) ol.docify(" ");
        al=md->templateArguments();
        if (al) // function template prefix
        {
          writeTemplatePrefix(ol,al);
        }
        if (cd && cd->templateArguments())
        {
          // add template name lists to all occurrences of the class name.
          def=addTemplateNames(def,cd->name(),cd->getTemplateNameString());
        }
        linkifyText(ol,scopeName,md->name(),def);
        writeDefArgumentList(ol,cd,scopeName,md);
        if (md->excpString())
        {
          ol.docify(" ");
          linkifyText(ol,scopeName,md->name(),md->excpString());
        }
      }
      
      Specifier virt=md->virtualness();
      MemberDef *rmd=md->reimplements();
      while (rmd && virt==Normal)
      {
        virt = rmd->virtualness()==Normal ? Normal : Virtual;
        rmd  = rmd->reimplements();
      }

      if (md->isStatic() || md->protection()!=Public || 
          virt!=Normal || md->isSignal() || md->isFriend() || 
          md->isRelated() || md->isSlot()
         )
      {
        // write the member specifier list
        ol.writeLatexSpacing();
        ol.startTypewriter();
        ol.docify(" [");
        QStrList sl;
        if (md->isFriend()) sl.append("friend");
        else if (md->isRelated()) sl.append("related");
        else
        {
          if      (md->isStatic())              sl.append("static");
          if      (md->protection()==Protected) sl.append("protected");
          else if (md->protection()==Private)   sl.append("private");
          if      (virt==Virtual)               sl.append("virtual");
          else if (virt==Pure)                  sl.append("pure virtual");
          if      (md->isSignal())              sl.append("signal");
          if      (md->isSlot())                sl.append("slot");
        }
        const char *s=sl.first();
        while (s)
        {
          ol.docify(s);
          s=sl.next();
          if (s) ol.docify(", ");
        }
        ol.docify("]");
        ol.endTypewriter();
      }
      ol.endMemberDoc();
      ol.startIndent();
      ol.newParagraph();

      if (!md->briefDescription().isEmpty() && 
          (repeatBriefFlag || 
             (!briefMemDescFlag && md->documentation().isEmpty())
          )
         )  
      { 
        parseDoc(ol,scopeName,md->name(),md->briefDescription());
        ol.newParagraph();
      }
      if (!md->documentation().isEmpty())
      { 
        parseDoc(ol,scopeName,md->name(),md->documentation()+"\n");
      }
      
      if (md->isEnumerate())
      {
        bool first=TRUE;
        MemberList *fmdl=md->enumFieldList();
        if (fmdl)
        {
          MemberDef *fmd=fmdl->first();
          while (fmd)
          {
            if (fmd->hasDocumentation())
            {
              if (first)
              {
                ol.newParagraph();
                ol.startBold();
                parseDoc(ol,0,0,theTranslator->trEnumerationValues());
                //ol.writeBoldString("Enumeration values:");
                ol.docify(":");
                ol.endBold();
                ol.startMemberList();
              }
              ol.writeDoxyAnchor(cname,fmd->anchor(),fmd->name());
              ol.addToIndex(fmd->name(),cname);
              ol.addToIndex(cname,fmd->name());
              ol.writeListItem();
              first=FALSE;
              ol.startBold();
              ol.docify(fmd->name());
              ol.endBold();
              ol.newParagraph();

              if (!fmd->briefDescription().isEmpty())
              { 
                parseDoc(ol,scopeName,fmd->name(),fmd->briefDescription());
                ol.newParagraph();
              }
              if (!fmd->documentation().isEmpty())
              { 
                parseDoc(ol,scopeName,fmd->name(),fmd->documentation()+"\n");
              }
              ol.disable(OutputGenerator::Man);
              ol.newParagraph();
              ol.enable(OutputGenerator::Man);
            }
            fmd=fmdl->next();
          }
        }
        if (!first) { ol.endMemberList(); ol.writeChar('\n'); }
      }
      
      MemberDef *bmd=md->reimplements();
      if (bmd)
      {
        if (virt!=Normal) // search for virtual member of the deepest base class
        {
          MemberDef *lastBmd=bmd;
          while (lastBmd) 
          {
            if (lastBmd->virtualness()!=Normal) bmd=lastBmd;
            lastBmd=lastBmd->reimplements();
          }
        }
        // write class that contains a member that is reimplemented by this one
        ClassDef *bcd = bmd->memberClass();
        ol.newParagraph();
        parseDoc(ol,0,0,theTranslator->trReimplementedFrom());
        //ol.writeString("Reimplemented from ");
        ol.docify(" ");
        if (bmd->hasDocumentation())
        {
          ol.writeObjectLink(bcd->getReference(),bcd->classFile(),
              bmd->anchor(),bcd->name());
          if (
              !bcd->isReference() &&
              //(bcd->hasDocumentation() || !hideClassFlag) &&
              //(bcd->protection()!=Private || extractPrivateFlag)
              bcd->isVisible() 
              /*&& bmd->detailsAreVisible()*/
             ) ol.writePageRef(bcd->name(),bmd->anchor());
        }
        else
        {
          ol.writeObjectLink(bcd->getReference(),bcd->classFile(),
              0,bcd->name());
          if (
              !bcd->isReference() &&
              //(bcd->hasDocumentation() || !hideClassFlag) &&
              //(bcd->protection()!=Private || extractPrivateFlag)
              bcd->isVisible()
             ) ol.writePageRef(bcd->name(),0);
        }
        ol.writeString(".");
      }
      MemberList *bml=md->reimplementedBy();
      int count;
      if (bml && (count=bml->count())>0)
      {
        // write the list of classes that overwrite this member
        ol.newParagraph();
        parseDoc(ol,0,0,theTranslator->trReimplementedIn());
        //ol.writeString("Reimplemented in ");
        ol.docify(" ");
        bmd=bml->first();
        while (bmd)
        {
          ClassDef *bcd = bmd->memberClass();
          if (bmd->hasDocumentation())
          {
            ol.writeObjectLink(bcd->getReference(),bcd->classFile(),
                          bmd->anchor(),bcd->name());
          if (
              !bcd->isReference() &&
              //(bcd->hasDocumentation() || !hideClassFlag) &&
              //(bcd->protection()!=Private || extractPrivateFlag)
              bcd->isVisible()
              /*&& bmd->detailsAreVisible()*/
             ) ol.writePageRef(bcd->name(),bmd->anchor());
          }
          else
          {
            ol.writeObjectLink(bcd->getReference(),bcd->classFile(),
                0,bcd->name());
            if (
                !bcd->isReference() &&
                //(bcd->hasDocumentation() || !hideClassFlag) &&
                //(bcd->protection()!=Private || extractPrivateFlag)
                bcd->isVisible()
               ) ol.writePageRef(bcd->name(),0);
          }
          bmd=bml->next(); 
          if (bmd)
          {
            if (bml->at()==count-1) 
              //ol.writeString(" and "); 
              parseDoc(ol,0,0," "+theTranslator->trAnd()+" ");
            else 
              ol.writeString(", ");
          }
        }
        ol.writeString(".");
      }
      // write the list of examples that use this member
      if (md->hasExamples())
      {
        ol.startDescList();
        ol.startBold();
        parseDoc(ol,0,0,theTranslator->trExamples()+": ");
        //ol.writeBoldString("Examples: ");
        ol.endBold();
        ol.endDescTitle();
        ol.writeDescItem();
        md->writeExample(ol);
        //ol.endDescItem();
        ol.endDescList();
      }
      ol.endIndent();
      // enable LaTeX again
      if (extractAllFlag && !hasDocs) ol.enable(OutputGenerator::Latex); 
                                          
    }
  }
}

//----------------------------------------------------------------------------
// read a file with `name' to a string.

QString fileToString(const char *name)
{
  if (name==0 || name[0]==0) return 0;
  QFileInfo fi(name);
  if (!fi.exists() || !fi.isFile())
  {
    err("Error: file `%s' not found\n",name);
    exit(1);
  }
  QFile f(name);
  if (!f.open(IO_ReadOnly))
  {
    err("Error: cannot open file `%s'\n",name);
    exit(1);
  }
  int fsize=fi.size();
  QString contents(fsize+1);
  f.readBlock(contents.data(),fsize);
  contents[fsize]='\0';
  f.close();
  return contents;
}

QString dateToString(bool includeTime)
{
  if (includeTime)
  {
    return QDateTime::currentDateTime().toString();
  }
  else
  {
    const QDate &d=QDate::currentDate();
    QString result;
    result.sprintf("%d %s %d",
        d.day(),
        d.monthName(d.month()),
        d.year());
    return result;
  }
  //QDate date=dt.date();
  //QTime time=dt.time();
  //QString dtString;
  //dtString.sprintf("%02d:%02d, %04d/%02d/%02d",
  //    time.hour(),time.minute(),date.year(),date.month(),date.day());
  //return dtString;
}


//----------------------------------------------------------------------
// recursive function that returns the number of branches in the 
// inheritance tree that the base class `bcd' is below the class `cd'

static int minClassDistance(ClassDef *cd,ClassDef *bcd,int level=0)
{
  if (cd==bcd) return level; 
  BaseClassListIterator bcli(*cd->baseClasses());
  int m=maxInheritanceDepth; 
  for ( ; bcli.current() ; ++bcli)
  {
    m=QMIN(minClassDistance(bcli.current()->classDef,bcd,level+1),m);
  }
  return m;
}

//static void printArgList(ArgumentList *al)
//{
//  if (al==0) return;
//  ArgumentListIterator ali(*al);
//  Argument *a;
//  printf("(");
//  for (;(a=ali.current());++ali)
//  {
//    printf("t=`%s' n=`%s' v=`%s' ",a->type.data(),a->name.length()>0?a->name.data():"",a->defval.length()>0?a->defval.data():""); 
//  }
//  printf(")");
//}

// strip any template specifiers that follow className in string s
static QString trimTemplateSpecifiers(const QString &className,const QString &s)
{
  // first we resolve any defines
  //int i=0,p,l;
  //QString result;
  //QRegExp r("[A-Z_a-z][A-Z_a-z0-9]*");
  //while ((p=r.match(s,i,&l))!=-1)
  //{
  //  if (p>i) result+=s.mid(i,p-i);
  //  result+=resolveDefines(s.mid(p,l));
  //  i=p+l;
  //}
  //if (i<(int)s.length()) result+=s.mid(i,s.length()-i);
  
  // We strip the template arguments following className (if any)
  QString result=s.copy();
  int l=className.length();
  if (l>0) // there is a class name
  {
    int i,p=0;
    while ((i=result.find(className,p))!=-1) // class name is in the argument type
    {
      uint s=i+l;
      if (s<result.length() && result.at(s)=='<') // class has template args
      {
        int b=1;
        uint e=s+1;
        while (b>0 && e<result.length()) // find matching >
        {
          if (result.at(e)=='<') b++;
          else if (result.at(e)=='>') b--;
          e++;
        }
        // remove template argument
        result=result.left(s)+result.right(result.length()-e);
        if (result.length()>s && (result.at(s)=='*' || result.at(s)=='&'))
        {
          // insert a space to keep the argument in the canonical form
          result=result.left(s)+" "+result.right(result.length()-s);
        }
      }
      p=i+l;
    }
  }
  return result;
}

// removes the (one and only) occurrence of name:: from s.
static QString trimScope(const QString &name,const QString &s)
{
  int spos;
  spos=s.find(name+"::");
  if (spos!=-1)
  {
    return s.left(spos)+s.right(s.length()-spos-name.length()-2);
  }
  return s;
}

static QString trimBaseClassScope(BaseClassList *bcl,const QString &s)
{
  BaseClassListIterator bcli(*bcl);
  BaseClassDef *bcd;
  for (;(bcd=bcli.current());++bcli)
  {
    ClassDef *cd=bcd->classDef;
    int spos=s.find(cd->name());
    if (spos!=-1)
    {
      return s.left(spos)+s.right(
                      s.length()-spos-cd->name().length()-2
                     );
    }
    if (cd->baseClasses()->count()>0)
      trimBaseClassScope(cd->baseClasses(),s); 
  }
  return s;
}

//----------------------------------------------------------------------
// Matches the arguments list srcAl with the argument list dstAl
// Returns TRUE if the argument lists are equal. Two argument list are 
// considered equal if the number of arguments is equal and the types of all 
// arguments are equal. Furthermore the const and volatile specifiers 
// stored in the list should be equal.

bool matchArguments(ArgumentList *srcAl,ArgumentList *dstAl,
                    const char *cl,const char *ns)
{
  QString className=cl;
  QString namespaceName=ns;
  //printf("matchArguments(%s,%s) className=%s namespaceName=%s\n",
  //    srcAl ? argListToString(srcAl).data() : "",
  //    dstAl ? argListToString(dstAl).data() : "",
  //    cl,ns);
  if (srcAl==0 || dstAl==0)
  {
    return srcAl==dstAl; // at least one of the members is not a function
  }
  if ( srcAl->count()==0 && dstAl->count()==1 && 
       dstAl->getFirst()->type=="void" )
  { // special case for finding match between func() and func(void)
    Argument *a=new Argument;
    a->type = "void";
    srcAl->append(a);
  }
  if ( dstAl->count()==0 && srcAl->count()==1 &&
       srcAl->getFirst()->type=="void" )
  { // special case for finding match between func(void) and func()
    Argument *a=new Argument;
    a->type = "void";
    dstAl->append(a);
    return TRUE;
  }
  if (srcAl->count() != dstAl->count())
  {
    return FALSE; // different number of arguments -> no match
  }
  if (srcAl->constSpecifier != dstAl->constSpecifier) 
  {
    return FALSE; // one member is const, the other not -> no match
  }
  if (srcAl->volatileSpecifier != dstAl->volatileSpecifier)
  {
    return FALSE; // one member is volatile, the other not -> no match
  }

  // so far the argument list could match, so we need to compare the types of
  // all arguments.
  ArgumentListIterator srcAli(*srcAl),dstAli(*dstAl);
  Argument *srcA,*dstA;
  for (;(srcA=srcAli.current(),dstA=dstAli.current());++srcAli,++dstAli)
  {
    QString srcAType=trimTemplateSpecifiers(className,srcA->type);
    QString dstAType=trimTemplateSpecifiers(className,dstA->type);
    
    if (srcAType!=dstAType) // check if the argument only differs on name 
    {
      //printf("`%s' <=> `%s'\n",srcAType.data(),dstAType.data());

      QString srcScope;
      QString dstScope;

      // strip redundant scope specifiers
      if (!className.isEmpty())
      {
        srcAType=trimScope(className,srcAType);
        dstAType=trimScope(className,dstAType);
        ClassDef *cd=getClass(className);
        if (cd->baseClasses()->count()>0)
        {
          srcAType=trimBaseClassScope(cd->baseClasses(),srcAType); 
          dstAType=trimBaseClassScope(cd->baseClasses(),dstAType); 
        }
      }
      if (!namespaceName.isEmpty())
      {
        srcAType=trimScope(namespaceName,srcAType);
        dstAType=trimScope(namespaceName,dstAType);
      }
      
      //printf("`%s' <=> `%s'\n",srcAType.data(),dstAType.data());
      uint srcPos=0,dstPos=0; 
      bool equal=TRUE;
      while (srcPos<srcAType.length() && dstPos<dstAType.length() && equal)
      {
        equal=srcAType.at(srcPos)==dstAType.at(dstPos);
        if (equal) srcPos++,dstPos++; 
      }
      if (srcPos<srcAType.length() && dstPos<dstAType.length())
      {
        // if nothing matches or the match ends in the middle or at the
        // end of a string then there is no match
        //if (srcPos==0 || isalnum(srcAType.at(srcPos-1)) ||
        //    dstPos==0 || isalnum(dstAType.at(dstPos-1))) { printf("No match1\n"); return FALSE; }
        int srcStart=srcPos;
        int dstStart=dstPos;
        if (srcPos==0 || dstPos==0) return FALSE;
        if (isId(srcAType.at(srcPos)) && isId(dstAType.at(dstPos)))
        {
          // check if a name if already found -> if no then there is no match
          if (srcA->name.length()>0 || dstA->name.length()>0) return FALSE;
          while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++;
          while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++;
          if (srcPos<srcAType.length() || dstPos<dstAType.length()) return FALSE;
          // find the start of the name
          while (srcStart>=0 && isId(srcAType.at(srcStart))) srcStart--;
          while (dstStart>=0 && isId(dstAType.at(dstStart))) dstStart--;
          if (srcStart>0) // move the name from the type to the name field
          {
            srcA->name=srcAType.right(srcAType.length()-srcStart-1);
            srcA->type=srcAType.left(srcStart+1).stripWhiteSpace(); 
          } 
          if (dstStart>0) // move the name from the type to the name field
          {
            dstA->name=dstAType.right(dstAType.length()-dstStart-1);
            dstA->type=dstAType.left(dstStart+1).stripWhiteSpace(); 
          } 
        }
        else
        {
          // otherwise we assume that a name starts at the current position.
          while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++;
          while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++;
          // if nothing more follows for both types then we assume we have
          // found a match. Note that now `signed int' and `signed' match, but
          // seeing that int is not a name can only be done by looking at the
          // semantics.

          if (srcPos!=srcAType.length() || dstPos!=dstAType.length()) { return FALSE; }
          dstA->name=dstAType.right(dstAType.length()-dstStart);
          dstA->type=dstAType.left(dstStart).stripWhiteSpace();
          srcA->name=srcAType.right(dstAType.length()-srcStart);
          srcA->type=srcAType.left(srcStart).stripWhiteSpace();
        }
      }
      else if (dstPos<dstAType.length())
      {
        if (!isspace(dstAType.at(dstPos))) // maybe the names differ
        {
          int startPos=dstPos;
          while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++;
          if (dstPos!=dstAType.length()) return FALSE; // more than a difference in name -> no match
          while (startPos>=0 && isId(dstAType.at(startPos))) startPos--;
          if (startPos>0)
          {
            dstA->name=dstAType.right(dstAType.length()-startPos-1);
            dstA->type=dstAType.left(startPos+1).stripWhiteSpace(); 
          } 
        }
        else // maybe dst has a name while src has not
        {
          dstPos++;
          int startPos=dstPos;
          while (dstPos<dstAType.length() && isId(dstAType.at(dstPos))) dstPos++;
          if (dstPos!=dstAType.length()) return FALSE; // nope not a name -> no match
          else // its a name (most probably) so move it
          {
            dstA->name=dstAType.right(dstAType.length()-startPos);
            dstA->type=dstAType.left(startPos).stripWhiteSpace();
          }
        }
      }
      else if (srcPos<srcAType.length())
      {
        if (!isspace(srcAType.at(srcPos))) // maybe the names differ
        {
          int startPos=srcPos;
          while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++;
          if (srcPos!=srcAType.length()) return FALSE; // more than a difference in name -> no match
          while (startPos>=0 && isId(srcAType.at(startPos))) startPos--;
          if (startPos>0)
          {
            srcA->name=srcAType.right(srcAType.length()-startPos-1);
            srcA->type=srcAType.left(startPos+1).stripWhiteSpace(); 
          } 
        }
        else // maybe src has a name while dst has not
        {
          srcPos++;
          int startPos=srcPos;
          while (srcPos<srcAType.length() && isId(srcAType.at(srcPos))) srcPos++;
          if (srcPos!=srcAType.length()) return FALSE; // nope not a name -> no match
          else // its a name (most probably) so move it
          {
            srcA->name=srcAType.right(srcAType.length()-startPos);
            srcA->type=srcAType.left(startPos).stripWhiteSpace();
          }
        }
      }
      else // without scopes the names match exactly
      {
      }
    }
    else if (srcA->name.length()==0 && dstA->name.length()==0) 
                          // arguments match exactly but no name ->
                          // see if we can find the name
    {
      int i=srcAType.length()-1;
      while (i>=0 && isId(srcAType.at(i))) i--;
      if (i>0 && i<(int)srcAType.length()-1 && srcAType.at(i)!=':') 
        // there is (probably) a name
      {
        srcA->name=srcAType.right(srcAType.length()-i-1);
        srcA->type=srcAType.left(i+1).stripWhiteSpace();
        dstA->name=dstAType.right(dstAType.length()-i-1);
        dstA->type=dstAType.left(i+1).stripWhiteSpace();
      } 
    }
  }
  //printf("Match found!\n");
  return TRUE; // all arguments match 
}

// merges the initializer of two argument lists
// pre:  the types of the arguments in the list should match.
void mergeArguments(ArgumentList *srcAl,ArgumentList *dstAl)
{
  //printf("mergeArguments `%s', `%s'\n",
  //    argListToString(srcAl).data(),argListToString(dstAl).data());
  //printArgList(srcAl);printf(" <=> ");
  //printArgList(dstAl);printf("\n");
  if (srcAl==0 || dstAl==0 || srcAl->count()!=dstAl->count())
  {
    return; // invalid argument lists -> do not merge
  }

  ArgumentListIterator srcAli(*srcAl),dstAli(*dstAl);
  Argument *srcA,*dstA;
  for (;(srcA=srcAli.current(),dstA=dstAli.current());++srcAli,++dstAli)
  {
    if (srcA->defval.length()==0 && dstA->defval.length()>0)
    {
      //printf("Defval changing `%s'->`%s'\n",srcA->defval.data(),dstA->defval.data());
      srcA->defval=dstA->defval.copy();
    }
    else if (srcA->defval.length()>0 && dstA->defval.length()==0)
    {
      //printf("Defval changing `%s'->`%s'\n",dstA->defval.data(),srcA->defval.data());
      dstA->defval=srcA->defval.copy();
    }
    if (srcA->name.isEmpty() && !dstA->name.isEmpty())
    {
      //printf("type: `%s':=`%s'\n",srcA->type.data(),dstA->type.data());
      //printf("name: `%s':=`%s'\n",srcA->name.data(),dstA->name.data());
      srcA->type = dstA->type.copy();
      srcA->name = dstA->name.copy();
    }
    else if (!srcA->name.isEmpty() && dstA->name.isEmpty())
    {
      //printf("type: `%s':=`%s'\n",dstA->type.data(),srcA->type.data());
      //printf("name: `%s':=`%s'\n",dstA->name.data(),srcA->name.data());
      dstA->type = srcA->type.copy();
      dstA->name = dstA->name.copy();
    }
    int i1=srcA->type.find("::"),
        i2=dstA->type.find("::"),
        j1=srcA->type.length()-i1-2,
        j2=dstA->type.length()-i2-2;
    if (i1!=-1 && i2==-1 && srcA->type.right(j1)==dstA->type)
    {
      //printf("type: `%s':=`%s'\n",dstA->type.data(),srcA->type.data());
      //printf("name: `%s':=`%s'\n",dstA->name.data(),srcA->name.data());
      dstA->type = srcA->type.left(i1+2)+dstA->type;
      dstA->name = dstA->name.copy();
    }
    else if (i1==-1 && i2!=-1 && dstA->type.right(j2)==srcA->type)
    {
      //printf("type: `%s':=`%s'\n",srcA->type.data(),dstA->type.data());
      //printf("name: `%s':=`%s'\n",dstA->name.data(),srcA->name.data());
      srcA->type = dstA->type.left(i2+2)+srcA->type;
      srcA->name = dstA->name.copy();
    }
  }
  //printf("result mergeArguments `%s', `%s'\n",
  //    argListToString(srcAl).data(),argListToString(dstAl).data());
}

//----------------------------------------------------------------------
// searches for the class and member definitions corresponding with 
// memberName and className.
// These classes are returned using `md' and `cd'.
// returns TRUE if the class and member both could be found

bool getDefs(const QString &memberName,const QString &className, 
             const char *args,MemberDef *&md, ClassDef *&cd, FileDef *&fd)
{
  //printf("Search for %s::%s %s\n",className.data(),memberName.data(),args);
  fd=0; md=0; cd=0;
  if (memberName.length()==0) return FALSE;
  MemberName *mn;
  if ((mn=memberNameDict[memberName]) && className.length()>0)
  {
    //printf("  >member name found\n");
    ClassDef *fcd=0;
    if ((fcd=getClass(className)))
    {
      //printf("  >member class found\n");
      MemberDef *mmd=mn->first();
      int mdist=maxInheritanceDepth; 
      while (mmd)
      {
        if ((mmd->protection()!=Private || extractPrivateFlag) &&
            mmd->hasDocumentation() 
            /*mmd->detailsAreVisible()*/
            /* && (args==0 || matchArgumentsOld(mmd->argsString(),args)) */
            )
        {
          bool match=TRUE;
          ArgumentList *argList=0;
          if (args)
          {
            match=FALSE;
            argList=new ArgumentList;
            stringToArgumentList(args,argList);
            match=matchArguments(mmd->argumentList(),argList); 
          }
          if (match)
          {
            ClassDef *mcd=mmd->memberClass();
            int m=minClassDistance(fcd,mcd);
            if (m<mdist && mcd->isVisible())
            {
              mdist=m;
              cd=mcd;
              md=mmd;
              fd=0;
            }
          }
          if (argList)
          {
            delete argList;
          }
        }
        mmd=mn->next();
      }
      if (mdist==maxInheritanceDepth && !strcmp(args,"()"))
        // no exact match found, but if args="()" an arbitrary member will do
      {
        //printf("  >Searching for arbitrary member\n");
        mmd=mn->first();
        while (mmd)
        {
          if ((mmd->protection()!=Private || extractPrivateFlag) &&
              (
               mmd->hasDocumentation() 
               /*mmd->detailsAreVisible()*/
               || mmd->isReference()
              )
             )
          {
            ClassDef *mcd=mmd->memberClass();
            //printf("  >Class %s found\n",mcd->name().data());
            int m=minClassDistance(fcd,mcd);
            if (m<mdist && mcd->isVisible())
            {
              //printf("Class distance %d\n",m);
              mdist=m;
              cd=mcd;
              md=mmd;
              fd=0;
            }
          }
          mmd=mn->next();
        }
      }
      //printf("  >Succes=%d\n",mdist<maxInheritanceDepth);
      return mdist<maxInheritanceDepth;
    } 
  }
  else // maybe an unrelated member ?
  {
    MemberName *mn;
    if ((mn=functionNameDict[memberName])) 
    {
      md=mn->first();
      while (md)
      {
        if (/*md->detailsAreVisible()*/ md->hasDocumentation())
        {
          fd=md->getFileDef();
          if (fd && fd->hasDocumentation())
          {
            cd=0;
            return TRUE;
          }
        }
        md=mn->next();
      }
    }
  }
  return FALSE;
}

//----------------------------------------------------------------------
// Generate a hypertext link to the class with name `clName'.
// If linkTxt is not null this text is used as the link, otherwise
// the name of the class will be used. If the class could be found a 
// hypertext link (in HTML) is written, otherwise the text of the link will 
// be written.

void generateClassRef(OutputList &ol,const char *clName,const char *linkTxt)
{
  QString className=clName;
  QString linkText=linkTxt ? linkTxt : (const char *)className;
  if (className.length()==0) 
  {
    ol.docify(linkText);
    return;
  }
  ClassDef *cd;
  if ((cd=getClass(className)) && cd->isVisible())
  {
    ol.writeObjectLink(cd->getReference(),cd->classFile(),0,linkText);
    if (!cd->isReference()) ol.writePageRef(cd->name(),0);
  }
  else
    ol.docify(linkText);
}

//----------------------------------------------------------------------
// generate a reference to a class or member.
// `clName' is the name of the class that contains the documentation 
// string that is returned.
// `name' is the name of the member or class that we want to link to.
// `name' may have five formats:
//    1) "ClassName"
//    2) "memberName()"    one of the (overloaded) function or define 
//                         with name memberName.
//    3) "memberName(...)" a specific (overloaded) function or define 
//                         with name memberName
//    4) "::memberName     a non-function member or define
//    5) ("ClassName::")+"memberName()" 
//    6) ("ClassName::")+"memberName(...)" 
//    7) ("ClassName::")+"memberName" 

void generateRef(OutputList &ol,const char *clName,
                 const char *name,bool inSeeBlock,const char *rt)
{
  //printf("generateRef(clName=%s,name=%s,rt=%s)\n",clName,name,rt);
  
  // check if we have a plane name
  QString tmpName = substitute(name,"#","::");
  QString linkText = rt;
  int scopePos=tmpName.findRev("::");
  int bracePos=tmpName.find('(');
  if (scopePos==-1 && bracePos==-1)
  {
    if (!inSeeBlock) /* check for class link */
    {
      if (linkText.isNull()) linkText=tmpName;
      // check if this is a class reference
      if (clName!=tmpName) 
        generateClassRef(ol,name,linkText);
      else
        ol.docify(linkText);
      return;
    }
    else /* check if it is a class, if not continue to search */
    {
      if (clName!=tmpName && getClass(tmpName)!=0)
      {
        generateClassRef(ol,tmpName,linkText);
        return;
      }
    }
  }
  
  // extract scope
  QString scopeStr;
  if (scopePos>0) scopeStr=tmpName.left(scopePos); else scopeStr=clName;

  // extract name
  int startNamePos=scopePos!=-1 ? scopePos+2 : 0;
  int endNamePos=bracePos!=-1 ? bracePos : tmpName.length();
  QString nameStr=tmpName.mid(startNamePos,endNamePos-startNamePos);

  // extract arguments
  QString argsStr;
  if (bracePos!=-1) argsStr=tmpName.right(tmpName.length()-bracePos);
 
  bool explicitLink=TRUE;
  // create a default link text if none was explicitly given
  if (linkText.isNull())
  {
    if (!scopeStr.isNull() && scopePos>0) linkText=scopeStr+"::";
    linkText+=nameStr;
    explicitLink=FALSE;
  } 
  
  //printf("scope=`%s' name=`%s' arg=`%s' linkText=`%s'\n",
  //       scopeStr.data(),nameStr.data(),argsStr.data(),linkText.data());

  //Define *d=0;
  MemberDef *md;
  ClassDef *cd;
  FileDef *fd;
  // check if nameStr is a member or global.
  if (getDefs(nameStr,scopeStr,argsStr,md,cd,fd))
  {
    QString anchor = md->hasDocumentation() ? md->anchor() : 0;
    QString cName,aName;
    if (cd) // nameStr is a member of cd
    {
      //printf("addObjectLink(%s,%s,%s,%s)\n",cd->getReference(),
      //      cd->classFile(),anchor.data(),resultName.stripWhiteSpace().data());
      ol.writeObjectLink(cd->getReference(),
                        cd->classFile(),anchor,
                        linkText.stripWhiteSpace());
      cName=cd->name();
      aName=md->anchor();
    }
    else if (fd) // nameStr is a global in file fd
    {
      //printf("addFileLink(%s,%s,%s)\n",fd->diskName(),anchor.data(),
      //        resultName.stripWhiteSpace().data());
      ol.writeObjectLink(fd->getReference(),fd->diskName(),
                         anchor, linkText.stripWhiteSpace());
      cName=fd->name();
      aName=md->anchor();
    }
    else // should not be reached
    {
      //printf("add no link fd=cd=0\n");
      ol.docify(linkText);
    }
    
    // for functions we add the arguments if explicitly specified or else "()"
    if (!rt && (md->isFunction() || md->isPrototype() || md->isSignal() || md->isSlot())) 
    {
      if (argsStr.isNull())
        ol.writeString("()");
      else
        ol.docify(argsStr);
    }
    
    // generate the page reference (for LaTeX)
    if (cName.length()>0 || aName.length()>0)
    {
      if (/*md->detailsAreVisible() &&*/
          (
           (cd && !cd->isReference() &&
          // (cd->hasDocumentation() || !hideClassFlag) &&
          // (cd->protection()!=Private || extractPrivateFlag)
            cd->isVisible()
           ) || 
           (fd && !fd->isReference())
          )
         ) ol.writePageRef(cName,aName);
    }
  }
//  else if (!nameStr.isNull() && (d=defineDict[nameStr]))
//     // check if nameStr is perhaps a define
//  {
//    if (d->hasDocumentation() && d->fileDef)
//    {
//      ol.writeObjectLink(0,d->fileDef->diskName(),d->anchor,
//                         linkText.stripWhiteSpace());
//      if (!explicitLink) ol.docify(argsStr);
//    }
//  }
  else // nameStr is a false alarm or a typo.
  {
    if (rt) 
      ol.docify(rt); 
    else 
    {
      ol.docify(linkText);
      if (!argsStr.isNull()) ol.docify(argsStr);
    }
  }
  return;
}

//----------------------------------------------------------------------
// General function that generates the HTML code for a reference to some
// file, class or member from text `lr' within the context of class `clName'. 
// This link has the text 'lt' (if not 0), otherwise `lr' is used as a
// basis for the link's text.

void generateLink(OutputList &ol,const char *clName,
                     const char *lr,bool inSeeBlock,const char *lt)
{
  QString linkRef=lr;
  //PageInfo *pi=0;
  //printf("generateLink(%s,%s)\n",lr,lt);
  //FileInfo *fi=0;
  FileDef *fd;
  bool ambig;
  if (linkRef.length()==0) // no reference name!
    ol.docify(lt);
  else if ((pageDict[linkRef])) // link to a page
    ol.writeObjectLink(0,linkRef,0,lt);  
  else if ((exampleDict[linkRef])) // link to an example
    ol.writeObjectLink(0,linkRef+"-example",0,lt);
  else if ((fd=findFileDef(&inputNameDict,linkRef,ambig))
       && fd->hasDocumentation())
        // link to documented input file
    ol.writeObjectLink(fd->getReference(),fd->diskName(),0,lt);
  else // probably a class or member reference
    generateRef(ol,clName,lr,inSeeBlock,lt);
}

void generateFileRef(OutputList &ol,const char *name,const char *text)
{
  QString linkText = text ? text : name;
  //FileInfo *fi;
  FileDef *fd;
  bool ambig;
  if ((fd=findFileDef(&inputNameDict,name,ambig)) && 
      fd->hasDocumentation()) 
    // link to documented input file
    ol.writeObjectLink(fd->getReference(),fd->diskName(),0,linkText);
  else
    ol.docify(linkText); 
}

//----------------------------------------------------------------------

QString substituteClassNames(const QString &s)
{
  int i=0,l,p;
  QString result;
  QRegExp r("[a-z_A-Z][a-z_A-Z0-9]*");
  while ((p=r.match(s,i,&l))!=-1)
  {
    QString *subst;
    if (p>i) result+=s.mid(i,p-i);
    if ((subst=substituteDict[s.mid(p,l)]))
    {
      result+=*subst;
    }
    else
    {
      result+=s.mid(p,l);
    }
    i=p+l;
  }
  result+=s.mid(i,s.length()-i);
  return result;
}

//----------------------------------------------------------------------

QString convertSlashes(const QString &s,bool dots)
{
  QString result;
  int i,l=s.length();
  for (i=0;i<l;i++)
    if (s.at(i)!='/' && (!dots || s.at(i)!='.'))
    {
      if (caseSensitiveNames)
      {
        result+=s[i]; 
      }
      else
      {
        result+=tolower(s[i]); 
      }
    }
    else 
      result+="_";
  return result;
}

//----------------------------------------------------------------------
// substitute all occurences of `src' in `s' by `dst'

QString substitute(const char *s,const char *src,const char *dst)
{
  QString input=s;
  QString output;
  int i=0,p;
  while ((p=input.find(src,i))!=-1)
  {
    output+=input.mid(i,p-i);
    output+=dst;
    i=p+strlen(src);
  }
  output+=input.mid(i,input.length()-i);
  return output;
}

//----------------------------------------------------------------------

FileDef *findFileDef(const FileNameDict *fnDict,const char *n,bool &ambig)
{
  ambig=FALSE;
  QString name=n;
  QString path;
  if (name.isNull()) return 0;
  int slashPos=QMAX(name.findRev('/'),name.findRev('\\'));
  if (slashPos!=-1)
  {
    path=name.left(slashPos+1);
    name=name.right(name.length()-slashPos-1); 
  }
  //printf("findFileDef path=`%s' name=`%s'\n",path.data(),name.data());
  if (name.isNull()) return 0;
  FileName *fn;
  if ((fn=(*fnDict)[name]))
  {
    if (fn->count()==1)
    {
      return fn->first();
    }
    else // file name alone is ambigious
    {
      int count=0;
      FileDef *fd=fn->first();
      FileDef *lastMatch=0;
      while (fd)
      {
        if (path.isNull() || fd->getPath().right(path.length())==path) 
        { 
          count++; 
          lastMatch=fd; 
        }
        fd=fn->next();
      }
      ambig=(count>1);
      return lastMatch;
    }
  }
  return 0;
}

//----------------------------------------------------------------------

void showFileDefMatches(const FileNameDict *fnDict,const char *n)
{
  QString name=n;
  QString path;
  int slashPos=QMAX(name.findRev('/'),name.findRev('\\'));
  if (slashPos!=-1)
  {
    path=name.left(slashPos+1);
    name=name.right(name.length()-slashPos-1); 
  }
  FileName *fn;
  if ((fn=(*fnDict)[name]))
  {
    FileDef *fd=fn->first();
    while (fd)
    {
      if (path.isNull() || fd->getPath().right(path.length())==path)
      {
        msg("   %s\n",fd->absFilePath().data());
      }
      fd=fn->next();
    }
  }
}