foamDictionary: Added -dict option to set, add and merge

With the -dict option the set, add and merge options read the entry from the
dictionary name argument rather than directly from the argument string.
This commit is contained in:
Henry Weller
2018-12-06 23:07:53 +00:00
parent abde9a8a7c
commit d61ca8d8d8

View File

@ -46,6 +46,9 @@ Usage
- \par -merge \<value\>
Merges the entry
- \par -dict
Set, add or merge entry from a dictionary
- \par -remove
Remove the selected entry
@ -273,6 +276,11 @@ int main(int argc, char *argv[])
"Merge entry"
);
argList::addBoolOption
(
"dict",
"Set, add or merge entry from a dictionary."
);
argList::addBoolOption
(
"remove",
"Remove the entry."
@ -325,13 +333,13 @@ int main(int argc, char *argv[])
<< exit(FatalError, 1);
}
bool changed = false;
// Read but preserve headers
dictionary dict;
dict.read(dictFile(), true);
bool changed = false;
if (listIncludes)
{
return 0;
@ -382,11 +390,49 @@ int main(int argc, char *argv[])
const bool merge = args.optionFound("merge");
Pair<word> dAk(dictAndKeyword(scopedName));
IStringStream str(string(dAk.second()) + ' ' + newValue + ';');
entry* ePtr(entry::New(str).ptr());
const dictionary& d(lookupScopedDict(dict, dAk.first()));
entry* ePtr = nullptr;
if (args.optionFound("dict"))
{
const fileName fromDictFileName(newValue);
autoPtr<IFstream> fromDictFile(new IFstream(fromDictFileName));
if (!fromDictFile().good())
{
FatalErrorInFunction
<< "Cannot open file " << fromDictFileName
<< exit(FatalError, 1);
}
dictionary fromDict(fromDictFile());
const entry* fePtr
(
fromDict.lookupScopedEntryPtr
(
scopedName,
false,
true // Support wildcards
)
);
if (!fePtr)
{
FatalErrorInFunction
<< "Cannot find entry " << entryName
<< " in file " << fromDictFileName
<< exit(FatalError, 1);
}
ePtr = fePtr->clone().ptr();
}
else
{
IStringStream str(string(dAk.second()) + ' ' + newValue + ';');
ePtr = entry::New(str).ptr();
}
if (overwrite)
{
const_cast<dictionary&>(d).set(ePtr);