Skip to content

Commit 3204a22

Browse files
committed
Refactoring: Replaced QFileInfo with FileInfo
- FileInfo is based on ghc::filesystem, a std::filesystem compatible implementation that does not require C++17.
1 parent 781c3ec commit 3204a22

38 files changed

+6326
-282
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ add_library(doxymain STATIC
256256
emoji.cpp
257257
entry.cpp
258258
filedef.cpp
259+
fileinfo.cpp
259260
fileparser.cpp
260261
formula.cpp
261262
ftvhelp.cpp

src/cite.cpp

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#include "resourcemgr.h"
2424
#include "util.h"
2525
#include "debug.h"
26+
#include "fileinfo.h"
2627

2728
#include <qfile.h>
28-
#include <qfileinfo.h>
2929
#include <qdir.h>
3030

3131
#include <map>
@@ -112,7 +112,7 @@ void CitationManager::insertCrossReferencesForBibFile(const QCString &bibFile)
112112
{
113113
return;
114114
}
115-
QFileInfo fi(bibFile);
115+
FileInfo fi(bibFile.str());
116116
if (!fi.exists())
117117
{
118118
err("bib file %s not found!\n",bibFile.data());
@@ -287,7 +287,7 @@ void CitationManager::generatePage()
287287
{
288288
QCString bibFile = bibdata.c_str();
289289
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
290-
QFileInfo fi(bibFile);
290+
FileInfo fi(bibFile.str());
291291
if (fi.exists())
292292
{
293293
if (!bibFile.isEmpty())
@@ -317,55 +317,57 @@ void CitationManager::generatePage()
317317
QDir::setCurrent(oldDir);
318318

319319
// 6. read back the file
320-
f.setName(citeListFile);
321-
if (!f.open(IO_ReadOnly))
322-
{
323-
err("could not open file %s for reading\n",citeListFile.data());
324-
}
325-
326320
QCString doc;
327-
QFileInfo fi(citeListFile);
328-
QCString input(fi.size()+1);
329-
f.readBlock(input.rawData(),fi.size());
330-
f.close();
331-
input.at(fi.size())='\0';
332-
333-
bool insideBib=FALSE;
334-
int pos=0,s;
335-
//printf("input=[%s]\n",input.data());
336-
while ((s=input.find('\n',pos))!=-1)
337321
{
338-
QCString line = input.mid((uint)pos,(uint)(s-pos));
339-
//printf("pos=%d s=%d line=[%s]\n",pos,s,line.data());
340-
pos=s+1;
322+
f.setName(citeListFile);
323+
if (!f.open(IO_ReadOnly))
324+
{
325+
err("could not open file %s for reading\n",citeListFile.data());
326+
}
327+
328+
FileInfo fi(citeListFile.str());
329+
QCString input(fi.size()+1);
330+
f.readBlock(input.rawData(),fi.size());
331+
f.close();
332+
input.at(fi.size())='\0';
341333

342-
if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE;
343-
else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE;
344-
// determine text to use at the location of the @cite command
345-
if (insideBib && (i=line.find("name=\"CITEREF_"))!=-1)
334+
bool insideBib=FALSE;
335+
int pos=0,s;
336+
//printf("input=[%s]\n",input.data());
337+
while ((s=input.find('\n',pos))!=-1)
346338
{
347-
int j=line.find("\">[");
348-
int k=line.find("]</a>");
349-
if (j!=-1 && k!=-1)
339+
QCString line = input.mid((uint)pos,(uint)(s-pos));
340+
//printf("pos=%d s=%d line=[%s]\n",pos,s,line.data());
341+
pos=s+1;
342+
343+
if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE;
344+
else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE;
345+
// determine text to use at the location of the @cite command
346+
if (insideBib && (i=line.find("name=\"CITEREF_"))!=-1)
350347
{
351-
uint ui=(uint)i;
352-
uint uj=(uint)j;
353-
uint uk=(uint)k;
354-
QCString label = line.mid(ui+14,uj-ui-14);
355-
QCString number = line.mid(uj+2,uk-uj-1);
356-
label = substitute(substitute(label,"&ndash;","--"),"&mdash;","---");
357-
line = line.left(ui+14) + label + line.right(line.length()-uj);
358-
auto it = p->entries.find(label.data());
359-
//printf("label='%s' number='%s' => %p\n",label.data(),number.data(),it->second.get());
360-
if (it!=p->entries.end())
348+
int j=line.find("\">[");
349+
int k=line.find("]</a>");
350+
if (j!=-1 && k!=-1)
361351
{
362-
it->second->setText(number);
352+
uint ui=(uint)i;
353+
uint uj=(uint)j;
354+
uint uk=(uint)k;
355+
QCString label = line.mid(ui+14,uj-ui-14);
356+
QCString number = line.mid(uj+2,uk-uj-1);
357+
label = substitute(substitute(label,"&ndash;","--"),"&mdash;","---");
358+
line = line.left(ui+14) + label + line.right(line.length()-uj);
359+
auto it = p->entries.find(label.data());
360+
//printf("label='%s' number='%s' => %p\n",label.data(),number.data(),it->second.get());
361+
if (it!=p->entries.end())
362+
{
363+
it->second->setText(number);
364+
}
363365
}
364366
}
367+
if (insideBib) doc+=line+"\n";
365368
}
366-
if (insideBib) doc+=line+"\n";
369+
//printf("doc=[%s]\n",doc.data());
367370
}
368-
//printf("doc=[%s]\n",doc.data());
369371

370372
// 7. add it as a page
371373
addRelatedPage(fileName(),theTranslator->trCiteReferences(),doc,fileName(),1,1);
@@ -382,7 +384,7 @@ void CitationManager::generatePage()
382384
QCString bibFile = bibdata.c_str();
383385
// Note: file can now have multiple dots
384386
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
385-
fi.setFile(bibFile);
387+
FileInfo fi(bibFile.str());
386388
if (fi.exists())
387389
{
388390
if (!bibFile.isEmpty())
@@ -427,7 +429,7 @@ QCString CitationManager::latexBibFiles()
427429
QCString bibFile = bibdata.c_str();
428430
// Note: file can now have multiple dots
429431
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
430-
QFileInfo fi(bibFile);
432+
FileInfo fi(bibFile.str());
431433
if (fi.exists())
432434
{
433435
if (!bibFile.isEmpty())

src/classdef.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <algorithm>
2020

2121
#include <qfile.h>
22-
#include <qfileinfo.h>
2322
#include "classdef.h"
2423
#include "classlist.h"
2524
#include "entry.h"
@@ -50,6 +49,7 @@
5049
#include "membergroup.h"
5150
#include "definitionimpl.h"
5251
#include "symbolresolver.h"
52+
#include "fileinfo.h"
5353

5454
//-----------------------------------------------------------------------------
5555

@@ -1738,10 +1738,10 @@ void ClassDefImpl::writeIncludeFilesForSlice(OutputList &ol) const
17381738
unsigned int length = 0;
17391739
for (const auto &s : paths)
17401740
{
1741-
QFileInfo info(s.c_str());
1741+
FileInfo info(s);
17421742
if (info.exists())
17431743
{
1744-
QCString prefix = info.absFilePath().utf8();
1744+
QCString prefix = info.absFilePath();
17451745
if (prefix.at(prefix.length() - 1) != '/')
17461746
{
17471747
prefix += '/';

src/configimpl.l

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <stdarg.h>
2828
#include <errno.h>
2929

30-
#include <qfileinfo.h>
3130
#include <qdir.h>
3231

3332
#include <thread>
@@ -41,6 +40,7 @@
4140

4241
#include "lang_cfg.h"
4342
#include "configoptions.h"
43+
#include "fileinfo.h"
4444

4545
#define YY_NO_INPUT 1
4646
#define YY_NO_UNISTD_H 1
@@ -766,7 +766,7 @@ static void processList()
766766
static FILE *tryPath(const char *path,const char *fileName)
767767
{
768768
QCString absName=(path ? (QCString)path+"/"+fileName : (QCString)fileName);
769-
QFileInfo fi(absName);
769+
FileInfo fi(absName.str());
770770
if (fi.exists() && fi.isFile())
771771
{
772772
FILE *f=Portable::fopen(absName,"r");
@@ -1327,7 +1327,7 @@ static QCString configFileToString(const char *name)
13271327
}
13281328
else // read from file
13291329
{
1330-
QFileInfo fi(name);
1330+
FileInfo fi(name);
13311331
if (!fi.exists() || !fi.isFile())
13321332
{
13331333
config_err("file '%s' not found\n",name);
@@ -1393,10 +1393,10 @@ static void cleanUpPaths(StringVector &str)
13931393
std::replace(path.begin(),path.end(),'\\','/');
13941394
if ((path[0]!='/' && (path.size()<=2 || path[1]!=':')) || path[path.size()-1]!='/')
13951395
{
1396-
QFileInfo fi(path.c_str());
1396+
FileInfo fi(path);
13971397
if (fi.exists() && fi.isDir())
13981398
{
1399-
path = fi.absFilePath().utf8().str();
1399+
path = fi.absFilePath();
14001400
if (path[path.size()-1]!='/') path+='/';
14011401
}
14021402
}
@@ -1551,7 +1551,7 @@ void Config::checkAndCorrect()
15511551
QCString headerFile = Config_getString(HTML_HEADER);
15521552
if (!headerFile.isEmpty())
15531553
{
1554-
QFileInfo fi(headerFile);
1554+
FileInfo fi(headerFile.str());
15551555
if (!fi.exists())
15561556
{
15571557
config_term("tag HTML_HEADER: header file '%s' "
@@ -1564,7 +1564,7 @@ void Config::checkAndCorrect()
15641564
QCString footerFile = Config_getString(HTML_FOOTER);
15651565
if (!footerFile.isEmpty())
15661566
{
1567-
QFileInfo fi(footerFile);
1567+
FileInfo fi(footerFile.str());
15681568
if (!fi.exists())
15691569
{
15701570
config_term("tag HTML_FOOTER: footer file '%s' "
@@ -1579,7 +1579,7 @@ void Config::checkAndCorrect()
15791579
QCString mathJaxCodefile = Config_getString(MATHJAX_CODEFILE);
15801580
if (!mathJaxCodefile.isEmpty())
15811581
{
1582-
QFileInfo fi(mathJaxCodefile);
1582+
FileInfo fi(mathJaxCodefile.str());
15831583
if (!fi.exists())
15841584
{
15851585
config_term("tag MATHJAX_CODEFILE file '%s' "
@@ -1599,7 +1599,7 @@ void Config::checkAndCorrect()
15991599
QCString latexHeaderFile = Config_getString(LATEX_HEADER);
16001600
if (!latexHeaderFile.isEmpty())
16011601
{
1602-
QFileInfo fi(latexHeaderFile);
1602+
FileInfo fi(latexHeaderFile.str());
16031603
if (!fi.exists())
16041604
{
16051605
config_term("tag LATEX_HEADER: header file '%s' "
@@ -1612,7 +1612,7 @@ void Config::checkAndCorrect()
16121612
QCString latexFooterFile = Config_getString(LATEX_FOOTER);
16131613
if (!latexFooterFile.isEmpty())
16141614
{
1615-
QFileInfo fi(latexFooterFile);
1615+
FileInfo fi(latexFooterFile.str());
16161616
if (!fi.exists())
16171617
{
16181618
config_term("tag LATEX_FOOTER: footer file '%s' "
@@ -1625,7 +1625,7 @@ void Config::checkAndCorrect()
16251625
const StringVector &includePath = Config_getList(INCLUDE_PATH);
16261626
for (const auto &s : includePath)
16271627
{
1628-
QFileInfo fi(s.c_str());
1628+
FileInfo fi(s);
16291629
if (!fi.exists()) warn_uncond("tag INCLUDE_PATH: include path '%s' "
16301630
"does not exist\n",s.c_str());
16311631
}
@@ -1774,22 +1774,23 @@ void Config::checkAndCorrect()
17741774
QCString dotPath = Config_getString(DOT_PATH);
17751775
if (!dotPath.isEmpty())
17761776
{
1777-
QFileInfo fi(dotPath);
1777+
FileInfo fi(dotPath.str());
17781778
if (fi.exists() && fi.isFile()) // user specified path + exec
17791779
{
1780-
dotPath=fi.dirPath(TRUE).utf8()+"/";
1780+
dotPath=fi.dirPath(TRUE)+"/";
17811781
}
17821782
else
17831783
{
1784-
QFileInfo dp(dotPath+"/dot"+Portable::commandExtension());
1784+
QCString dotExe = dotPath+"/dot"+Portable::commandExtension();
1785+
FileInfo dp(dotExe.str());
17851786
if (!dp.exists() || !dp.isFile())
17861787
{
17871788
warn_uncond("the dot tool could not be found at %s\n",dotPath.data());
17881789
dotPath="";
17891790
}
17901791
else
17911792
{
1792-
dotPath=dp.dirPath(TRUE).utf8()+"/";
1793+
dotPath=dp.dirPath(TRUE)+"/";
17931794
}
17941795
}
17951796
#if defined(_WIN32) // convert slashes
@@ -1808,13 +1809,14 @@ void Config::checkAndCorrect()
18081809
QCString plantumlJarPath = Config_getString(PLANTUML_JAR_PATH);
18091810
if (!plantumlJarPath.isEmpty())
18101811
{
1811-
QFileInfo pu(plantumlJarPath);
1812+
FileInfo pu(plantumlJarPath.str());
18121813
if (pu.exists() && pu.isDir()) // PLANTUML_JAR_PATH is directory
18131814
{
1814-
QFileInfo jar(plantumlJarPath+Portable::pathSeparator()+"plantuml.jar");
1815+
QCString plantumlJar = plantumlJarPath+Portable::pathSeparator()+"plantuml.jar";
1816+
FileInfo jar(plantumlJar.str());
18151817
if (jar.exists() && jar.isFile())
18161818
{
1817-
plantumlJarPath = jar.dirPath(TRUE).utf8()+Portable::pathSeparator();
1819+
plantumlJarPath = jar.dirPath(TRUE)+Portable::pathSeparator();
18181820
}
18191821
else
18201822
{
@@ -1825,7 +1827,7 @@ void Config::checkAndCorrect()
18251827
}
18261828
else if (pu.exists() && pu.isFile() && plantumlJarPath.right(4)==".jar") // PLANTUML_JAR_PATH is file
18271829
{
1828-
plantumlJarPath = pu.dirPath(TRUE).utf8()+Portable::pathSeparator();
1830+
plantumlJarPath = pu.dirPath(TRUE)+Portable::pathSeparator();
18291831
}
18301832
else
18311833
{
@@ -1841,15 +1843,16 @@ void Config::checkAndCorrect()
18411843
QCString diaPath = Config_getString(DIA_PATH);
18421844
if (!diaPath.isEmpty())
18431845
{
1844-
QFileInfo dp(diaPath+"/dia"+Portable::commandExtension());
1846+
QCString diaExe = diaPath+"/dia"+Portable::commandExtension();
1847+
FileInfo dp(diaExe.str());
18451848
if (!dp.exists() || !dp.isFile())
18461849
{
18471850
warn_uncond("dia could not be found at %s\n",diaPath.data());
18481851
diaPath="";
18491852
}
18501853
else
18511854
{
1852-
diaPath=dp.dirPath(TRUE).utf8()+"/";
1855+
diaPath=dp.dirPath(TRUE)+"/";
18531856
#if defined(_WIN32) // convert slashes
18541857
uint i=0,l=diaPath.length();
18551858
for (i=0;i<l;i++) if (diaPath.at(i)=='/') diaPath.at(i)='\\';
@@ -1874,7 +1877,7 @@ void Config::checkAndCorrect()
18741877
{
18751878
for (const auto &s : inputSources)
18761879
{
1877-
QFileInfo fi(s.c_str());
1880+
FileInfo fi(s.c_str());
18781881
if (!fi.exists())
18791882
{
18801883
warn_uncond("tag INPUT: input source '%s' does not exist\n",s.c_str());

0 commit comments

Comments
 (0)