177bool upgradeScope(
word& entryName)
182 <<
"Warning: upgrading very old ':' scope syntax: \""
183 << entryName <<
'"' <<
endl;
192 for (
const word& cmpt : cmpts)
194 if (addSep) entryName +=
'.';
218 dictAndKeyword(
const word& scopedName)
220 auto i = scopedName.rfind(
'/');
221 if (i == std::string::npos)
223 i = scopedName.rfind(
'.');
226 if (i != std::string::npos)
228 dict_ = scopedName.substr(0, i);
229 key_ = scopedName.substr(i+1);
237 const word&
dict() const noexcept {
return dict_; }
239 const word&
key() const noexcept {
return key_; }
246 const word& subDictName
249 if (subDictName.empty())
256 if (!finder.good() || !finder.isDict())
260 <<
'"' << subDictName <<
'"' <<
nl;
273 <<
"Known entries of " << finder.context().name() <<
" : " <<
nl
274 << finder.context().keys()
278 return finder.dict();
284 for (
const entry& refEntry : dictToRemove)
292 if (refEntry.isDict())
294 removeDict(finder.dict(), refEntry.dict());
297 purge = finder.dict().empty();
300 else if (finder.good() && !refEntry.isDict())
303 purge = (finder.ref() == refEntry);
308 dict.remove(refEntry.keyword());
316int main(
int argc,
char *argv[])
320 "Interrogate and manipulate dictionaries"
337 "Set entry value or add new entry"
354 "Write differences with respect to the specified dictionary"
360 "As per -diff, but locate the file as per foamEtcFile"
367 "Set default write precision for IOstreams"
373 "List the #include/#sinclude files to standard output"
378 "Read the specified dictionary file, expand the macros etc. and write "
379 "the resulting dictionary to standard output"
383 "disableFunctionEntries",
384 "Disable expansion of dictionary directives - #include, #codeStream etc"
390 const bool listIncludes =
args.found(
"includes");
397 const bool disableEntries =
args.found(
"disableFunctionEntries");
401 InfoErr<<
"Not expanding variables or dictionary directives" <<
endl;
407 const unsigned prec =
args.getOrDefault<
unsigned>(
"precision", 0u);
412 Sout.precision(prec);
419 if (!dictFile || !dictFile().good())
422 <<
"Cannot open file " << dictFileName
427 bool changed =
false;
434 const auto dictFormat = dictFile().format();
441 else if (
args.found(
"expand"))
444 <<
"//\n// " << dictFileName <<
"\n//\n";
453 bool optDiff =
false;
459 if (
args.readIfPresent(
"diff", diffFileName))
462 if (!diffFile.good())
465 <<
"Cannot open file " << diffFileName
471 diffDict = readDictionary(diffFile);
475 else if (
args.readIfPresent(
"diff-etc", diffFileName))
478 if (foundName.empty())
481 <<
"Cannot find etcFile " << diffFileName
486 if (!diffFile.good())
489 <<
"Cannot open file " << foundName
495 diffDict = readDictionary(diffFile);
501 if (
args.readIfPresent(
"entry", scopedName))
503 upgradeScope(scopedName);
508 args.readIfPresent(
"set", newValue)
509 ||
args.readIfPresent(
"add", newValue)
512 const bool overwrite =
args.found(
"set");
515 const dictAndKeyword dAk(scopedName);
542 else if (
args.found(
"remove"))
545 const dictAndKeyword dAk(scopedName);
559 const dictAndKeyword dAk(scopedName);
562 const dictionary& d2(lookupScopedDict(diffDict, dAk.dict()));
569 if (*e1Ptr == *e2Ptr)
571 const_cast<dictionary&
>(d1).remove(dAk.key());
589 <<
"Cannot find entry " << scopedName
592 else if (
args.found(
"keywords"))
595 for (
const entry&
e : finder.dict())
600 else if (
args.found(
"value"))
605 Info<< finder.dict();
607 else if (finder.isStream())
609 bool separator =
false;
611 for (
const token& tok : finder.stream())
630 else if (
args.found(
"keywords"))
641 removeDict(
dict, diffDict);
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
static Ostream & writeBanner(Ostream &os, const bool noSyntaxHint=false)
Write the standard OpenFOAM file/dictionary banner.
streamFormat format() const noexcept
Get the current stream format.
static streamFormat formatEnum(const word &fmtName, const streamFormat deflt=streamFormat::ASCII)
Lookup streamFormat enum corresponding to the string (ascii | binary).
static unsigned int defaultPrecision() noexcept
Return the default precision.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
virtual void rewind()=0
Rewind the stream so that it may be read again.
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Extract command arguments and options from the supplied argc and argv parameters.
static void noBanner()
Disable emitting the banner information.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A keyword and a list of tokens is an 'entry'.
virtual bool isDict() const noexcept
True if this entry is a dictionary.
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.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary, otherwise Fatal.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
A class for handling file names.
static bool log
Report to stdout which file is included.
@ REGEX
Regular expression.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
bool contains(char c) const noexcept
True if string contains given character (cf. C++23).
A token holds an item read from Istream.
bool isPunctuation() const noexcept
Token is PUNCTUATION.
@ BEGIN_BLOCK
Begin block [isseparator].
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
bool read(Istream &is)
Read a token from Istream, calls reset() first.
A class for handling words, derived from Foam::string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Functions to search 'etc' directories for configuration files etc.
OBJstream os(runTime.globalPath()/outputName)
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
List< word > wordList
List of word.
messageStream Info
Information stream (stdout output on master, null elsewhere).
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
OSstream Sout
OSstream wrapped stdout (std::cout).
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
messageStream InfoErr
Information stream (stderr output on master, null elsewhere).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
word format(conversionProperties.get< word >("format"))
dict add("bounds", meshBb)
Foam::argList args(argc, argv)