diff --git a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C index 8f0e53f4e2..7f84d96bc2 100644 --- a/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.C +++ b/applications/utilities/miscellaneous/foamDebugSwitches/foamDebugSwitches.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 @@ -61,7 +61,12 @@ int main(int argc, char *argv[]) if (args.optionFound("old") || args.optionFound("new")) { - dictionary controlDict(IFstream(findEtcFile("controlDict", true))()); + fileNameList controlDictFiles = findEtcFile("controlDict", true); + dictionary controlDict; + forAllReverse(controlDictFiles, cdfi) + { + controlDict.merge(dictionary(IFstream(controlDictFiles[cdfi])())); + } wordHashSet oldDebug ( diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index c79d8f0290..920d720cf5 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -264,10 +264,11 @@ bool Foam::chDir(const fileName& dir) } -Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) +Foam::fileNameList Foam::findEtcFiles(const fileName& name, bool mandatory) { - // - // search for user files in + fileNameList results; + + // Search for user files in // * ~/.OpenFOAM/VERSION // * ~/.OpenFOAM // @@ -277,19 +278,17 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) fileName fullName = searchDir/FOAMversion/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } fullName = searchDir/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } } - - // - // search for group (site) files in + // Search for group (site) files in // * $WM_PROJECT_SITE/VERSION // * $WM_PROJECT_SITE // @@ -301,19 +300,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) fileName fullName = searchDir/FOAMversion/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } fullName = searchDir/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } } } else { - // // OR search for group (site) files in // * $WM_PROJECT_INST_DIR/site/VERSION // * $WM_PROJECT_INST_DIR/site @@ -324,20 +322,18 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) fileName fullName = searchDir/"site"/FOAMversion/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } fullName = searchDir/"site"/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } } } - - // - // search for other (shipped) files in + // Search for other (shipped) files in // * $WM_PROJECT_DIR/etc // searchDir = getEnv("WM_PROJECT_DIR"); @@ -346,24 +342,41 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) fileName fullName = searchDir/"etc"/name; if (isFile(fullName)) { - return fullName; + results.append(fullName); } } // Not found - // abort if the file is mandatory, otherwise return null - if (mandatory) + if (results.empty()) { - std::cerr - << "--> FOAM FATAL ERROR in Foam::findEtcFile() :" - " could not find mandatory file\n '" - << name.c_str() << "'\n\n" << std::endl; - ::exit(1); + // Abort if the file is mandatory, otherwise return null + if (mandatory) + { + std::cerr + << "--> FOAM FATAL ERROR in Foam::findEtcFiles() :" + " could not find mandatory file\n '" + << name.c_str() << "'\n\n" << std::endl; + ::exit(1); + } } - // Return null-constructed fileName rather than fileName::null - // to avoid cyclic dependencies in the construction of globals - return fileName(); + // Return list of matching paths or empty list if none found + return results; +} + + +Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory) +{ + fileNameList results(findEtcFiles(name, mandatory)); + + if (results.size()) + { + return results[0]; + } + else + { + return fileName(); + } } diff --git a/src/OpenFOAM/global/debug/debug.C b/src/OpenFOAM/global/debug/debug.C index b0c696987a..2cd9c861fe 100644 --- a/src/OpenFOAM/global/debug/debug.C +++ b/src/OpenFOAM/global/debug/debug.C @@ -75,10 +75,15 @@ Foam::dictionary& Foam::debug::controlDict() { if (!controlDictPtr_) { - controlDictPtr_ = new dictionary - ( - IFstream(findEtcFile("controlDict", true))() - ); + fileNameList controlDictFiles = findEtcFiles("controlDict", true); + controlDictPtr_ = new dictionary(); + forAllReverse(controlDictFiles, cdfi) + { + controlDictPtr_->merge + ( + dictionary(IFstream(controlDictFiles[cdfi])()) + ); + } } return *controlDictPtr_; diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index b774997339..119c669b5f 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -93,7 +93,7 @@ fileName cwd(); // else return false bool chDir(const fileName& dir); -//- Search for a file from user/group/shipped directories. +//- Search for files from user/group/shipped directories. // The search scheme allows for version-specific and // version-independent files using the following hierarchy: // - \b user settings: @@ -108,7 +108,14 @@ bool chDir(const fileName& dir); // - \b other (shipped) settings: // - $WM_PROJECT_DIR/etc/ // -// \return The full path name or fileName() if the name cannot be found +// \return The list of full paths of all the matching files or +// an empty list if the name cannot be found. +// Optionally abort if the file cannot be found +fileNameList findEtcFiles(const fileName&, bool mandatory=false); + +//- Search for a file using findEtcFiles. +// \return The full path name of the first file found which in the +// search hierarchy or an empty fileName if the name cannot be found. // Optionally abort if the file cannot be found fileName findEtcFile(const fileName&, bool mandatory=false);