1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
29 Extract command arguments and options from the supplied
30 @a argc and @a argv parameters.
32 Sequences with "(" ... ")" are transformed into a stringList.
35 program -listFiles \( *.txt \)
37 would create a stringList:
39 ( "file1.txt" "file2.txt" ... "fileN.txt" )
41 The backslash-escaping has been used to avoid shell expansions.
43 @par Default command-line options
44 @param -case \<dir\> \n
45 select an case directory instead of the current working directory
47 specify case as a parallel job
49 display the documentation in browser
51 display the source documentation in browser
55 The environment variable @b FOAM_CASE is set to the path of the
56 global case (same for serial and parallel jobs).
57 The environment variable @b FOAM_CASENAME is set to the name of the
61 - Adjustment of the valid (mandatory) arguments
62 by directly manipulating the static member argList::validArgs.
63 - Adjustment of the valid options
64 by directly manipulating the static member argList::validOptions.
69 \*---------------------------------------------------------------------------*/
74 #include "stringList.H"
77 #include "HashTable.H"
81 #include "IStringStream.H"
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 static bool bannerEnabled;
101 HashTable<string> options_;
105 fileName globalCase_;
108 ParRunControl parRunControl_;
117 // Private member functions
121 //- Transcribe argv into internal args_
122 // return true if any "(" ... ")" sequences were captured
123 bool regroupArgv(int& argc, char**& argv);
128 // Static data members
130 //- A list of valid (mandatory) arguments
131 static SLList<string> validArgs;
133 //- A list of valid options
134 static HashTable<string> validOptions;
136 //- A list of valid parallel options
137 static HashTable<string> validParOptions;
139 //! @cond ignoreDocumentation
140 class initValidTables
146 //! @endcond ignoreDocumentation
151 //- Construct from argc and argv
152 // checking the arguments and options as requested
171 //- Name of executable
172 const word& executable() const
178 const fileName& rootPath() const
184 const fileName& globalCaseName() const
189 //- Return case name (parallel run) or global case (serial run)
190 const fileName& caseName() const
196 fileName path() const
198 return rootPath()/caseName();
202 const stringList& args() const
207 //- Return additionl arguments,
208 // i.e. those additional to the executable itself
209 stringList::subList additionalArgs() const;
212 const Foam::HashTable<string>& options() const
217 //- Return the argument string associated with the named option
218 const string& option(const word& opt) const
220 return options_.operator[](opt);
223 //- Return true if the named option is found
224 bool optionFound(const word& opt) const
226 return options_.found(opt);
229 //- Return an IStringStream to the named option
230 IStringStream optionLookup(const word& opt) const
232 return IStringStream(option(opt));
235 //- Read a value from the named option
237 T optionRead(const word& opt) const
240 optionLookup(opt)() >> val;
244 //- Read a value from the named option if present.
245 // Return true if the named option was found.
247 bool optionReadIfPresent(const word& opt, T& val) const
249 if (optionFound(opt))
251 optionLookup(opt)() >> val;
260 //- Read a List of values from the named option
262 List<T> optionReadList(const word& opt) const
264 return readList<T>(optionLookup(opt)());
270 //- Disable emitting the banner information
271 static void noBanner();
273 //- Remove the parallel options
274 static void noParallel();
280 void printUsage() const;
282 //- Display documentation in browser
283 // Optionally display the application source code
284 void displayDoc(bool source=false) const;
289 //- Check argument list
290 bool check(bool checkArgs=true, bool checkOpts=true) const;
292 //- Check root path and case path
293 bool checkRootCase() const;
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 } // End namespace Foam
301 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305 // ************************************************************************* //