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:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user