From 4ebca298906a77adad175f738d79f9114157f34f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 26 Jul 2009 13:04:03 +0200 Subject: [PATCH] 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" --- ReleaseNotes-1.6 | 2 + src/OpenFOAM/global/argList/argList.C | 62 ++++++++++++++------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/ReleaseNotes-1.6 b/ReleaseNotes-1.6 index 7b6a086e92..bb09a0deff 100644 --- a/ReleaseNotes-1.6 +++ b/ReleaseNotes-1.6 @@ -147,6 +147,8 @@ processing command-line options. + Export *new* environment variable =FOAM_CASENAME= that contains the name part of the =FOAM_CASE= environment variable + + Resolve relative cases ending in =..= to avoid potentially bad/ugly + case names being used. *** Misc. improvements + Improved consistency and interoperability between =face= and =triFace= classes. diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 37caa6ddb3..16f216adf6 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -66,14 +66,14 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv) // note: we also re-write directly into args_ // 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++; tmpString += "("; } - else if (strcmp(argv[argi], ")") == 0) + else if (strcmp(argv[argI], ")") == 0) { if (level >= 1) { @@ -87,19 +87,19 @@ bool Foam::argList::regroupArgv(int& argc, char**& argv) } else { - args_[nArgs++] = argv[argi]; + args_[nArgs++] = argv[argI]; } } else if (level) { // quote each string element tmpString += "\""; - tmpString += argv[argi]; + tmpString += argv[argI]; tmpString += "\""; } else { - args_[nArgs++] = argv[argi]; + args_[nArgs++] = argv[argI]; } } @@ -129,12 +129,18 @@ void Foam::argList::getRootCase() casePath = iter(); casePath.clean(); - // handle degenerate form and '-case .' like no -case specified if (casePath.empty() || casePath == ".") { + // handle degenerate form and '-case .' like no -case specified casePath = cwd(); 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 { @@ -169,11 +175,11 @@ Foam::argList::argList { // Check if this run is a parallel run by searching for any parallel option // If found call runPar (might filter argv) - for (int argi=0; argi= args_.size()) + argI++; + if (argI >= args_.size()) { FatalError << "option " << "'-" << optionName << '\'' @@ -226,8 +232,8 @@ Foam::argList::argList } argListString += ' '; - argListString += args_[argi]; - options_.insert(optionName, args_[argi]); + argListString += args_[argI]; + options_.insert(optionName, args_[argI]); } else { @@ -236,9 +242,9 @@ Foam::argList::argList } else { - if (nArgs != argi) + if (nArgs != argI) { - args_[nArgs] = args_[argi]; + args_[nArgs] = args_[argI]; } nArgs++; } @@ -529,21 +535,19 @@ Foam::argList::argList // Set the case and case-name as an environment variable if (rootPath_[0] == '/') { - // absolute path + // absolute path - use as-is setEnv("FOAM_CASE", rootPath_/globalCase_, true); - } - else if (rootPath_ == ".") - { - // relative to the current working directory - setEnv("FOAM_CASE", cwd()/globalCase_, true); + setEnv("FOAM_CASENAME", globalCase_, true); } else { // qualify relative path - setEnv("FOAM_CASE", cwd()/rootPath_/globalCase_, true); - } - setEnv("FOAM_CASENAME", globalCase_, true); + fileName casePath = cwd()/rootPath_/globalCase_; + casePath.clean(); + setEnv("FOAM_CASE", casePath, true); + setEnv("FOAM_CASENAME", casePath.name(), true); + } // Switch on signal trapping. We have to wait until after Pstream::init // since this sets up its own ones.