mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: #codeStream: preserve across preprocessing
- new token: token::VERBATIMSTRING - writing of this type in primitiveEntry - disabling of all functionEntries in entry
This commit is contained in:
@ -60,6 +60,8 @@ Usage
|
||||
\param -literalRE \n
|
||||
Do not interpret regular expressions; treat them as any other keyword.
|
||||
|
||||
\param -enableFunctionEntries \n
|
||||
By default all dictionary preprocessing of fields is disabled
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -255,6 +257,11 @@ int main(int argc, char *argv[])
|
||||
"literalRE",
|
||||
"treat regular expressions literally (ie, as a keyword)"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"enableFunctionEntries",
|
||||
"enable expansion of dictionary directives - #include, #codeStream etc"
|
||||
);
|
||||
#include "addRegionOption.H"
|
||||
|
||||
#include "setRootCase.H"
|
||||
@ -271,6 +278,20 @@ int main(int argc, char *argv[])
|
||||
<< " not present." << endl;
|
||||
}
|
||||
|
||||
const bool enableEntries = args.optionFound("enableFunctionEntries");
|
||||
if (enableEntries)
|
||||
{
|
||||
Info<< "Allowing dictionary preprocessing ('#include', '#codeStream')."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int oldFlag = entry::disableFunctionEntries;
|
||||
if (!enableEntries)
|
||||
{
|
||||
// By default disable dictionary expansion for fields
|
||||
entry::disableFunctionEntries = 1;
|
||||
}
|
||||
|
||||
|
||||
fileName regionPrefix = "";
|
||||
if (regionName != fvMesh::defaultRegion)
|
||||
@ -410,6 +431,7 @@ int main(int argc, char *argv[])
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
const_cast<word&>(IOdictionary::typeName) = oldTypeName;
|
||||
// Fake type back to what was in field
|
||||
const_cast<word&>(fieldDict.type()) = fieldDict.headerClassName();
|
||||
@ -429,6 +451,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
entry::disableFunctionEntries = oldFlag;
|
||||
|
||||
Info<< endl;
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
|
||||
@ -34,6 +34,9 @@ Usage
|
||||
\param -test \n
|
||||
Suppress writing the updated files with split cyclics
|
||||
|
||||
\param -enableFunctionEntries \n
|
||||
By default all dictionary preprocessing of fields is disabled
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
@ -391,7 +394,12 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
timeSelector::addOptions();
|
||||
|
||||
argList::addBoolOption("test");
|
||||
argList::addBoolOption("test", "test only; do not change any files");
|
||||
argList::addBoolOption
|
||||
(
|
||||
"enableFunctionEntries",
|
||||
"enable expansion of dictionary directives - #include, #codeStream etc"
|
||||
);
|
||||
# include "addRegionOption.H"
|
||||
|
||||
# include "setRootCase.H"
|
||||
@ -404,6 +412,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Info<< "-test option: no changes made" << nl << endl;
|
||||
}
|
||||
const bool enableEntries = args.optionFound("enableFunctionEntries");
|
||||
|
||||
|
||||
Foam::word regionName = polyMesh::defaultRegion;
|
||||
@ -482,6 +491,13 @@ int main(int argc, char *argv[])
|
||||
IOobjectList objects(runTime, runTime.timeName());
|
||||
|
||||
|
||||
int oldFlag = entry::disableFunctionEntries;
|
||||
if (!enableEntries)
|
||||
{
|
||||
// By default disable dictionary expansion for fields
|
||||
entry::disableFunctionEntries = 1;
|
||||
}
|
||||
|
||||
// volFields
|
||||
// ~~~~~~~~~
|
||||
|
||||
@ -615,6 +631,8 @@ int main(int argc, char *argv[])
|
||||
thisNames,
|
||||
nbrNames
|
||||
);
|
||||
|
||||
entry::disableFunctionEntries = oldFlag;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -136,7 +136,8 @@
|
||||
- =foamFormatConvert=
|
||||
- =changeDictionaryDict=
|
||||
- =foamUpgradeCyclics=
|
||||
- =fieldToCell=
|
||||
These applications will usually switch off all '#' processing.
|
||||
|
||||
|
||||
Note: above field initialisation has the problem that the boundary conditions
|
||||
are not evaluated so e.g. processor boundaries will not hold the opposite cell
|
||||
|
||||
@ -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
|
||||
@ -162,11 +162,16 @@ Foam::Istream& Foam::UIPstream::read(token& t)
|
||||
|
||||
// String
|
||||
case token::STRING :
|
||||
case token::VERBATIMSTRING :
|
||||
{
|
||||
string* pval = new string;
|
||||
if (read(*pval))
|
||||
{
|
||||
t = pval;
|
||||
if (c == token::VERBATIMSTRING)
|
||||
{
|
||||
t.type() = token::VERBATIMSTRING;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -203,7 +203,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
|
||||
return *this;
|
||||
}
|
||||
// Verbatim string
|
||||
// Possible verbatim string or dictionary functionEntry
|
||||
case token::HASH :
|
||||
{
|
||||
char nextC;
|
||||
@ -226,6 +226,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
else
|
||||
{
|
||||
t = sPtr;
|
||||
t.type() = token::VERBATIMSTRING;
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
||||
@ -78,6 +78,7 @@ public:
|
||||
PUNCTUATION,
|
||||
WORD,
|
||||
STRING,
|
||||
VERBATIMSTRING,
|
||||
LABEL,
|
||||
FLOAT_SCALAR,
|
||||
DOUBLE_SCALAR,
|
||||
@ -318,6 +319,7 @@ public:
|
||||
// Access
|
||||
|
||||
inline tokenType type() const;
|
||||
inline tokenType& type();
|
||||
|
||||
inline bool good() const;
|
||||
inline bool undefined() const;
|
||||
|
||||
@ -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,7 +39,7 @@ inline void token::clear()
|
||||
{
|
||||
delete wordTokenPtr_;
|
||||
}
|
||||
else if (type_ == STRING)
|
||||
else if (type_ == STRING || type_ == VERBATIMSTRING)
|
||||
{
|
||||
delete stringTokenPtr_;
|
||||
}
|
||||
@ -88,6 +88,7 @@ inline token::token(const token& t)
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
stringTokenPtr_ = new string(*t.stringTokenPtr_);
|
||||
break;
|
||||
|
||||
@ -178,6 +179,11 @@ inline token::tokenType token::type() const
|
||||
return type_;
|
||||
}
|
||||
|
||||
inline token::tokenType& token::type()
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
inline bool token::good() const
|
||||
{
|
||||
return (type_ != ERROR && type_ != UNDEFINED);
|
||||
@ -231,12 +237,12 @@ inline const word& token::wordToken() const
|
||||
|
||||
inline bool token::isString() const
|
||||
{
|
||||
return (type_ == STRING);
|
||||
return (type_ == STRING || type_ == VERBATIMSTRING);
|
||||
}
|
||||
|
||||
inline const string& token::stringToken() const
|
||||
{
|
||||
if (type_ == STRING)
|
||||
if (type_ == STRING || type_ == VERBATIMSTRING)
|
||||
{
|
||||
return *stringTokenPtr_;
|
||||
}
|
||||
@ -405,6 +411,7 @@ inline void token::operator=(const token& t)
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
stringTokenPtr_ = new string(*t.stringTokenPtr_);
|
||||
break;
|
||||
|
||||
@ -511,6 +518,7 @@ inline bool token::operator==(const token& t) const
|
||||
return *wordTokenPtr_ == *t.wordTokenPtr_;
|
||||
|
||||
case STRING:
|
||||
case VERBATIMSTRING:
|
||||
return *stringTokenPtr_ == *t.stringTokenPtr_;
|
||||
|
||||
case LABEL:
|
||||
@ -544,7 +552,7 @@ inline bool token::operator==(const word& w) const
|
||||
|
||||
inline bool token::operator==(const string& s) const
|
||||
{
|
||||
return (type_ == STRING && stringToken() == s);
|
||||
return ((type_ == STRING || type_ == VERBATIMSTRING) && stringToken() == s);
|
||||
}
|
||||
|
||||
inline bool token::operator==(const label l) const
|
||||
|
||||
@ -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
|
||||
@ -70,6 +70,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
|
||||
break;
|
||||
|
||||
case token::STRING:
|
||||
case token::VERBATIMSTRING:
|
||||
os << *t.stringTokenPtr_;
|
||||
break;
|
||||
|
||||
@ -156,6 +157,10 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
|
||||
os << " the string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::LABEL:
|
||||
os << " the label " << t.labelToken();
|
||||
break;
|
||||
@ -226,6 +231,10 @@ Ostream& operator<<(Ostream& os, const InfoProxy<token>& ip)
|
||||
os << " the string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::VERBATIMSTRING:
|
||||
os << " the verbatim string " << t.stringToken();
|
||||
break;
|
||||
|
||||
case token::LABEL:
|
||||
os << " the label " << t.labelToken();
|
||||
break;
|
||||
|
||||
@ -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
|
||||
@ -27,6 +27,14 @@ License
|
||||
#include "dictionary.H"
|
||||
#include "OStringStream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
int Foam::entry::disableFunctionEntries
|
||||
(
|
||||
Foam::debug::infoSwitch("disableFunctionEntries", 0)
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::entry::entry(const keyType& keyword)
|
||||
|
||||
@ -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
|
||||
@ -81,6 +81,9 @@ class entry
|
||||
|
||||
public:
|
||||
|
||||
static int disableFunctionEntries;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from keyword
|
||||
|
||||
@ -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
|
||||
@ -98,21 +98,32 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
|
||||
}
|
||||
else // Keyword starts entry ...
|
||||
{
|
||||
if (keyword[0] == '#') // ... Function entry
|
||||
if
|
||||
(
|
||||
!disableFunctionEntries
|
||||
&& keyword[0] == '#'
|
||||
) // ... Function entry
|
||||
{
|
||||
word functionName = keyword(1, keyword.size()-1);
|
||||
return functionEntry::execute(functionName, parentDict, is);
|
||||
}
|
||||
else if (keyword[0] == '$') // ... Substitution entry
|
||||
else if
|
||||
(
|
||||
!disableFunctionEntries
|
||||
&& keyword[0] == '$') // ... Substitution entry
|
||||
{
|
||||
parentDict.substituteKeyword(keyword);
|
||||
return true;
|
||||
}
|
||||
else if (keyword == "include") // ... For backward compatibility
|
||||
else if
|
||||
(
|
||||
!disableFunctionEntries
|
||||
&& keyword == "include"
|
||||
) // ... For backward compatibility
|
||||
{
|
||||
return functionEntries::includeEntry::execute(parentDict, is);
|
||||
}
|
||||
else // ... Data entries
|
||||
else // ... Data entries
|
||||
{
|
||||
token nextToken(is);
|
||||
is.putBack(nextToken);
|
||||
|
||||
@ -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
|
||||
@ -44,7 +44,8 @@ void Foam::primitiveEntry::append
|
||||
|
||||
if
|
||||
(
|
||||
w.size() == 1
|
||||
disableFunctionEntries
|
||||
|| w.size() == 1
|
||||
|| (
|
||||
!(w[0] == '$' && expandVariable(w, dict))
|
||||
&& !(w[0] == '#' && expandFunction(w, dict, is))
|
||||
@ -215,7 +216,17 @@ void Foam::primitiveEntry::write(Ostream& os) const
|
||||
|
||||
for (label i=0; i<size(); ++i)
|
||||
{
|
||||
os << operator[](i);
|
||||
const token& t = operator[](i);
|
||||
if (t.type() == token::VERBATIMSTRING)
|
||||
{
|
||||
os << token::HASH << token::BEGIN_BLOCK;
|
||||
os.writeQuoted(t.stringToken(), false);
|
||||
os << token::HASH << token::END_BLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << t;
|
||||
}
|
||||
|
||||
if (i < size()-1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user