diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index 083107efb941126c93d447101baf8c057d60804a..c5df6ef79f2a88db3605186cbfc879c8fc5f6ae1 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -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; diff --git a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C index dd44b492809ce6d09a3cef1e004d24a17d030ee0..f1a7ab5301a2ed90260a227fc12891eebbd69f63 100644 --- a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C +++ b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C @@ -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; diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org index 57bd7f46cdffc96edf29b81966eed6ef290e96fa..3297d26573d7464221179e6ab898633f36343b08 100644 --- a/doc/changes/codeStream.org +++ b/doc/changes/codeStream.org @@ -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 diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C index f0026c2ff09e230b21c229b7eb2152f728e123c9..50728c425ccba43a2f960d4b8d00d102089dcbb7 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C @@ -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 { diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C index 135f61823afe9c3e8f6ba2f54840a6242f160f0b..90e2a46c829155bf39056901cff9544fefd2b6bc 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C @@ -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; diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H index 7c91758c1a528011db70e6564b6876935c93f380..c48c22b5c3e067ce2d3e6b3bd5affe04e24279fd 100644 --- a/src/OpenFOAM/db/IOstreams/token/token.H +++ b/src/OpenFOAM/db/IOstreams/token/token.H @@ -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; diff --git a/src/OpenFOAM/db/IOstreams/token/tokenI.H b/src/OpenFOAM/db/IOstreams/token/tokenI.H index 6c3434deadd3a8eaa779a4975cabb6dab2564ba2..11124e9e2aea899bae69eb4459703e52d51890f4 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenI.H +++ b/src/OpenFOAM/db/IOstreams/token/tokenI.H @@ -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 diff --git a/src/OpenFOAM/db/IOstreams/token/tokenIO.C b/src/OpenFOAM/db/IOstreams/token/tokenIO.C index bf7cdd081d0451fddca9149665e0ec7244f85aef..23c17e75e582899d711315820d294246dc5783a9 100644 --- a/src/OpenFOAM/db/IOstreams/token/tokenIO.C +++ b/src/OpenFOAM/db/IOstreams/token/tokenIO.C @@ -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; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index de62c861a48a164b3a88fabb66e21eade3b6a93b..3bba611deeb574cde58d921f6d4fc02b7012f8d7 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -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) diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index 21f56347282f4ebcd05ddc8afd7b7b1f0e144250..93b5a143a213b8fcba54632d54db9682cf35a304 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.H @@ -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 diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index c61a97e7c58f71f2a02e7268ac078c72c3a46921..1f3172f0e50af5a4ce13043bd8cd61822e66d087 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.C @@ -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); diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index a7fcb0c64dab12157c7538694ca8fdb5f9b1e9a5..fa9a50efdb15b6dc603d17abfdb4295f5e6a51ac 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -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) {