diff --git a/applications/test/codeStream/codeStreamDict1 b/applications/test/codeStream/codeStreamDict1
index 54fb3d0efe..ec94ddb173 100644
--- a/applications/test/codeStream/codeStreamDict1
+++ b/applications/test/codeStream/codeStreamDict1
@@ -14,10 +14,15 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-// #include "codeStreamDefaults"
+// values from outer-scope
+begIter 0;
+endIter 200;
writeInterval #codeStream
{
+ // values from inner-scope
+ nDumps 5;
+
codeInclude
#{
#include "fvCFD.H"
@@ -30,14 +35,15 @@ writeInterval #codeStream
code
#{
- scalar start = 0;
- scalar end = 100;
- label nDumps = 5;
- label interval = end - start;
- Info<<"on-the-fly: " << ((interval)/nDumps) << endl;
- os << ((interval)/nDumps);
+ label interval = ($endIter - $begIter);
+ label nDumps = $nDumps;
+ os << (interval / nDumps);
#};
};
+// play with cleanup
+#remove begIter
+
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictCalc b/applications/test/dictionary/testDictCalc
deleted file mode 100644
index d57031f8d6..0000000000
--- a/applications/test/dictionary/testDictCalc
+++ /dev/null
@@ -1,31 +0,0 @@
-/*--------------------------------*- C++ -*----------------------------------*\
-| ========= | |
-| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
-| \\ / O peration | Version: Any |
-| \\ / A nd | Web: www.OpenFOAM.com |
-| \\/ M anipulation | |
-\*---------------------------------------------------------------------------*/
-FoamFile
-{
- version 2.0;
- format ascii;
- class dictionary;
- object testDictCalc;
-}
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-flowRatePerHour 720;
-
-x 10;
-y 20;
-z t s v;
-p #calc{ 1 + 2 + 10 * 15 + $x - $y };
-
-// this calculation is in-place, but does not work inside a string:
-flowRate "The flow rate " #calc{ $flowRatePerHour / 3600 } "kg/s";
-
-// this is also okay
-x #calc{ $x * 1E-3 };
-
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictCalcError b/applications/test/dictionary/testDictCalcError
deleted file mode 100644
index 911df9feb8..0000000000
--- a/applications/test/dictionary/testDictCalcError
+++ /dev/null
@@ -1,46 +0,0 @@
-/*--------------------------------*- C++ -*----------------------------------*\
-| ========= | |
-| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
-| \\ / O peration | Version: Any |
-| \\ / A nd | Web: www.OpenFOAM.com |
-| \\/ M anipulation | |
-\*---------------------------------------------------------------------------*/
-FoamFile
-{
- version 2.0;
- format ascii;
- class dictionary;
- object testDictCalcError;
-}
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-flowRatePerHour 720;
-
-x 10;
-y 20;
-z t s v;
-// z #test{ // this
-// 123 - 456
-// // comments // are
-// /* stripped
-// * 10
-// * {}
-// */
-// + 1 /*100 */ 10
-// };
-
-p this calculation #calc{
- 1xxx1 + 2 + 10 * 15 +
- $x - $y
- // $x + $y
-}
-is done inplace;
-
-
-flowRate #calc{ $flowRatePerHour / 3600};
-
-xxx yyy;
-foo 30;
-bar 15;
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C
index d117f50c41..e9639c4736 100644
--- a/applications/test/string/Test-string.C
+++ b/applications/test/string/Test-string.C
@@ -22,11 +22,13 @@ License
along with OpenFOAM. If not, see .
Description
+ Test some string functionality
\*---------------------------------------------------------------------------*/
#include "string.H"
#include "stringOps.H"
+#include "dictionary.H"
#include "IOstreams.H"
using namespace Foam;
@@ -38,9 +40,19 @@ int main(int argc, char *argv[])
{
string test
(
- " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ "
+ " $HOME kjhkjhkjh \" \\$HOME/tyetyery ${FOAM_RUN} \n ; hkjh ;$ with "
+ " $(DONOTSUBST) some other ${USER} entries "
);
+ dictionary dict;
+ dict.add("HOME", "myHome");
+
+ dictionary subDict;
+ subDict.add("value1", "test1");
+ subDict.add("value2", "test2");
+ dict.add("FOAM_RUN", subDict);
+
+
Info<< "string:" << test << nl << "hash:"
<< unsigned(string::hash()(test)) << endl;
@@ -73,7 +85,10 @@ int main(int argc, char *argv[])
Info<< string(test).replaceAll("kj", "zzz") << endl;
Info<< string(test).replaceAll("kj", "z") << endl;
- Info<< string(test).expand() << endl;
+ Info<< "expanded: " << string(test).expand() << endl;
+
+ Info<<"dictionary-based substitution: " << dict << endl;
+ Info<< "expandDict: " << stringOps::expandDict(test, dict) << endl;
string test2("~OpenFOAM/controlDict");
Info<< test2 << " => " << test2.expand() << endl;
diff --git a/doc/changes/codeStream.org b/doc/changes/codeStream.org
index bcef4c166b..6e26ba9810 100644
--- a/doc/changes/codeStream.org
+++ b/doc/changes/codeStream.org
@@ -49,13 +49,14 @@
- it copies a template file
=($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C)=, substituting all
occurences of =code=, =codeInclude=, =codeOptions=.
- - it writes library source files to =constant/codeStream/= and compiles
+ - it writes library source files to =codeStream/= and compiles
it using =wmake libso=.
- - the resulting library gets loaded (=dlopen=, =dlsym=) and the function
- executed
+ - the resulting library is generated under
+ =codeStream/platforms/$WM_OPTIONS/lib= and is loaded (=dlopen=, =dlsym=)
+ and the function executed
- the function will have written its output into the Ostream which then gets
used to construct the entry to replace the whole =#codeStream= section.
- - using the sha1 means that same code will only be compiled and loaded once.
+ - using the SHA1 means that same code will only be compiled and loaded once.
* Boundary condition: =codedFixedValue=
This uses the code from codeStream to have an in-line specialised
diff --git a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
index 417b77ee68..76a31e9fb0 100644
--- a/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
+++ b/etc/codeTemplates/codeStream/fixedValueFvPatchScalarFieldTemplate.C
@@ -35,6 +35,20 @@ ${codeInclude}
namespace Foam
{
+// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
+
+extern "C"
+{
+ // unique function name that can be checked if the correct library version
+ // has been loaded
+ bool ${typeName}_${SHA1sum}()
+ {
+ return true;
+ }
+}
+
+
+
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
${typeName}FixedValueFvPatchScalarField::
diff --git a/etc/controlDict b/etc/controlDict
index 403aa02285..4aa8a3ec0a 100644
--- a/etc/controlDict
+++ b/etc/controlDict
@@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
-| \\ / O peration | Version: 1.7 |
+| \\ / O peration | Version: 2.0 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@@ -24,6 +24,7 @@ Documentation
"$WM_PROJECT_USER_DIR/html"
"~OpenFOAM/html"
"$WM_PROJECT_DIR/doc/Doxygen/html"
+ "$WM_PROJECT_DIR/doc/doxygen/html"
);
doxySourceFileExts
(
@@ -32,6 +33,34 @@ Documentation
);
}
+
+InfoSwitches
+{
+ writePrecision 6;
+ writeJobInfo 0;
+
+ // Allow case-supplied c++ code (#codeStream, codedFixedValue)
+ allowSystemOperations 0;
+}
+
+
+OptimisationSwitches
+{
+ fileModificationSkew 10;
+
+ //- Modification checking:
+ // - timeStamp : use modification time on file
+ // - inotify : use inotify framework
+ // - timeStampMaster : do time stamp (and file reading) only on master.
+ // - inotifyMaster : do inotify (and file reading) only on master.
+ fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster;
+
+ commsType nonBlocking; //scheduled; //blocking;
+ floatTransfer 0;
+ nProcsSimpleSum 0;
+}
+
+
DebugSwitches
{
Analytical 0;
@@ -864,30 +893,6 @@ DebugSwitches
zoneToPoint 0;
}
-InfoSwitches
-{
- writePrecision 6;
- writeJobInfo 0;
-
- // Allow case-supplied c++ code (#codeStream, codedFixedValue)
- allowSystemOperations 0;
-}
-
-OptimisationSwitches
-{
- fileModificationSkew 10;
-
- //- Modification checking:
- // - timeStamp : use modification time on file
- // - inotify : use inotify framework
- // - timeStampMaster : do time stamp (and file reading) only on master.
- // - inotifyMaster : do inotify (and file reading) only on master.
- fileModificationChecking timeStampMaster;//inotify;timeStamp;inotifyMaster;
-
- commsType nonBlocking; //scheduled; //blocking;
- floatTransfer 0;
- nProcsSimpleSum 0;
-}
DimensionedConstants
{
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index 03eefb623b..4909d08244 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -63,28 +63,28 @@ defineTypeNameAndDebug(Foam::POSIX, 0);
pid_t Foam::pid()
{
- return getpid();
+ return ::getpid();
}
pid_t Foam::ppid()
{
- return getppid();
+ return ::getppid();
}
pid_t Foam::pgid()
{
- return getpgrp();
+ return ::getpgrp();
}
bool Foam::env(const word& envName)
{
- return getenv(envName.c_str()) != NULL;
+ return ::getenv(envName.c_str()) != NULL;
}
Foam::string Foam::getEnv(const word& envName)
{
- char* env = getenv(envName.c_str());
+ char* env = ::getenv(envName.c_str());
if (env)
{
@@ -113,12 +113,12 @@ bool Foam::setEnv
Foam::word Foam::hostName(bool full)
{
char buf[128];
- gethostname(buf, sizeof(buf));
+ ::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools
if (full)
{
- struct hostent *hp = gethostbyname(buf);
+ struct hostent *hp = ::gethostbyname(buf);
if (hp)
{
return hp->h_name;
@@ -132,13 +132,13 @@ Foam::word Foam::hostName(bool full)
Foam::word Foam::domainName()
{
char buf[128];
- gethostname(buf, sizeof(buf));
+ ::gethostname(buf, sizeof(buf));
// implementation as per hostname from net-tools
- struct hostent *hp = gethostbyname(buf);
+ struct hostent *hp = ::gethostbyname(buf);
if (hp)
{
- char *p = strchr(hp->h_name, '.');
+ char *p = ::strchr(hp->h_name, '.');
if (p)
{
++p;
@@ -152,7 +152,7 @@ Foam::word Foam::domainName()
Foam::word Foam::userName()
{
- struct passwd* pw = getpwuid(getuid());
+ struct passwd* pw = ::getpwuid(::getuid());
if (pw != NULL)
{
@@ -167,14 +167,14 @@ Foam::word Foam::userName()
bool Foam::isAdministrator()
{
- return (geteuid() == 0);
+ return (::geteuid() == 0);
}
// use $HOME environment variable or passwd info
Foam::fileName Foam::home()
{
- char* env = getenv("HOME");
+ char* env = ::getenv("HOME");
if (env != NULL)
{
@@ -182,7 +182,7 @@ Foam::fileName Foam::home()
}
else
{
- struct passwd* pw = getpwuid(getuid());
+ struct passwd* pw = ::getpwuid(getuid());
if (pw != NULL)
{
@@ -202,18 +202,18 @@ Foam::fileName Foam::home(const word& userName)
if (userName.size())
{
- pw = getpwnam(userName.c_str());
+ pw = ::getpwnam(userName.c_str());
}
else
{
- char* env = getenv("HOME");
+ char* env = ::getenv("HOME");
if (env != NULL)
{
return fileName(env);
}
- pw = getpwuid(getuid());
+ pw = ::getpwuid(::getuid());
}
if (pw != NULL)
@@ -230,7 +230,7 @@ Foam::fileName Foam::home(const word& userName)
Foam::fileName Foam::cwd()
{
char buf[256];
- if (getcwd(buf, sizeof(buf)))
+ if (::getcwd(buf, sizeof(buf)))
{
return buf;
}
@@ -247,7 +247,7 @@ Foam::fileName Foam::cwd()
bool Foam::chDir(const fileName& dir)
{
- return chdir(dir.c_str()) == 0;
+ return ::chdir(dir.c_str()) == 0;
}
@@ -311,7 +311,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
// abort if the file is mandatory, otherwise return null
if (mandatory)
{
- cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
+ std::cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
" could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl;
::exit(1);
@@ -591,7 +591,7 @@ Foam::fileNameList Foam::readDir
label nEntries = 0;
// Attempt to open directory and set the structure pointer
- if ((source = opendir(directory.c_str())) == NULL)
+ if ((source = ::opendir(directory.c_str())) == NULL)
{
dirEntries.setSize(0);
@@ -605,7 +605,7 @@ Foam::fileNameList Foam::readDir
else
{
// Read and parse all the entries in the directory
- while ((list = readdir(source)) != NULL)
+ while ((list = ::readdir(source)) != NULL)
{
fileName fName(list->d_name);
@@ -651,7 +651,7 @@ Foam::fileNameList Foam::readDir
// Reset the length of the entries list
dirEntries.setSize(nEntries);
- closedir(source);
+ ::closedir(source);
}
return dirEntries;
@@ -781,7 +781,7 @@ bool Foam::ln(const fileName& src, const fileName& dst)
return false;
}
- if (symlink(src.c_str(), dst.c_str()) == 0)
+ if (::symlink(src.c_str(), dst.c_str()) == 0)
{
return true;
}
@@ -810,11 +810,11 @@ bool Foam::mv(const fileName& src, const fileName& dst)
{
const fileName dstName(dst/src.name());
- return rename(src.c_str(), dstName.c_str()) == 0;
+ return ::rename(src.c_str(), dstName.c_str()) == 0;
}
else
{
- return rename(src.c_str(), dst.c_str()) == 0;
+ return ::rename(src.c_str(), dst.c_str()) == 0;
}
}
@@ -846,7 +846,7 @@ bool Foam::mvBak(const fileName& src, const std::string& ext)
// possible index where we have no choice
if (!exists(dstName, false) || n == maxIndex)
{
- return rename(src.c_str(), dstName.c_str()) == 0;
+ return ::rename(src.c_str(), dstName.c_str()) == 0;
}
}
@@ -873,7 +873,7 @@ bool Foam::rm(const fileName& file)
}
else
{
- return remove(string(file + ".gz").c_str()) == 0;
+ return ::remove(string(file + ".gz").c_str()) == 0;
}
}
@@ -892,7 +892,7 @@ bool Foam::rmDir(const fileName& directory)
struct dirent *list;
// Attempt to open directory and set the structure pointer
- if ((source = opendir(directory.c_str())) == NULL)
+ if ((source = ::opendir(directory.c_str())) == NULL)
{
WarningIn("rmDir(const fileName&)")
<< "cannot open directory " << directory << endl;
@@ -902,7 +902,7 @@ bool Foam::rmDir(const fileName& directory)
else
{
// Read and parse all the entries in the directory
- while ((list = readdir(source)) != NULL)
+ while ((list = ::readdir(source)) != NULL)
{
fileName fName(list->d_name);
@@ -919,7 +919,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory
<< endl;
- closedir(source);
+ ::closedir(source);
return false;
}
@@ -933,7 +933,7 @@ bool Foam::rmDir(const fileName& directory)
<< " while removing directory " << directory
<< endl;
- closedir(source);
+ ::closedir(source);
return false;
}
@@ -947,12 +947,12 @@ bool Foam::rmDir(const fileName& directory)
WarningIn("rmDir(const fileName&)")
<< "failed to remove directory " << directory << endl;
- closedir(source);
+ ::closedir(source);
return false;
}
- closedir(source);
+ ::closedir(source);
return true;
}
@@ -990,7 +990,7 @@ bool Foam::ping
struct sockaddr_in destAddr; // will hold the destination addr
u_int addr;
- if ((hostPtr = gethostbyname(destName.c_str())) == NULL)
+ if ((hostPtr = ::gethostbyname(destName.c_str())) == NULL)
{
FatalErrorIn
(
@@ -1003,7 +1003,7 @@ bool Foam::ping
addr = (reinterpret_cast(*(hostPtr->h_addr_list)))->s_addr;
// Allocate socket
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
FatalErrorIn
@@ -1031,7 +1031,7 @@ bool Foam::ping
if
(
- connect
+ ::connect
(
sockfd,
reinterpret_cast(&destAddr),
@@ -1074,19 +1074,19 @@ int Foam::system(const std::string& command)
void* Foam::dlOpen(const fileName& lib)
{
- return dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
+ return ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
}
bool Foam::dlClose(void* handle)
{
- return dlclose(handle) == 0;
+ return ::dlclose(handle) == 0;
}
void* Foam::dlSym(void* handle, const std::string& symbol)
{
- void* fun = dlsym(handle, symbol.c_str());
+ void* fun = ::dlsym(handle, symbol.c_str());
char *error;
if ((error = dlerror()) != NULL)
diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H
index f1196852bf..cb3b03b00f 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.H
+++ b/src/OpenFOAM/db/dictionary/dictionary.H
@@ -477,7 +477,8 @@ public:
// Write
- void write(Ostream&, bool subDict=true) const;
+ //- Write dictionary, normally with sub-dictionary formatting
+ void write(Ostream&, const bool subDict=true) const;
// Member Operators
diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H
index 050840c5e4..7713e503af 100644
--- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H
+++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.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
@@ -146,7 +146,7 @@ public:
//- Return non-const access to dictionary
dictionary& dict();
- // Write
+ //- Write
void write(Ostream&) const;
//- Return info proxy.
diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C
index b090188a0d..2477f0450b 100644
--- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C
+++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.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
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
index 1ae00ea731..6144653367 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
@@ -35,9 +35,9 @@ License
#include "dlLibraryTable.H"
#include "OSspecific.H"
#include "Time.H"
-#include "Pstream.H"
#include "PstreamReduceOps.H"
+
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
@@ -71,30 +71,27 @@ bool Foam::functionEntries::codeStream::execute
Istream& is
)
{
- if (isAdministrator())
- {
- FatalIOErrorIn
- (
- "functionEntries::codeStream::execute(..)",
- parentDict
- ) << "This code should not be executed by someone with administrator"
- << " rights due to security reasons." << endl
- << "(it writes a shared library which then gets loaded "
- << "using dlopen)"
- << exit(FatalIOError);
- }
+ codeStreamTools::checkSecurity
+ (
+ "functionEntries::codeStream::execute(..)",
+ parentDict
+ );
+
+ // get code dictionary
+ // must reference parent for stringOps::expand to work nicely
+ dictionary codeDict("#codeStream", parentDict, is);
// Read three sections of code.
// Remove any leading whitespace - necessary for compilation options,
// convenience for includes and body.
- dictionary codeDict(is);
// "codeInclude" is optional
string codeInclude;
if (codeDict.found("codeInclude"))
{
codeInclude = stringOps::trim(codeDict["codeInclude"]);
+ stringOps::inplaceExpand(codeInclude, codeDict);
}
// "codeOptions" is optional
@@ -102,10 +99,13 @@ bool Foam::functionEntries::codeStream::execute
if (codeDict.found("codeOptions"))
{
codeOptions = stringOps::trim(codeDict["codeOptions"]);
+ stringOps::inplaceExpand(codeOptions, codeDict);
}
// "code" is mandatory
string code = stringOps::trim(codeDict["code"]);
+ stringOps::inplaceExpand(code, codeDict);
+
// Create SHA1 digest from the contents
SHA1Digest sha;
@@ -169,6 +169,7 @@ bool Foam::functionEntries::codeStream::execute
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
+ copyFiles[0].set("SHA1sum", sha.str());
List filesContents(2);
@@ -212,6 +213,7 @@ bool Foam::functionEntries::codeStream::execute
}
}
+ // all processes must wait for compile
bool dummy = true;
reduce(dummy, orOp());
diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H
index 6edf2c621c..01f08cea5b 100644
--- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H
+++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.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
@@ -168,6 +168,9 @@ public:
//- Write
void write(Ostream&) const;
+ //- Write, optionally with contents only (no keyword, etc)
+ void write(Ostream&, const bool contentsOnly) const;
+
//- Return info proxy.
// Used to print token information to a stream
InfoProxy info() const
diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C
index fa9a50efdb..33c3dc8ff7 100644
--- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C
+++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C
@@ -210,31 +210,43 @@ Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
-void Foam::primitiveEntry::write(Ostream& os) const
+void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
{
- os.writeKeyword(keyword());
+ if (!contentsOnly)
+ {
+ os.writeKeyword(keyword());
+ }
for (label i=0; iwrite(os, false);
}
diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C
index fc1c6f0ffb..cf252d1f8b 100644
--- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C
+++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.C
@@ -49,30 +49,37 @@ const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
-Foam::fileName Foam::codeStreamTools::baseDir()
+void Foam::codeStreamTools::checkSecurity
+(
+ const char* title,
+ const dictionary& context
+)
{
- return stringOps::expandEnv("$FOAM_CASE/codeStream");
+ if (isAdministrator())
+ {
+ FatalIOErrorIn
+ (
+ title,
+ context
+ ) << "This code should not be executed by someone with administrator"
+ << " rights due to security reasons." << nl
+ << "(it writes a shared library which then gets loaded "
+ << "using dlopen)"
+ << exit(FatalIOError);
+ }
}
-Foam::fileName Foam::codeStreamTools::libSubDir()
-{
- return stringOps::expandEnv("platforms/$WM_OPTIONS/lib");
-}
-
Foam::fileName Foam::codeStreamTools::codePath(const word& subDirName)
{
- return stringOps::expandEnv
- (
- "$FOAM_CASE/codeStream/" + subDirName
- );
+ return stringOps::expand("$FOAM_CASE/codeStream/" + subDirName);
}
Foam::fileName Foam::codeStreamTools::libPath(const word& codeName)
{
- return stringOps::expandEnv
+ return stringOps::expand
(
"$FOAM_CASE/codeStream/platforms/$WM_OPTIONS/lib/lib"
+ codeName + ".so"
@@ -159,12 +166,11 @@ void Foam::codeStreamTools::copyAndExpand
{
is.getLine(line);
- // normal expansion according to mapping
+ // expand according to mapping
+ // expanding according to env variables might cause too many
+ // surprises
stringOps::inplaceExpand(line, mapping);
- // expand according to env variables
- stringOps::inplaceExpandEnv(line, true, true);
-
os << line.c_str() << nl;
}
while (is.good());
@@ -269,6 +275,13 @@ bool Foam::codeStreamTools::copyFilesContents(const fileName& dir) const
// variables mapping
HashTable mapping(copyFiles_[i]);
mapping.set("typeName", name_);
+
+ // provide a zero digest if not otherwise specified
+ if (!mapping.found("SHA1sum"))
+ {
+ mapping.insert("SHA1sum", SHA1Digest().str());
+ }
+
copyAndExpand(is, os, mapping);
}
diff --git a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H
index 4f158b6aea..8df397cc15 100644
--- a/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H
+++ b/src/OpenFOAM/db/dynamicLibrary/codeStream/codeStreamTools.H
@@ -145,13 +145,12 @@ public:
// Member functions
- //- Directory for compile/link (case-specific)
- // Expanded from \$FOAM_CASE/codeStream
- static fileName baseDir();
-
- //- Subdirectory name for library
- // Expanded from platforms/\$WM_OPTIONS/lib
- static fileName libSubDir();
+ //- Check security for creating dynamic code
+ static void checkSecurity
+ (
+ const char* title,
+ const dictionary& context
+ );
//- Local path for specified code name
// Expanded from \$FOAM_CASE/codeStream
diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C
index 05ad3a5682..4c9218d77e 100644
--- a/src/OpenFOAM/primitives/strings/string/string.C
+++ b/src/OpenFOAM/primitives/strings/string/string.C
@@ -93,8 +93,7 @@ Foam::string& Foam::string::replaceAll
}
-// Expand all occurences of environment variables and initial tilde sequences
-Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
+Foam::string& Foam::string::expand(const bool allowEmpty)
{
size_type begVar = 0;
@@ -134,20 +133,15 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
if (endVar != npos && endVar != begVar)
{
- string varName = substr
+ const string varName = substr
(
begVar + 1 + delim,
endVar - begVar - 2*delim
);
- string varValue = getEnv(varName);
-
+ const string varValue = getEnv(varName);
if (varValue.size())
{
- if (recurse)
- {
- varValue.expand(recurse, allowEmptyVar);
- }
std::string::replace
(
begVar,
@@ -156,7 +150,7 @@ Foam::string& Foam::string::expand(const bool recurse, const bool allowEmptyVar)
);
begVar += varValue.size();
}
- else if (allowEmptyVar)
+ else if (allowEmpty)
{
std::string::replace
(
diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H
index 8dec948567..618ce6bb59 100644
--- a/src/OpenFOAM/primitives/strings/string/string.H
+++ b/src/OpenFOAM/primitives/strings/string/string.H
@@ -180,13 +180,10 @@ public:
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
+ // Any unknown entries are removed silently if allowEmpty is true
// \sa
// Foam::findEtcFile
- string& expand
- (
- const bool recurse=false,
- const bool allowEmptyVar = false
- );
+ string& expand(const bool allowEmpty = false);
//- Remove repeated characters returning true if string changed
bool removeRepeated(const char);
diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
index 49142b10ec..99e7fb8ab3 100644
--- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
+++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C
@@ -24,7 +24,9 @@ License
\*---------------------------------------------------------------------------*/
#include "stringOps.H"
+#include "typeInfo.H"
#include "OSspecific.H"
+#include "OStringStream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -73,10 +75,17 @@ Foam::string& Foam::stringOps::inplaceExpand
{
string::iterator iter = s.begin() + begVar + 1;
+ // more generous in accepting keywords than for env variables
while
(
iter != s.end()
- && (isalnum(*iter) || *iter == '_')
+ &&
+ (
+ isalnum(*iter)
+ || *iter == '.'
+ || *iter == ':'
+ || *iter == '_'
+ )
)
{
++iter;
@@ -86,10 +95,14 @@ Foam::string& Foam::stringOps::inplaceExpand
if (endVar != string::npos && endVar != begVar)
{
- string varName = s.substr
+ const word varName
(
- begVar + 1 + delim,
- endVar - begVar - 2*delim
+ s.substr
+ (
+ begVar + 1 + delim,
+ endVar - begVar - 2*delim
+ ),
+ false
);
HashTable::const_iterator fnd =
@@ -130,24 +143,145 @@ Foam::string& Foam::stringOps::inplaceExpand
}
-Foam::string Foam::stringOps::expandEnv
+Foam::string Foam::stringOps::expand
(
const string& original,
- const bool recurse,
- const bool allowEmptyVar
+ const dictionary& dict,
+ const char sigil
)
{
string s(original);
- return inplaceExpandEnv(s, recurse, allowEmptyVar);
+ return inplaceExpand(s, dict, sigil);
}
-// Expand all occurences of environment variables and initial tilde sequences
-Foam::string& Foam::stringOps::inplaceExpandEnv
+Foam::string& Foam::stringOps::inplaceExpand
(
string& s,
- const bool recurse,
- const bool allowEmptyVar
+ const dictionary& dict,
+ const char sigil
+)
+{
+ string::size_type begVar = 0;
+
+ // Expand $VAR or ${VAR}
+ // Repeat until nothing more is found
+ while
+ (
+ (begVar = s.find(sigil, begVar)) != string::npos
+ && begVar < s.size()-1
+ )
+ {
+ if (begVar == 0 || s[begVar-1] != '\\')
+ {
+ // Find end of first occurrence
+ string::size_type endVar = begVar;
+ string::size_type delim = 0;
+
+ if (s[begVar+1] == '{')
+ {
+ endVar = s.find('}', begVar);
+ delim = 1;
+ }
+ else
+ {
+ string::iterator iter = s.begin() + begVar + 1;
+
+ // more generous in accepting keywords than for env variables
+ while
+ (
+ iter != s.end()
+ &&
+ (
+ isalnum(*iter)
+ || *iter == '.'
+ || *iter == ':'
+ || *iter == '_'
+ )
+ )
+ {
+ ++iter;
+ ++endVar;
+ }
+ }
+
+ if (endVar != string::npos && endVar != begVar)
+ {
+ const word varName
+ (
+ s.substr
+ (
+ begVar + 1 + delim,
+ endVar - begVar - 2*delim
+ ),
+ false
+ );
+
+
+ // lookup in the dictionary
+ const entry* ePtr = dict.lookupEntryPtr(varName, true, true);
+
+ // if defined - copy its entries
+ if (ePtr)
+ {
+ OStringStream buf;
+ if (ePtr->isDict())
+ {
+ ePtr->dict().write(buf, false);
+ }
+ else
+ {
+ // fail for other types
+ dynamicCast
+ (
+ *ePtr
+ ).write(buf, true);
+ }
+
+ s.std::string::replace
+ (
+ begVar,
+ endVar - begVar + 1,
+ buf.str()
+ );
+ begVar += buf.str().size();
+ }
+ else
+ {
+ // not defined - leave original string untouched
+ begVar = endVar;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ else
+ {
+ ++begVar;
+ }
+ }
+
+ return s;
+}
+
+
+Foam::string Foam::stringOps::expand
+(
+ const string& original,
+ const bool allowEmpty
+)
+{
+ string s(original);
+ return inplaceExpand(s, allowEmpty);
+}
+
+
+Foam::string& Foam::stringOps::inplaceExpand
+(
+ string& s,
+ const bool allowEmpty
)
{
string::size_type begVar = 0;
@@ -188,20 +322,19 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
if (endVar != string::npos && endVar != begVar)
{
- string varName = s.substr
+ const word varName
(
- begVar + 1 + delim,
- endVar - begVar - 2*delim
+ s.substr
+ (
+ begVar + 1 + delim,
+ endVar - begVar - 2*delim
+ ),
+ false
);
- string varValue = getEnv(varName);
-
+ const string varValue = getEnv(varName);
if (varValue.size())
{
- if (recurse)
- {
- varValue.expand(recurse, allowEmptyVar);
- }
s.std::string::replace
(
begVar,
@@ -210,7 +343,7 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
);
begVar += varValue.size();
}
- else if (allowEmptyVar)
+ else if (allowEmpty)
{
s.std::string::replace
(
@@ -221,7 +354,10 @@ Foam::string& Foam::stringOps::inplaceExpandEnv
}
else
{
- FatalErrorIn("string::expand(const bool, const bool)")
+ FatalErrorIn
+ (
+ "stringOps::inplaceExpand(string&, const bool)"
+ )
<< "Unknown variable name " << varName << '.'
<< exit(FatalError);
}
@@ -294,7 +430,7 @@ Foam::string Foam::stringOps::trimLeft(const string& s)
if (!s.empty())
{
string::size_type beg = 0;
- while (isspace(s[beg]))
+ while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@@ -314,7 +450,7 @@ Foam::string& Foam::stringOps::inplaceTrimLeft(string& s)
if (!s.empty())
{
string::size_type beg = 0;
- while (isspace(s[beg]))
+ while (beg < s.size() && isspace(s[beg]))
{
++beg;
}
@@ -380,4 +516,5 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
return s;
}
+
// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
index d9756a2705..cfd7993739 100644
--- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
+++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.H
@@ -36,6 +36,7 @@ SourceFiles
#define stringOps_H
#include "string.H"
+#include "dictionary.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -54,6 +55,8 @@ namespace stringOps
// -# variables
// - "$VAR", "${VAR}"
//
+ // Any unknown entries are removed
+ //
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string expand
@@ -69,6 +72,8 @@ namespace stringOps
// -# variables
// - "$VAR", "${VAR}"
//
+ // Any unknown entries are removed
+ //
// \note the leading sigil can be changed to avoid conflicts with other
// string expansions
string& inplaceExpand
@@ -78,6 +83,39 @@ namespace stringOps
const char sigil = '$'
);
+ //- Expand occurences of variables according to the dictionary
+ // Expansion includes:
+ // -# variables
+ // - "$VAR", "${VAR}"
+ //
+ // Any unknown entries are left as-is
+ //
+ // \note the leading sigil can be changed to avoid conflicts with other
+ // string expansions
+ string expand
+ (
+ const string&,
+ const dictionary& dict,
+ const char sigil = '$'
+ );
+
+
+ //- Inplace expand occurences of variables according to the dictionary
+ // Expansion includes:
+ // -# variables
+ // - "$VAR", "${VAR}"
+ //
+ // Any unknown entries are left as-is
+ //
+ // \note the leading sigil can be changed to avoid conflicts with other
+ // string expansions
+ string& inplaceExpand
+ (
+ string&,
+ const dictionary& dict,
+ const char sigil = '$'
+ );
+
//- Expand initial tildes and all occurences of environment variables
// Expansion includes:
@@ -90,13 +128,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
+ // Any unknown entries are removed silently if allowEmpty is true
// \sa
// Foam::findEtcFile
- string expandEnv
+ string expand
(
const string&,
- const bool recurse=false,
- const bool allowEmptyVar = false
+ const bool allowEmpty = false
);
@@ -111,13 +149,13 @@ namespace stringOps
// - leading "~user" : home directory for specified user
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
//
+ // Any unknown entries are removed silently if allowEmpty is true
// \sa
// Foam::findEtcFile
- string& inplaceExpandEnv
+ string& inplaceExpand
(
string&,
- const bool recurse=false,
- const bool allowEmptyVar = false
+ const bool allowEmpty = false
);
@@ -128,23 +166,18 @@ namespace stringOps
string& inplaceTrimLeft(string&);
//- Return string trimmed of trailing whitespace
- // NOT IMPLEMENTED
string trimRight(const string&);
//- Trim trailing whitespace inplace
- // NOT IMPLEMENTED
string& inplaceTrimRight(string&);
//- Return string trimmed of leading and trailing whitespace
- // NOT IMPLEMENTED
string trim(const string&);
//- Trim leading and trailing whitespace inplace
- // NOT IMPLEMENTED
string& inplaceTrim(string&);
-
} // End namespace stringOps
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
index b87a560ac0..8b19852db8 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
@@ -96,6 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
+ stringOps::inplaceExpand(codeInclude, dict);
}
// "codeOptions" is optional
@@ -103,10 +104,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
+ stringOps::inplaceExpand(codeOptions, dict);
}
// "code" is mandatory
string code = stringOps::trim(dict["code"]);
+ stringOps::inplaceExpand(code, dict);
+
// Create SHA1 digest from the contents
SHA1Digest sha;
@@ -120,7 +124,9 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
// <<"new SHA1: " << sha << endl;
- // (void) codeStreamTools::upToDate(codePath, sha)
+ // only use side-effect of writing SHA1Digest for now
+ (void) codeStreamTools::upToDate(codePath, sha);
+
// TODO: compile on-demand
if (true)
{
@@ -148,6 +154,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
+ copyFiles[0].set("SHA1sum", sha.str());
copyFiles[1].file() = fileHsrc;
@@ -186,18 +193,11 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
{
- if (isAdministrator())
- {
- FatalIOErrorIn
- (
- "codedFixedValueFvPatchScalarField::updateLibrary()",
- dict_
- ) << "This code should not be executed by someone with administrator"
- << " rights due to security reasons." << endl
- << "(it writes a shared library which then gets loaded "
- << "using dlopen)"
- << exit(FatalIOError);
- }
+ codeStreamTools::checkSecurity
+ (
+ "codedFixedValueFvPatchScalarField::updateLibrary()",
+ dict_
+ );
// write code into redirectType_ subdir
const fileName codePath = codeStreamTools::codePath(redirectType_);
@@ -216,6 +216,16 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
void* lib = dlLibraryTable::findLibrary(libPath);
+
+ // TODO:
+ // calculate old/new SHA1 for code
+ // check if the correct library version was already loaded.
+ // Find the library handle.
+ //
+ // string signatureName(redirectType_ + "_" + sha().str());
+ // void (*signatureFunction)();
+ // signatureFunction = reinterpret_cast(dlSym(lib, signatureName));
+
if (dict_.found("code"))
{
if (!lib)
@@ -270,6 +280,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
}
}
+ // all processes must wait for compile
bool dummy = true;
reduce(dummy, orOp());
diff --git a/src/postProcessing/functionObjects/systemCall/systemCall.C b/src/postProcessing/functionObjects/systemCall/systemCall.C
index 664589750c..0a9d825644 100644
--- a/src/postProcessing/functionObjects/systemCall/systemCall.C
+++ b/src/postProcessing/functionObjects/systemCall/systemCall.C
@@ -102,7 +102,7 @@ void Foam::systemCall::execute()
{
forAll(executeCalls_, callI)
{
- Foam::system(executeCalls_[callI].c_str());
+ Foam::system(executeCalls_[callI]);
}
}
@@ -111,7 +111,7 @@ void Foam::systemCall::end()
{
forAll(endCalls_, callI)
{
- Foam::system(endCalls_[callI].c_str());
+ Foam::system(endCalls_[callI]);
}
}
@@ -120,7 +120,7 @@ void Foam::systemCall::write()
{
forAll(writeCalls_, callI)
{
- Foam::system(writeCalls_[callI].c_str());
+ Foam::system(writeCalls_[callI]);
}
}
diff --git a/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary b/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary
index 22050b51a1..ae94ef4763 100644
--- a/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary
+++ b/tutorials/incompressible/icoFoam/cavity/constant/polyMesh/boundary
@@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
-| \\ / O peration | Version: dev.olesenm |
+| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
diff --git a/wmake/rules/General/standard b/wmake/rules/General/standard
index 76a60a31ce..d3e977df09 100644
--- a/wmake/rules/General/standard
+++ b/wmake/rules/General/standard
@@ -4,7 +4,7 @@ include $(GENERAL_RULES)/sourceToDep
include $(GENERAL_RULES)/flex
include $(GENERAL_RULES)/flex++
-include $(GENERAL_RULES)/coco-cpp
+## include $(GENERAL_RULES)/coco-cpp
## include $(GENERAL_RULES)/byacc
## include $(GENERAL_RULES)/btyacc++
include $(GENERAL_RULES)/bison