139 using namespace Foam;
145 bool upgradeScope(
word& entryName)
150 <<
"Warning: upgrading very old ':' scope syntax: \"" 151 << entryName <<
'"' <<
endl;
160 for (
const word& cmpt : cmpts)
162 if (addSep) entryName +=
'.';
186 dictAndKeyword(
const word& scopedName)
188 auto i = scopedName.rfind(
'/');
189 if (i == std::string::npos)
191 i = scopedName.rfind(
'.');
194 if (i != std::string::npos)
196 dict_ = scopedName.substr(0, i);
197 key_ = scopedName.substr(i+1);
214 const word& subDictName
217 if (subDictName.empty())
224 if (!eptr || !eptr->
isDict())
227 <<
"'" << subDictName <<
"' not found in dictionary " 228 <<
dict.
name() <<
" or is not a dictionary" <<
nl 229 <<
"Known entries are " <<
dict.
keys()
239 for (
const entry& refEntry : dictToRemove)
247 if (refEntry.isDict())
249 removeDict(finder.dict(), refEntry.dict());
252 purge = finder.
dict().empty();
255 else if (finder.good() && !refEntry.isDict())
258 purge = (finder.ref() == refEntry);
269 int main(
int argc,
char *argv[])
273 "Interrogate and manipulate dictionaries" 290 "Set entry value or add new entry" 307 "Write differences with respect to the specified dictionary" 313 "As per -diff, but locate the file as per foamEtcFile" 320 "Set default write precision for IOstreams" 326 "List the #include/#sinclude files to standard output" 331 "Read the specified dictionary file, expand the macros etc. and write " 332 "the resulting dictionary to standard output" 336 "disableFunctionEntries",
337 "Disable expansion of dictionary directives - #include, #codeStream etc" 343 const bool listIncludes =
args.
found(
"includes");
350 const bool disableEntries =
args.
found(
"disableFunctionEntries");
354 InfoErr<<
"Not expanding variables or dictionary directives" <<
endl;
372 if (!dictFile().good())
375 <<
"Cannot open file " << dictFileName
380 bool changed =
false;
392 <<
"//\n// " << dictFileName <<
"\n//\n";
401 bool optDiff =
false;
410 if (!diffFile.good())
413 <<
"Cannot open file " << diffFileName
418 diffDict.
read(diffFile,
true);
424 if (foundName.empty())
427 <<
"Cannot find etcFile " << diffFileName
432 if (!diffFile.good())
435 <<
"Cannot open file " << foundName
440 diffDict.
read(diffFile,
true);
448 upgradeScope(scopedName);
457 const bool overwrite =
args.
found(
"set");
460 const dictAndKeyword dAk(scopedName);
490 const dictAndKeyword dAk(scopedName);
504 const dictAndKeyword dAk(scopedName);
507 const dictionary& d2(lookupScopedDict(diffDict, dAk.dict()));
514 if (*e1Ptr == *e2Ptr)
516 const_cast<dictionary&
>(d1).
remove(dAk.key());
522 const_cast<dictionary&>(e1Ptr->
dict()),
534 <<
"Cannot find entry " << scopedName
540 for (
const entry&
e : finder.dict())
550 Info<< finder.dict();
552 else if (finder.ref().isStream())
556 const tokenList& tokens = finder.ref().stream();
558 for (
const token& tok : tokens)
585 removeDict(
dict, diffDict);
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
dict_reference dict() const
Reference the found entry as a dictionary.
static void addNote(const string ¬e)
Add extra notes for the usage information.
A class for handling file names.
bool contains(char c) const noexcept
True if string contains given character (cf. C++23)
errorManipArg< error, int > exit(error &err, const int errNo=1)
messageStream InfoErr
Information stream (stderr output on master, null elsewhere)
bool read(Istream &is)
Read dictionary from Istream (discards the header). Reads entries until EOF or when the first token i...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
static unsigned int defaultPrecision() noexcept
Return the default precision.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
const fileName & name() const noexcept
The dictionary name.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
bool remove(const word &keyword)
Remove an entry specified by keyword.
const_searcher search(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
const dimensionedScalar e
Elementary charge.
virtual int precision() const override
Get precision of output field.
A class for handling words, derived from Foam::string.
Functions to search 'etc' directories for configuration files etc.
Extract command arguments and options from the supplied argc and argv parameters. ...
OSstream Sout
OSstream wrapped stdout (std::cout)
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
const_searcher csearchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using scoping.
Input from file stream, using an ISstream.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
T get(const label index) const
Get a value from the argument at index.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void noBanner()
Disable emitting the banner information.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
static Ostream & writeBanner(Ostream &os, const bool noSyntaxHint=false)
Write the standard OpenFOAM file/dictionary banner.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
static bool log
Report to stdout which file is included.
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
A keyword and a list of tokens is an 'entry'.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...