Skip to content
Snippets Groups Projects
Commit 4ebca298 authored by Mark Olesen's avatar Mark Olesen
Browse files

argList: avoid relative cases ending in '..' - makes for very ugly names

- this stop problems caused by a "-case .." specification

  Previously  args.globalCaseName() + ".Ext"  resulted in silly names
  eg, "...png", or "surface-...stl"
parent 35986a39
No related branches found
No related tags found
No related merge requests found
...@@ -147,6 +147,8 @@ ...@@ -147,6 +147,8 @@
processing command-line options. processing command-line options.
+ Export *new* environment variable =FOAM_CASENAME= that contains the + Export *new* environment variable =FOAM_CASENAME= that contains the
name part of the =FOAM_CASE= environment variable name part of the =FOAM_CASE= environment variable
+ Resolve relative cases ending in =..= to avoid potentially bad/ugly
case names being used.
*** Misc. improvements *** Misc. improvements
+ Improved consistency and interoperability between =face= and =triFace= classes. + Improved consistency and interoperability between =face= and =triFace= classes.
......
...@@ -66,14 +66,14 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv) ...@@ -66,14 +66,14 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
// note: we also re-write directly into args_ // note: we also re-write 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++) for (int argI = 0; argI < argc; argI++)
{ {
if (strcmp(argv[argi], "(") == 0) if (strcmp(argv[argI], "(") == 0)
{ {
level++; level++;
tmpString += "("; tmpString += "(";
} }
else if (strcmp(argv[argi], ")") == 0) else if (strcmp(argv[argI], ")") == 0)
{ {
if (level >= 1) if (level >= 1)
{ {
...@@ -87,19 +87,19 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv) ...@@ -87,19 +87,19 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv)
} }
else else
{ {
args_[nArgs++] = argv[argi]; args_[nArgs++] = argv[argI];
} }
} }
else if (level) else if (level)
{ {
// quote each string element // quote each string element
tmpString += "\""; tmpString += "\"";
tmpString += argv[argi]; tmpString += argv[argI];
tmpString += "\""; tmpString += "\"";
} }
else else
{ {
args_[nArgs++] = argv[argi]; args_[nArgs++] = argv[argI];
} }
} }
...@@ -129,12 +129,18 @@ void Foam::argList::getRootCase() ...@@ -129,12 +129,18 @@ void Foam::argList::getRootCase()
casePath = iter(); casePath = iter();
casePath.clean(); casePath.clean();
// handle degenerate form and '-case .' like no -case specified
if (casePath.empty() || casePath == ".") if (casePath.empty() || casePath == ".")
{ {
// handle degenerate form and '-case .' like no -case specified
casePath = cwd(); casePath = cwd();
options_.erase("case"); options_.erase("case");
} }
else if (casePath[0] != '/' && casePath.name() == "..")
{
// avoid relative cases ending in '..' - makes for very ugly names
casePath = cwd()/casePath;
casePath.clean();
}
} }
else else
{ {
...@@ -169,11 +175,11 @@ Foam::argList::argList ...@@ -169,11 +175,11 @@ 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 (might filter argv) // If found call runPar (might filter argv)
for (int argi=0; argi<argc; argi++) for (int argI = 0; argI < argc; argI++)
{ {
if (argv[argi][0] == '-') if (argv[argI][0] == '-')
{ {
const char *optionName = &argv[argi][1]; const char *optionName = &argv[argI][1];
if (validParOptions.found(optionName)) if (validParOptions.found(optionName))
{ {
...@@ -195,14 +201,14 @@ Foam::argList::argList ...@@ -195,14 +201,14 @@ Foam::argList::argList
int nArgs = 1; int nArgs = 1;
string argListString = args_[0]; string argListString = args_[0];
for (int argi = 1; argi < args_.size(); argi++) for (int argI = 1; argI < args_.size(); argI++)
{ {
argListString += ' '; argListString += ' ';
argListString += args_[argi]; argListString += args_[argI];
if (args_[argi][0] == '-') if (args_[argI][0] == '-')
{ {
const char *optionName = &args_[argi][1]; const char *optionName = &args_[argI][1];
if if
( (
...@@ -216,8 +222,8 @@ Foam::argList::argList ...@@ -216,8 +222,8 @@ Foam::argList::argList
) )
) )
{ {
argi++; argI++;
if (argi >= args_.size()) if (argI >= args_.size())
{ {
FatalError FatalError
<< "option " << "'-" << optionName << '\'' << "option " << "'-" << optionName << '\''
...@@ -226,8 +232,8 @@ Foam::argList::argList ...@@ -226,8 +232,8 @@ Foam::argList::argList
} }
argListString += ' '; argListString += ' ';
argListString += args_[argi]; argListString += args_[argI];
options_.insert(optionName, args_[argi]); options_.insert(optionName, args_[argI]);
} }
else else
{ {
...@@ -236,9 +242,9 @@ Foam::argList::argList ...@@ -236,9 +242,9 @@ Foam::argList::argList
} }
else else
{ {
if (nArgs != argi) if (nArgs != argI)
{ {
args_[nArgs] = args_[argi]; args_[nArgs] = args_[argI];
} }
nArgs++; nArgs++;
} }
...@@ -529,21 +535,19 @@ Foam::argList::argList ...@@ -529,21 +535,19 @@ Foam::argList::argList
// Set the case and case-name as an environment variable // Set the case and case-name as an environment variable
if (rootPath_[0] == '/') if (rootPath_[0] == '/')
{ {
// absolute path // absolute path - use as-is
setEnv("FOAM_CASE", rootPath_/globalCase_, true); setEnv("FOAM_CASE", rootPath_/globalCase_, true);
} setEnv("FOAM_CASENAME", globalCase_, true);
else if (rootPath_ == ".")
{
// relative to the current working directory
setEnv("FOAM_CASE", cwd()/globalCase_, true);
} }
else else
{ {
// qualify relative path // qualify relative path
setEnv("FOAM_CASE", cwd()/rootPath_/globalCase_, true); fileName casePath = cwd()/rootPath_/globalCase_;
} casePath.clean();
setEnv("FOAM_CASENAME", globalCase_, true);
setEnv("FOAM_CASE", casePath, true);
setEnv("FOAM_CASENAME", casePath.name(), true);
}
// Switch on signal trapping. We have to wait until after Pstream::init // Switch on signal trapping. We have to wait until after Pstream::init
// since this sets up its own ones. // since this sets up its own ones.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment