ENH: provide FOAM_EXECUTABLE as environment variable in argList

- can be used directly from within an application or function-object.
  Makes it available for dictionaries.
This commit is contained in:
Mark Olesen
2017-02-24 17:48:13 +01:00
parent 65eb43fcb1
commit 5fc6c3ca34
4 changed files with 57 additions and 23 deletions

View File

@ -288,6 +288,9 @@ Foam::vtkPVFoam::vtkPVFoam
fullCasePath = cwd(); fullCasePath = cwd();
} }
// The name of the executable, unless already present in the environment
setEnv("FOAM_EXECUTABLE", "paraview", false);
// Set the case as an environment variable - some BCs might use this // Set the case as an environment variable - some BCs might use this
if (fullCasePath.name().find("processor", 0) == 0) if (fullCasePath.name().find("processor", 0) == 0)
{ {

View File

@ -206,6 +206,9 @@ Foam::vtkPVblockMesh::vtkPVblockMesh
fullCasePath = cwd(); fullCasePath = cwd();
} }
// The name of the executable, unless already present in the environment
setEnv("FOAM_EXECUTABLE", "paraview", false);
// Set the case as an environment variable - some BCs might use this // Set the case as an environment variable - some BCs might use this
if (fullCasePath.name().find("processor", 0) == 0) if (fullCasePath.name().find("processor", 0) == 0)
{ {

View File

@ -310,17 +310,17 @@ bool Foam::argList::postProcess(int argc, char *argv[])
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Convert argv -> args_
// Transform sequences with "(" ... ")" into string lists in the process
bool Foam::argList::regroupArgv(int& argc, char**& argv) bool Foam::argList::regroupArgv(int& argc, char**& argv)
{ {
int nArgs = 0; int nArgs = 1;
int listDepth = 0; unsigned listDepth = 0;
string tmpString; string tmpString;
// Note: we also re-write directly into args_ // Note: we rewrite directly into args_
// and use a second pass to sort out args/options // and use a second pass to sort out args/options
for (int argI = 0; argI < argc; ++argI)
args_[0] = fileName(argv[0]);
for (int argI = 1; argI < argc; ++argI)
{ {
if (strcmp(argv[argI], "(") == 0) if (strcmp(argv[argI], "(") == 0)
{ {
@ -333,7 +333,7 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
{ {
--listDepth; --listDepth;
tmpString += ")"; tmpString += ")";
if (listDepth == 0) if (!listDepth)
{ {
args_[nArgs++] = tmpString; args_[nArgs++] = tmpString;
tmpString.clear(); tmpString.clear();
@ -359,11 +359,21 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
if (tmpString.size()) if (tmpString.size())
{ {
// Group(s) not closed, but flush anything still pending
args_[nArgs++] = tmpString; args_[nArgs++] = tmpString;
} }
args_.setSize(nArgs); args_.setSize(nArgs);
std::string::size_type len = (nArgs-1); // Spaces between args
forAll(args_, argi)
{
len += args_[argi].size();
}
// Length needed for regrouped command-line
argListStr_.reserve(len);
return nArgs < argc; return nArgs < argc;
} }
@ -403,6 +413,8 @@ void Foam::argList::getRootCase()
globalCase_ = casePath.name(); globalCase_ = casePath.name();
case_ = globalCase_; case_ = globalCase_;
// The name of the executable, unless already present in the environment
setEnv("FOAM_EXECUTABLE", executable_, false);
// Set the case and case-name as an environment variable // Set the case and case-name as an environment variable
if (rootPath_.isAbsolute()) if (rootPath_.isAbsolute())
@ -440,7 +452,7 @@ Foam::argList::argList
{ {
// Check if this run is a parallel run by searching for any parallel option // Check if this run is a parallel run by searching for any parallel option
// If found call runPar which might filter argv // If found call runPar which might filter argv
for (int argI = 0; argI < argc; ++argI) for (int argI = 1; argI < argc; ++argI)
{ {
if (argv[argI][0] == '-') if (argv[argI][0] == '-')
{ {
@ -455,17 +467,11 @@ Foam::argList::argList
} }
// Convert argv -> args_ and capture ( ... ) lists // Convert argv -> args_ and capture ( ... ) lists
// for normal arguments and for options
regroupArgv(argc, argv); regroupArgv(argc, argv);
argListStr_ += args_[0];
// Get executable name // Check arguments and options, argv[0] was already handled
args_[0] = fileName(argv[0]);
executable_ = fileName(argv[0]).name();
// Check arguments and options, we already have argv[0]
int nArgs = 1; int nArgs = 1;
argListStr_ = args_[0];
for (int argI = 1; argI < args_.size(); ++argI) for (int argI = 1; argI < args_.size(); ++argI)
{ {
argListStr_ += ' '; argListStr_ += ' ';
@ -525,6 +531,9 @@ Foam::argList::argList
args_.setSize(nArgs); args_.setSize(nArgs);
// Set executable name
executable_ = fileName(args_[0]).name();
parse(checkArgs, checkOpts, initialise); parse(checkArgs, checkOpts, initialise);
} }
@ -769,7 +778,7 @@ void Foam::argList::parse
} }
// Distribute the master's argument list (with new root) // Distribute the master's argument list (with new root)
bool hadCaseOpt = options_.found("case"); const bool hadCaseOpt = options_.found("case");
for for
( (
int slave = Pstream::firstSlave(); int slave = Pstream::firstSlave();

View File

@ -42,6 +42,8 @@ Description
Default command-line options: Default command-line options:
- \par -case \<dir\> - \par -case \<dir\>
Select a case directory instead of the current working directory Select a case directory instead of the current working directory
- \par -decomposeParDict \<file\>
Read decomposePar dictionary from specified location
- \par -parallel - \par -parallel
Specify case as a parallel job Specify case as a parallel job
- \par -doc - \par -doc
@ -51,10 +53,25 @@ Description
- \par -help - \par -help
Print the usage Print the usage
The environment variable \b FOAM_CASE is set to the path of the Additionally, the \b -noFunctionObjects and \b -postProcess options
global case (same for serial and parallel jobs). may be present for some solvers or utilities.
The environment variable \b FOAM_CASENAME is set to the name of the
global case. Environment variables set by argList or by Time:
- \par FOAM_CASE
The path of the global case.
It is the same for serial and parallel jobs.
- \par FOAM_CASENAME
The name of the global case.
- \par FOAM_EXECUTABLE
If not already present in the calling environment,
it is set to the \a name portion of the calling executable.
- \par FOAM_APPLICATION
If not already present in the calling environment,
it is set to the value of the \c application entry
(from \c controlDict) if that entry is present.
The value of the \b FOAM_APPLICATION may be inconsistent if the value of
the \c application entry is adjusted during runtime.
Note Note
- The document browser used is defined by the \b FOAM_DOC_BROWSER - The document browser used is defined by the \b FOAM_DOC_BROWSER
@ -131,10 +148,12 @@ class argList
// * cwd // * cwd
// //
// Also export FOAM_CASE and FOAM_CASENAME environment variables // Also export FOAM_CASE and FOAM_CASENAME environment variables
// so they can be used immediately (eg, in decomposeParDict) // so they can be used immediately (eg, in decomposeParDict), as well
// as the FOAM_EXECUTABLE environment.
void getRootCase(); void getRootCase();
//- Transcribe argv into internal args_ //- Transcribe argv into internal args_.
// Transform sequences with "(" ... ")" into string lists
// return true if any "(" ... ")" sequences were captured // return true if any "(" ... ")" sequences were captured
bool regroupArgv(int& argc, char**& argv); bool regroupArgv(int& argc, char**& argv);