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
|
/******************************************************************************
*
* Copyright (C) 1997-2020 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.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#include <algorithm>
#include "dirdef.h"
#include "md5.h"
#include "filename.h"
#include "doxygen.h"
#include "util.h"
#include "outputlist.h"
#include "language.h"
#include "message.h"
#include "dot.h"
#include "dotdirdeps.h"
#include "layout.h"
#include "ftextstream.h"
#include "config.h"
#include "docparser.h"
#include "definitionimpl.h"
#include "filedef.h"
//----------------------------------------------------------------------
class DirDefImpl : public DefinitionMixin<DirDef>
{
public:
DirDefImpl(const char *path);
virtual ~DirDefImpl();
virtual DefType definitionType() const { return TypeDir; }
virtual QCString getOutputFileBase() const;
virtual QCString anchor() const { return QCString(); }
virtual bool isLinkableInProject() const;
virtual bool isLinkable() const;
virtual QCString displayName(bool=TRUE) const { return m_dispName; }
virtual const QCString &shortName() const { return m_shortName; }
virtual void addSubDir(DirDef *subdir);
virtual FileList * getFiles() const { return m_fileList; }
virtual void addFile(FileDef *fd);
virtual const DirList &subDirs() const { return m_subdirs; }
virtual bool isCluster() const { return m_subdirs.size()>0; }
virtual int level() const { return m_level; }
virtual DirDef *parent() const { return m_parent; }
virtual int dirCount() const { return m_dirCount; }
virtual const UsedDirLinkedMap &usedDirs() const { return m_usedDirs; }
virtual bool isParentOf(const DirDef *dir) const;
virtual bool depGraphIsTrivial() const;
virtual QCString shortTitle() const;
virtual bool hasDetailedDescription() const;
virtual void writeDocumentation(OutputList &ol);
virtual void writeTagFile(FTextStream &t);
virtual void setDiskName(const QCString &name) { m_diskName = name; }
virtual void sort();
virtual void setParent(DirDef *parent);
virtual void setLevel();
virtual void addUsesDependency(DirDef *usedDir,FileDef *srcFd,
FileDef *dstFd,bool inherited);
virtual void computeDependencies();
public:
static DirDef *mergeDirectoryInTree(const QCString &path);
private:
void writeDetailedDescription(OutputList &ol,const QCString &title);
void writeBriefDescription(OutputList &ol);
void writeDirectoryGraph(OutputList &ol);
void writeSubDirList(OutputList &ol);
void writeFileList(OutputList &ol);
void startMemberDeclarations(OutputList &ol);
void endMemberDeclarations(OutputList &ol);
static DirDef *createNewDir(const char *path);
static bool matchPath(const QCString &path,const StringVector &l);
DirList m_subdirs;
QCString m_dispName;
QCString m_shortName;
QCString m_diskName;
FileList *m_fileList; // list of files in the group
int m_dirCount;
int m_level;
DirDef *m_parent;
UsedDirLinkedMap m_usedDirs;
};
DirDef *createDirDef(const char *path)
{
return new DirDefImpl(path);
}
//----------------------------------------------------------------------
// method implementation
static int g_dirCount=0;
DirDefImpl::DirDefImpl(const char *path) : DefinitionMixin(path,1,1,path)
{
bool fullPathNames = Config_getBool(FULL_PATH_NAMES);
// get display name (stripping the paths mentioned in STRIP_FROM_PATH)
// get short name (last part of path)
m_shortName = path;
m_diskName = path;
if (m_shortName.at(m_shortName.length()-1)=='/')
{ // strip trailing /
m_shortName = m_shortName.left(m_shortName.length()-1);
}
int pi=m_shortName.findRev('/');
if (pi!=-1)
{ // remove everything till the last /
m_shortName = m_shortName.mid(pi+1);
}
setLocalName(m_shortName);
m_dispName = fullPathNames ? stripFromPath(path) : m_shortName;
if (m_dispName.length()>0 && m_dispName.at(m_dispName.length()-1)=='/')
{ // strip trailing /
m_dispName = m_dispName.left(m_dispName.length()-1);
}
m_fileList = new FileList;
m_dirCount = g_dirCount++;
m_level=-1;
m_parent=0;
}
DirDefImpl::~DirDefImpl()
{
delete m_fileList;
}
bool DirDefImpl::isLinkableInProject() const
{
return !isReference();
}
bool DirDefImpl::isLinkable() const
{
return isReference() || isLinkableInProject();
}
void DirDefImpl::addSubDir(DirDef *subdir)
{
m_subdirs.push_back(subdir);
subdir->setOuterScope(this);
subdir->setParent(this);
}
void DirDefImpl::setParent(DirDef *p)
{
m_parent=p;
}
void DirDefImpl::addFile(FileDef *fd)
{
m_fileList->append(fd);
fd->setDirDef(this);
}
void DirDefImpl::sort()
{
std::sort(m_subdirs.begin(), m_subdirs.end(), compareDirDefs);
m_fileList->sort();
}
static QCString encodeDirName(const QCString &anchor)
{
// convert to md5 hash
uchar md5_sig[16];
QCString sigStr(33);
MD5Buffer((const unsigned char *)anchor.data(),anchor.length(),md5_sig);
MD5SigToString(md5_sig,sigStr.rawData(),33);
return sigStr;
// old algorithm
// QCString result;
// int l = anchor.length(),i;
// for (i=0;i<l;i++)
// {
// char c = anchor.at(i);
// if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9'))
// {
// result+=c;
// }
// else
// {
// static char hexStr[]="0123456789ABCDEF";
// char escChar[]={ '_', 0, 0, 0 };
// escChar[1]=hexStr[c>>4];
// escChar[2]=hexStr[c&0xf];
// result+=escChar;
// }
// }
// return result;
}
QCString DirDefImpl::getOutputFileBase() const
{
//printf("DirDefImpl::getOutputFileBase() %s->dir_%s\n",
// m_diskName.data(),encodeDirName(m_diskName).data());
return "dir_"+encodeDirName(m_diskName);
}
void DirDefImpl::writeDetailedDescription(OutputList &ol,const QCString &title)
{
if ((!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF)) ||
!documentation().isEmpty())
{
ol.pushGeneratorState();
ol.disable(OutputGenerator::Html);
ol.writeRuler();
ol.popGeneratorState();
ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Html);
ol.writeAnchor(0,"details");
ol.popGeneratorState();
ol.startGroupHeader();
ol.parseText(title);
ol.endGroupHeader();
// repeat brief description
if (!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF))
{
ol.generateDoc(briefFile(),briefLine(),this,0,briefDescription(),FALSE,FALSE,
0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT));
}
// separator between brief and details
if (!briefDescription().isEmpty() && Config_getBool(REPEAT_BRIEF) &&
!documentation().isEmpty())
{
ol.pushGeneratorState();
ol.disable(OutputGenerator::Man);
ol.disable(OutputGenerator::RTF);
// ol.newParagraph(); // FIXME:PARA
ol.enableAll();
ol.disableAllBut(OutputGenerator::Man);
ol.enable(OutputGenerator::Latex);
ol.writeString("\n\n");
ol.popGeneratorState();
}
// write documentation
if (!documentation().isEmpty())
{
ol.generateDoc(docFile(),docLine(),this,0,documentation()+"\n",TRUE,FALSE,
0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT));
}
}
}
void DirDefImpl::writeBriefDescription(OutputList &ol)
{
if (hasBriefDescription())
{
DocRoot *rootNode = validatingParseDoc(
briefFile(),briefLine(),this,0,briefDescription(),TRUE,FALSE,
0,FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT));
if (rootNode && !rootNode->isEmpty())
{
ol.startParagraph();
ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Man);
ol.writeString(" - ");
ol.popGeneratorState();
ol.writeDoc(rootNode,this,0);
ol.pushGeneratorState();
ol.disable(OutputGenerator::RTF);
ol.writeString(" \n");
ol.enable(OutputGenerator::RTF);
if (Config_getBool(REPEAT_BRIEF) ||
!documentation().isEmpty()
)
{
ol.disableAllBut(OutputGenerator::Html);
ol.startTextLink(0,"details");
ol.parseText(theTranslator->trMore());
ol.endTextLink();
}
ol.popGeneratorState();
ol.endParagraph();
}
delete rootNode;
}
ol.writeSynopsis();
}
void DirDefImpl::writeDirectoryGraph(OutputList &ol)
{
// write graph dependency graph
if (Config_getBool(DIRECTORY_GRAPH) && Config_getBool(HAVE_DOT))
{
DotDirDeps dirDep(this);
if (!dirDep.isTrivial())
{
msg("Generating dependency graph for directory %s\n",displayName().data());
ol.disable(OutputGenerator::Man);
//ol.startParagraph();
ol.startDirDepGraph();
ol.parseText(theTranslator->trDirDepGraph(shortName()));
ol.endDirDepGraph(dirDep);
//ol.endParagraph();
ol.enableAll();
}
}
}
void DirDefImpl::writeSubDirList(OutputList &ol)
{
int numSubdirs = 0;
for(const auto dd : m_subdirs)
{
if (dd->hasDocumentation() || dd->getFiles()->count()>0)
{
numSubdirs++;
}
}
// write subdir list
if (numSubdirs>0)
{
ol.startMemberHeader("subdirs");
ol.parseText(theTranslator->trDir(TRUE,FALSE));
ol.endMemberHeader();
ol.startMemberList();
for(const auto dd : m_subdirs)
{
if (dd->hasDocumentation() || dd->getFiles()->count()==0)
{
ol.startMemberDeclaration();
ol.startMemberItem(dd->getOutputFileBase(),0);
ol.parseText(theTranslator->trDir(FALSE,TRUE)+" ");
ol.insertMemberAlign();
ol.writeObjectLink(dd->getReference(),dd->getOutputFileBase(),0,dd->shortName());
ol.endMemberItem();
if (!dd->briefDescription().isEmpty() && Config_getBool(BRIEF_MEMBER_DESC))
{
ol.startMemberDescription(dd->getOutputFileBase());
ol.generateDoc(briefFile(),briefLine(),dd,0,dd->briefDescription(),
FALSE, // indexWords
FALSE, // isExample
0, // exampleName
TRUE, // single line
TRUE, // link from index
Config_getBool(MARKDOWN_SUPPORT)
);
ol.endMemberDescription();
}
ol.endMemberDeclaration(0,0);
}
}
ol.endMemberList();
}
}
void DirDefImpl::writeFileList(OutputList &ol)
{
int numFiles = 0;
QListIterator<FileDef> it(*m_fileList);
FileDef *fd;
for (it.toFirst();(fd=it.current());++it)
{
if (fd->hasDocumentation())
{
numFiles++;
}
}
// write file list
if (numFiles>0)
{
ol.startMemberHeader("files");
ol.parseText(theTranslator->trFile(TRUE,FALSE));
ol.endMemberHeader();
ol.startMemberList();
for (it.toFirst();(fd=it.current());++it)
{
if (fd->hasDocumentation())
{
ol.startMemberDeclaration();
ol.startMemberItem(fd->getOutputFileBase(),0);
ol.docify(theTranslator->trFile(FALSE,TRUE)+" ");
ol.insertMemberAlign();
if (fd->isLinkable())
{
ol.writeObjectLink(fd->getReference(),fd->getOutputFileBase(),0,fd->name());
}
else
{
ol.startBold();
ol.docify(fd->name());
ol.endBold();
}
if (fd->generateSourceFile())
{
ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Html);
ol.docify(" ");
ol.startTextLink(fd->includeName(),0);
ol.docify("[");
ol.parseText(theTranslator->trCode());
ol.docify("]");
ol.endTextLink();
ol.popGeneratorState();
}
ol.endMemberItem();
if (!fd->briefDescription().isEmpty() && Config_getBool(BRIEF_MEMBER_DESC))
{
ol.startMemberDescription(fd->getOutputFileBase());
ol.generateDoc(briefFile(),briefLine(),fd,0,fd->briefDescription(),
FALSE, // indexWords
FALSE, // isExample
0, // exampleName
TRUE, // single line
TRUE, // link from index
Config_getBool(MARKDOWN_SUPPORT)
);
ol.endMemberDescription();
}
ol.endMemberDeclaration(0,0);
}
}
ol.endMemberList();
}
}
void DirDefImpl::startMemberDeclarations(OutputList &ol)
{
ol.startMemberSections();
}
void DirDefImpl::endMemberDeclarations(OutputList &ol)
{
ol.endMemberSections();
}
QCString DirDefImpl::shortTitle() const
{
return theTranslator->trDirReference(m_shortName);
}
bool DirDefImpl::hasDetailedDescription() const
{
static bool repeatBrief = Config_getBool(REPEAT_BRIEF);
return (!briefDescription().isEmpty() && repeatBrief) || !documentation().isEmpty();
}
void DirDefImpl::writeTagFile(FTextStream &tagFile)
{
tagFile << " <compound kind=\"dir\">" << endl;
tagFile << " <name>" << convertToXML(displayName()) << "</name>" << endl;
tagFile << " <path>" << convertToXML(name()) << "</path>" << endl;
tagFile << " <filename>" << convertToXML(getOutputFileBase()) << Doxygen::htmlFileExtension << "</filename>" << endl;
QListIterator<LayoutDocEntry> eli(
LayoutDocManager::instance().docEntries(LayoutDocManager::Directory));
LayoutDocEntry *lde;
for (eli.toFirst();(lde=eli.current());++eli)
{
switch (lde->kind())
{
case LayoutDocEntry::DirSubDirs:
{
if (m_subdirs.size()>0)
{
for(const auto dd : m_subdirs)
{
tagFile << " <dir>" << convertToXML(dd->displayName()) << "</dir>" << endl;
}
}
}
break;
case LayoutDocEntry::DirFiles:
{
if (m_fileList->count()>0)
{
QListIterator<FileDef> it(*m_fileList);
FileDef *fd;
for (;(fd=it.current());++it)
{
tagFile << " <file>" << convertToXML(fd->name()) << "</file>" << endl;
}
}
}
break;
default:
break;
}
}
writeDocAnchorsToTagFile(tagFile);
tagFile << " </compound>" << endl;
}
void DirDefImpl::writeDocumentation(OutputList &ol)
{
static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
ol.pushGeneratorState();
QCString title=theTranslator->trDirReference(m_dispName);
startFile(ol,getOutputFileBase(),name(),title,HLI_Files,!generateTreeView);
if (!generateTreeView)
{
// write navigation path
writeNavigationPath(ol);
ol.endQuickIndices();
}
startTitle(ol,getOutputFileBase());
ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Html);
ol.parseText(shortTitle());
ol.enableAll();
ol.disable(OutputGenerator::Html);
ol.parseText(title);
ol.popGeneratorState();
endTitle(ol,getOutputFileBase(),title);
ol.startContents();
//---------------------------------------- start flexible part -------------------------------
SrcLangExt lang = getLanguage();
QListIterator<LayoutDocEntry> eli(
LayoutDocManager::instance().docEntries(LayoutDocManager::Directory));
LayoutDocEntry *lde;
for (eli.toFirst();(lde=eli.current());++eli)
{
switch (lde->kind())
{
case LayoutDocEntry::BriefDesc:
writeBriefDescription(ol);
break;
case LayoutDocEntry::DirGraph:
writeDirectoryGraph(ol);
break;
case LayoutDocEntry::MemberDeclStart:
startMemberDeclarations(ol);
break;
case LayoutDocEntry::DirSubDirs:
writeSubDirList(ol);
break;
case LayoutDocEntry::DirFiles:
writeFileList(ol);
break;
case LayoutDocEntry::MemberDeclEnd:
endMemberDeclarations(ol);
break;
case LayoutDocEntry::DetailedDesc:
{
LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
writeDetailedDescription(ol,ls->title(lang));
}
break;
case LayoutDocEntry::ClassIncludes:
case LayoutDocEntry::ClassInlineClasses:
case LayoutDocEntry::ClassInheritanceGraph:
case LayoutDocEntry::ClassNestedClasses:
case LayoutDocEntry::ClassCollaborationGraph:
case LayoutDocEntry::ClassAllMembersLink:
case LayoutDocEntry::ClassUsedFiles:
case LayoutDocEntry::NamespaceNestedNamespaces:
case LayoutDocEntry::NamespaceNestedConstantGroups:
case LayoutDocEntry::NamespaceClasses:
case LayoutDocEntry::NamespaceInterfaces:
case LayoutDocEntry::NamespaceStructs:
case LayoutDocEntry::NamespaceExceptions:
case LayoutDocEntry::NamespaceInlineClasses:
case LayoutDocEntry::FileClasses:
case LayoutDocEntry::FileInterfaces:
case LayoutDocEntry::FileStructs:
case LayoutDocEntry::FileExceptions:
case LayoutDocEntry::FileNamespaces:
case LayoutDocEntry::FileConstantGroups:
case LayoutDocEntry::FileIncludes:
case LayoutDocEntry::FileIncludeGraph:
case LayoutDocEntry::FileIncludedByGraph:
case LayoutDocEntry::FileSourceLink:
case LayoutDocEntry::FileInlineClasses:
case LayoutDocEntry::GroupClasses:
case LayoutDocEntry::GroupInlineClasses:
case LayoutDocEntry::GroupNamespaces:
case LayoutDocEntry::GroupDirs:
case LayoutDocEntry::GroupNestedGroups:
case LayoutDocEntry::GroupFiles:
case LayoutDocEntry::GroupGraph:
case LayoutDocEntry::GroupPageDocs:
case LayoutDocEntry::AuthorSection:
case LayoutDocEntry::MemberGroups:
case LayoutDocEntry::MemberDecl:
case LayoutDocEntry::MemberDef:
case LayoutDocEntry::MemberDefStart:
case LayoutDocEntry::MemberDefEnd:
err("Internal inconsistency: member %d should not be part of "
"LayoutDocManager::Directory entry list\n",lde->kind());
break;
}
}
//---------------------------------------- end flexible part -------------------------------
ol.endContents();
endFileWithNavPath(this,ol);
ol.popGeneratorState();
}
void DirDefImpl::setLevel()
{
if (m_level==-1) // level not set before
{
DirDef *p = parent();
if (p)
{
p->setLevel();
m_level = p->level()+1;
}
else
{
m_level = 0;
}
}
}
/** Add as "uses" dependency between \a this dir and \a dir,
* that was caused by a dependency on file \a fd.
*/
void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd,
FileDef *dstFd,bool inherited)
{
if (this==dir) return; // do not add self-dependencies
//static int count=0;
//printf(" %d add dependency %s->%s due to %s->%s\n",
// count++,shortName().data(),
// dir->shortName().data(),
// srcFd->name().data(),
// dstFd->name().data());
// levels match => add direct dependency
bool added=FALSE;
UsedDir *usedDir = m_usedDirs.find(dir->getOutputFileBase());
if (usedDir) // dir dependency already present
{
const FilePair *usedPair = usedDir->findFilePair(
srcFd->getOutputFileBase()+dstFd->getOutputFileBase());
if (usedPair==0) // new file dependency
{
//printf(" => new file\n");
usedDir->addFileDep(srcFd,dstFd);
added=TRUE;
}
else
{
// dir & file dependency already added
}
}
else // new directory dependency
{
//printf(" => new file\n");
auto newUsedDir = std::make_unique<UsedDir>(dir,inherited);
newUsedDir->addFileDep(srcFd,dstFd);
usedDir = m_usedDirs.add(dir->getOutputFileBase(),std::move(newUsedDir));
added=TRUE;
}
if (added)
{
if (dir->parent())
{
// add relation to parent of used dir
addUsesDependency(dir->parent(),srcFd,dstFd,inherited);
}
if (parent())
{
// add relation for the parent of this dir as well
parent()->addUsesDependency(dir,srcFd,dstFd,TRUE);
}
}
}
/** Computes the dependencies between directories
*/
void DirDefImpl::computeDependencies()
{
FileList *fl = m_fileList;
if (fl)
{
QListIterator<FileDef> fli(*fl);
FileDef *fd;
for (fli.toFirst();(fd=fli.current());++fli) // foreach file in dir dd
{
//printf(" File %s\n",fd->name().data());
//printf("** dir=%s file=%s\n",shortName().data(),fd->name().data());
QList<IncludeInfo> *ifl = fd->includeFileList();
if (ifl)
{
QListIterator<IncludeInfo> ifli(*ifl);
IncludeInfo *ii;
for (ifli.toFirst();(ii=ifli.current());++ifli) // foreach include file
{
//printf(" > %s\n",ii->includeName.data());
//printf(" #include %s\n",ii->includeName.data());
if (ii->fileDef && ii->fileDef->isLinkable()) // linkable file
{
DirDef *usedDir = ii->fileDef->getDirDef();
if (usedDir)
{
// add dependency: thisDir->usedDir
//static int count=0;
//printf(" %d: add dependency %s->%s\n",count++,name().data(),usedDir->name().data());
addUsesDependency(usedDir,fd,ii->fileDef,FALSE);
}
}
}
}
}
}
std::sort(m_usedDirs.begin(),m_usedDirs.end(),
[](const auto &u1,const auto &u2)
{ return qstricmp(u1->dir()->getOutputFileBase(),u2->dir()->getOutputFileBase())<0; });
for (const auto& usedDirectory : m_usedDirs)
{
usedDirectory->sort();
}
}
bool DirDefImpl::isParentOf(const DirDef *dir) const
{
if (dir->parent()==this) // this is a parent of dir
return TRUE;
else if (dir->parent()) // repeat for the parent of dir
return isParentOf(dir->parent());
else
return FALSE;
}
bool DirDefImpl::depGraphIsTrivial() const
{
return m_usedDirs.empty();
}
//----------------------------------------------------------------------
int FilePairDict::compareValues(const FilePair *left,const FilePair *right) const
{
int orderHi = qstricmp(left->source()->name(),right->source()->name());
if (orderHi!=0) return orderHi;
int orderLo = qstricmp(left->destination()->name(),right->destination()->name());
return orderLo;
}
//----------------------------------------------------------------------
UsedDir::UsedDir(const DirDef *dir,bool inherited) :
m_dir(dir), m_filePairs(7), m_inherited(inherited)
{
m_filePairs.setAutoDelete(TRUE);
}
UsedDir::~UsedDir()
{
}
void UsedDir::addFileDep(FileDef *srcFd,FileDef *dstFd)
{
m_filePairs.append(srcFd->getOutputFileBase()+dstFd->getOutputFileBase(),
new FilePair(srcFd,dstFd));
}
void UsedDir::sort()
{
m_filePairs.sort();
}
FilePair *UsedDir::findFilePair(const char *name)
{
QCString n=name;
return n.isEmpty() ? 0 : m_filePairs.find(n);
}
DirDef *DirDefImpl::createNewDir(const char *path)
{
ASSERT(path!=0);
DirDef *dir = Doxygen::dirLinkedMap->find(path);
if (dir==0) // new dir
{
dir = Doxygen::dirLinkedMap->add(path,
std::unique_ptr<DirDef>(
createDirDef(path)));
//printf("Adding new dir %s\n",path);
//printf("createNewDir %s short=%s\n",path,dir->shortName().data());
}
return dir;
}
bool DirDefImpl::matchPath(const QCString &path,const StringVector &l)
{
for (const auto &s : l)
{
std::string prefix = s.substr(0,path.length());
if (qstricmp(prefix.c_str(),path)==0) // case insensitive compare
{
return TRUE;
}
}
return FALSE;
}
/*! strip part of \a path if it matches
* one of the paths in the Config_getList(STRIP_FROM_PATH) list
*/
DirDef *DirDefImpl::mergeDirectoryInTree(const QCString &path)
{
//printf("DirDefImpl::mergeDirectoryInTree(%s)\n",path.data());
int p=0,i=0;
DirDef *dir=0;
while ((i=path.find('/',p))!=-1)
{
QCString part=path.left(i+1);
if (!matchPath(part,Config_getList(STRIP_FROM_PATH)) && (part!="/" && part!="//"))
{
dir=createNewDir(part);
}
p=i+1;
}
return dir;
}
//----------------------------------------------------------------------
static void writePartialDirPath(OutputList &ol,const DirDef *root,const DirDef *target)
{
if (target->parent()!=root)
{
writePartialDirPath(ol,root,target->parent());
ol.writeString(" / ");
}
ol.writeObjectLink(target->getReference(),target->getOutputFileBase(),0,target->shortName());
}
static void writePartialFilePath(OutputList &ol,const DirDef *root,const FileDef *fd)
{
if (fd->getDirDef() && fd->getDirDef()!=root)
{
writePartialDirPath(ol,root,fd->getDirDef());
ol.writeString(" / ");
}
if (fd->isLinkable())
{
ol.writeObjectLink(fd->getReference(),fd->getOutputFileBase(),0,fd->name());
}
else
{
ol.startBold();
ol.docify(fd->name());
ol.endBold();
}
}
void DirRelation::writeDocumentation(OutputList &ol)
{
static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
ol.pushGeneratorState();
ol.disableAllBut(OutputGenerator::Html);
QCString shortTitle=theTranslator->trDirRelation(
m_src->shortName()+" → "+
m_dst->dir()->shortName());
QCString title=theTranslator->trDirRelation(
m_src->displayName()+" -> "+
m_dst->dir()->shortName());
startFile(ol,getOutputFileBase(),getOutputFileBase(),
title,HLI_None,!generateTreeView,m_src->getOutputFileBase());
if (!generateTreeView)
{
// write navigation path
m_src->writeNavigationPath(ol);
ol.endQuickIndices();
}
ol.startContents();
ol.writeString("<h3>"+shortTitle+"</h3>");
ol.writeString("<table class=\"dirtab\">");
ol.writeString("<tr class=\"dirtab\">");
ol.writeString("<th class=\"dirtab\">");
ol.parseText(theTranslator->trFileIn(m_src->pathFragment()));
ol.writeString("</th>");
ol.writeString("<th class=\"dirtab\">");
ol.parseText(theTranslator->trIncludesFileIn(m_dst->dir()->pathFragment()));
ol.writeString("</th>");
ol.writeString("</tr>");
SDict<FilePair>::Iterator fpi(m_dst->filePairs());
FilePair *fp;
for (fpi.toFirst();(fp=fpi.current());++fpi)
{
ol.writeString("<tr class=\"dirtab\">");
ol.writeString("<td class=\"dirtab\">");
writePartialFilePath(ol,m_src,fp->source());
ol.writeString("</td>");
ol.writeString("<td class=\"dirtab\">");
writePartialFilePath(ol,m_dst->dir(),fp->destination());
ol.writeString("</td>");
ol.writeString("</tr>");
}
ol.writeString("</table>");
ol.endContents();
endFileWithNavPath(m_src,ol);
ol.popGeneratorState();
}
//----------------------------------------------------------------------
// external functions
/** In order to create stable, but unique directory names,
* we compute the common part of the path shared by all directories.
*/
static void computeCommonDirPrefix()
{
QCString path;
auto it = Doxygen::dirLinkedMap->begin();
if (!Doxygen::dirLinkedMap->empty()) // we have at least one dir
{
// start will full path of first dir
path=(*it)->name();
int i=path.findRev('/',(int)path.length()-2);
path=path.left(i+1);
bool done=FALSE;
if (i==-1)
{
path="";
}
else
{
while (!done)
{
uint l = path.length();
size_t count=0;
for (const auto &dir : *Doxygen::dirLinkedMap)
{
QCString dirName = dir->name();
if (dirName.length()>path.length())
{
if (qstrncmp(dirName,path,l)!=0) // dirName does not start with path
{
i=path.findRev('/',(int)l-2);
if (i==-1) // no unique prefix -> stop
{
path="";
done=TRUE;
}
else // restart with shorter path
{
path=path.left(i+1);
break;
}
}
}
else // dir is shorter than path -> take path of dir as new start
{
path=dir->name();
l=path.length();
i=path.findRev('/',(int)l-2);
if (i==-1) // no unique prefix -> stop
{
path="";
done=TRUE;
}
else // restart with shorter path
{
path=path.left(i+1);
}
break;
}
count++;
}
if (count==Doxygen::dirLinkedMap->size())
// path matches for all directories -> found the common prefix
{
done=TRUE;
}
}
}
}
for (const auto &dir : *Doxygen::dirLinkedMap)
{
QCString diskName = dir->name().right(dir->name().length()-path.length());
dir->setDiskName(diskName);
//printf("set disk name: %s -> %s\n",dir->name().data(),diskName.data());
}
}
void buildDirectories()
{
// for each input file
for (const auto &fn : *Doxygen::inputNameLinkedMap)
{
for (const auto &fd : *fn)
{
//printf("buildDirectories %s\n",fd->name().data());
if (fd->getReference().isEmpty())
{
DirDef *dir;
if ((dir=Doxygen::dirLinkedMap->find(fd->getPath()))==0) // new directory
{
dir = DirDefImpl::mergeDirectoryInTree(fd->getPath());
}
if (dir && !fd->isDocumentationFile()) dir->addFile(fd.get());
}
else
{
// do something for file imported via tag files.
}
}
}
// compute relations between directories => introduce container dirs.
for (const auto &dir : *Doxygen::dirLinkedMap)
{
QCString name = dir->name();
int i=name.findRev('/',(int)name.length()-2);
if (i>0)
{
DirDef *parent = Doxygen::dirLinkedMap->find(name.left(i+1));
//if (parent==0) parent=root;
if (parent)
{
parent->addSubDir(dir.get());
//printf("DirDefImpl::addSubdir(): Adding subdir\n%s to\n%s\n",
// dir->displayName().data(), parent->displayName().data());
}
}
}
// sort the directory contents
for (const auto &dir : *Doxygen::dirLinkedMap)
{
dir->sort();
}
// short the directories themselves
std::sort(Doxygen::dirLinkedMap->begin(),
Doxygen::dirLinkedMap->end(),
[](const auto &d1,const auto &d2)
{ return qstricmp(d1->shortName(),d2->shortName()) < 0; });
computeCommonDirPrefix();
}
void computeDirDependencies()
{
// compute nesting level for each directory
for (const auto &dir : *Doxygen::dirLinkedMap)
{
dir->setLevel();
}
// compute uses dependencies between directories
for (const auto &dir : *Doxygen::dirLinkedMap)
{
//printf("computeDependencies for %s: #dirs=%d\n",dir->name().data(),Doxygen::directories.count());
dir->computeDependencies();
}
}
void generateDirDocs(OutputList &ol)
{
for (const auto &dir : *Doxygen::dirLinkedMap)
{
ol.pushGeneratorState();
if (!dir->hasDocumentation())
{
ol.disableAllBut(OutputGenerator::Html);
}
dir->writeDocumentation(ol);
ol.popGeneratorState();
}
if (Config_getBool(DIRECTORY_GRAPH))
{
for (const auto &dr : Doxygen::dirRelations)
{
dr->writeDocumentation(ol);
}
}
}
bool compareDirDefs(const DirDef *item1, const DirDef *item2)
{
return qstricmp(item1->shortName(),item2->shortName()) < 0;
}
// --- Cast functions
DirDef *toDirDef(Definition *d)
{
if (d==0) return 0;
if (d && typeid(*d)==typeid(DirDefImpl))
{
return static_cast<DirDef*>(d);
}
else
{
return 0;
}
}
const DirDef *toDirDef(const Definition *d)
{
if (d==0) return 0;
if (d && typeid(*d)==typeid(DirDefImpl))
{
return static_cast<const DirDef*>(d);
}
else
{
return 0;
}
}
|