ENH: add 'report' to trace #includeEntry/#includeIfPresentEntry
- used in "expandDictionary -list" to find which files are included by any particular dictionary
This commit is contained in:
parent
e1137fe8e2
commit
c20efb0923
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -28,12 +28,33 @@ Description
|
||||
Read the dictionary provided as an argument, expand the macros etc. and
|
||||
write the resulting dictionary to standard output.
|
||||
|
||||
Usage
|
||||
- expandDictionary inputDict [OPTION]
|
||||
|
||||
\param -list \n
|
||||
Report the #include/#includeIfPresent to stdout only.
|
||||
|
||||
Note
|
||||
The \c -list option can be useful when determining which files
|
||||
are actually included by a directory. It can also be used to
|
||||
determine which files may need to be copied when transferring
|
||||
simulation to another environment. The following code snippet
|
||||
could be a useful basis for such cases:
|
||||
|
||||
\verbatim
|
||||
for i in . 0 constant system
|
||||
do
|
||||
find $i -maxdepth 1 -type f -exec expandDictionary -list '{}' \;
|
||||
done | sed -ne '/^"\//!{ s/^"//; s/"$//; p }' | sort | uniq
|
||||
\endverbatim
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOobject.H"
|
||||
#include "dictionary.H"
|
||||
#include "includeEntry.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -48,6 +69,12 @@ int main(int argc, char *argv[])
|
||||
"the resulting dictionary to standard output."
|
||||
);
|
||||
|
||||
argList::addBoolOption
|
||||
(
|
||||
"list",
|
||||
"Report the #include/#includeIfPresent to stdout only"
|
||||
);
|
||||
|
||||
argList::noBanner();
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputDict");
|
||||
@ -55,12 +82,22 @@ int main(int argc, char *argv[])
|
||||
|
||||
const string dictName = args[1];
|
||||
|
||||
IOobject::writeBanner(Info)
|
||||
<<"//\n// " << dictName << "\n//\n";
|
||||
const bool listOpt = args.optionFound("list");
|
||||
|
||||
dictionary(IFstream(dictName)(), true).write(Info, false);
|
||||
if (listOpt)
|
||||
{
|
||||
Foam::functionEntries::includeEntry::report = true;
|
||||
}
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
dictionary dict(IFstream(dictName)(), true);
|
||||
|
||||
if (!listOpt)
|
||||
{
|
||||
IOobject::writeBanner(Info)
|
||||
<<"//\n// " << dictName << "\n//\n";
|
||||
dict.write(Info, false);
|
||||
IOobject::writeDivider(Info);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -39,6 +39,9 @@ const Foam::word Foam::functionEntries::includeEntry::typeName
|
||||
// might include includeEntry
|
||||
int Foam::functionEntries::includeEntry::debug(0);
|
||||
|
||||
bool Foam::functionEntries::includeEntry::report(false);
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionEntries
|
||||
@ -89,10 +92,15 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
const fileName fName(includeFileName(is));
|
||||
IFstream ifs(fName);
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::report)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
}
|
||||
parentDict.read(ifs);
|
||||
return true;
|
||||
}
|
||||
@ -119,10 +127,15 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
const fileName fName(includeFileName(is));
|
||||
IFstream ifs(fName);
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::report)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
}
|
||||
entry.read(parentDict, ifs);
|
||||
return true;
|
||||
}
|
||||
|
@ -82,6 +82,12 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
|
||||
//- Report which file is included to stdout
|
||||
static bool report;
|
||||
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("include");
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -69,10 +69,15 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
const fileName fName(includeFileName(is));
|
||||
IFstream ifs(fName);
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::report)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
}
|
||||
parentDict.read(ifs);
|
||||
}
|
||||
|
||||
@ -87,10 +92,15 @@ bool Foam::functionEntries::includeIfPresentEntry::execute
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
IFstream ifs(includeFileName(is));
|
||||
const fileName fName(includeFileName(is));
|
||||
IFstream ifs(fName);
|
||||
|
||||
if (ifs)
|
||||
{
|
||||
if (Foam::functionEntries::includeEntry::report)
|
||||
{
|
||||
Info<< fName << endl;
|
||||
}
|
||||
entry.read(parentDict, ifs);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user