BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / miscellaneous / foamInfoExec / foamInfoExec.C
blob034808bfcbda5d9d42ee28ae7ec24ac9c96549bc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Interrogates a case and prints information to screen
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "objectRegistry.H"
32 #include "Time.H"
33 #include "dictionary.H"
34 #include "IFstream.H"
36 using namespace Foam;
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // Main program:
41 int main(int argc, char *argv[])
43     argList::noParallel();
44     argList::validOptions.insert("times", "");
45     argList::validOptions.insert("dictionary", "dictionary name");
46     argList::validOptions.insert("keywords", "");
47     argList::validOptions.insert("entry", "entry name");
49 #   include "setRootCase.H"
51     Info<< endl;
53     if (args.optionFound("times"))
54     {
55         instantList times
56         (
57             Foam::Time::findTimes(args.rootPath()/args.caseName())
58         );
60         forAll (times, i)
61         {
62             Info<< times[i].name() << endl;
63         }
64     }
66     if (args.optionFound("dictionary"))
67     {
68         fileName dictFileName
69         (
70             args.rootPath()/args.caseName()/args.option("dictionary")
71         );
73         IFstream dictFile(dictFileName);
75         if (dictFile.good())
76         {
77             dictionary dict(dictFile);
79             if (args.optionFound("keywords") && !args.optionFound("entry"))
80             {
81                 for
82                 (
83                     IDLList<entry>::iterator iter = dict.begin();
84                     iter != dict.end();
85                     ++iter
86                 )
87                 {
88                     Info<< iter().keyword() << endl;
89                 }
90             }
91             else if (args.optionFound("entry"))
92             {
93                 wordList entryNames
94                 (
95                     fileName(args.option("entry")).components(':')
96                 );
98                 if (dict.found(entryNames[0]))
99                 {
100                     const entry* entPtr = &dict.lookupEntry
101                     (
102                         entryNames[0],
103                         false,
104                         true            // wildcards
105                     );
107                     for (int i=1; i<entryNames.size(); i++)
108                     {
109                         if (entPtr->dict().found(entryNames[i]))
110                         {
111                             entPtr = &entPtr->dict().lookupEntry
112                             (
113                                 entryNames[i],
114                                 false,
115                                 true    // wildcards
116                             );
117                         }
118                         else
119                         {
120                             FatalErrorIn(args.executable())
121                                 << "Cannot find sub-entry " << entryNames[i]
122                                 << " in entry " << args.option("entry")
123                                 << " in dictionary " << dictFileName;
124                             FatalError.exit(3);
125                         }
126                     }
128                     if (args.optionFound("keywords"))
129                     {
130                         /*
131                         if (ent[1] != token::BEGIN_BLOCK)
132                         {
133                             FatalErrorIn(args.executable())
134                                 << "Cannot find entry "
135                                 << args.option("entry")
136                                 << " in dictionary " << dictFileName
137                                 << " is not a sub-dictionary";
138                             FatalError.exit(4);
139                         }
140                         */
142                         const dictionary& dict(entPtr->dict());
143                         for
144                         (
145                             IDLList<entry>::const_iterator iter = dict.begin();
146                             iter != dict.end();
147                             ++iter
148                         )
149                         {
150                             Info<< iter().keyword() << endl;
151                         }
152                     }
153                     else
154                     {
155                         Info<< *entPtr << endl;
156                     }
157                 }
158                 else
159                 {
160                     FatalErrorIn(args.executable())
161                         << "Cannot find entry "
162                         << entryNames[0]
163                         << " in dictionary " << dictFileName;
164                     FatalError.exit(2);
165                 }
166             }
167             else
168             {
169                 Info<< dict;
170             }
171         }
172         else
173         {
174             FatalErrorIn(args.executable())
175                 << "Cannot open file " << dictFileName;
176             FatalError.exit(1);
177         }
178     }
180     return 0;
184 // ************************************************************************* //