expandDictionary.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  expandDictionary
26 
27 Description
28  Read the dictionary provided as an argument, expand the macros etc. and
29  write the resulting dictionary to standard output.
30 
31 Usage
32  - expandDictionary inputDict [OPTION]
33 
34  \param -list \n
35  Report the #include/#includeIfPresent to stdout only.
36 
37 Note
38  The \c -list option can be useful when determining which files
39  are actually included by a directory. It can also be used to
40  determine which files may need to be copied when transferring
41  simulation to another environment. The following code snippet
42  could be a useful basis for such cases:
43 
44  \verbatim
45  for i in . 0 constant system
46  do
47  find $i -maxdepth 1 -type f -exec expandDictionary -list '{}' \;
48  done | sed -ne '/^"\//!{ s/^"//; s/"$//; p }' | sort | uniq
49  \endverbatim
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #include "argList.H"
54 #include "IFstream.H"
55 #include "IOobject.H"
56 #include "dictionary.H"
57 #include "includeEntry.H"
58 
59 using namespace Foam;
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 int main(int argc, char *argv[])
64 {
66  (
67  "Read the specified dictionary file, expand the macros etc. and write\n"
68  "the resulting dictionary to standard output."
69  );
70 
72  (
73  "list",
74  "Report the #include/#includeIfPresent to stdout only"
75  );
76 
79  argList::validArgs.append("inputDict");
80  argList args(argc, argv);
81 
82  const string dictName = args[1];
83 
84  const bool listOpt = args.optionFound("list");
85 
86  if (listOpt)
87  {
89  }
90 
91  dictionary dict(IFstream(dictName)(), true);
92 
93  if (!listOpt)
94  {
96  <<"//\n// " << dictName << "\n//\n";
97  dict.write(Info, false);
99  }
100 
101  return 0;
102 }
103 
104 
105 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:155
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
Foam::IFstream
Input from file stream.
Definition: IFstream.H:81
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::functionEntries::includeEntry::report
static bool report
Report which file is included to stdout.
Definition: includeEntry.H:94
dictName
const word dictName("particleTrackDict")
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
IOobject.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::IOobject::writeDivider
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:108
Foam::IOobject::writeBanner
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
Definition: IOobjectI.H:45
includeEntry.H
dictionary.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::dictionary::write
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:173