etc/controlDict: add support for merging etc/controlDict with user-specialised versions

This commit is contained in:
Henry
2011-07-06 12:40:06 +01:00
parent 5ee9f76ace
commit 49285512c7
4 changed files with 65 additions and 35 deletions

View File

@ -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
(

View File

@ -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();
}
}

View File

@ -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_;

View File

@ -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);