helpType.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2015 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "helpType.H"
29 #include "doxygenXmlParser.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(helpType, 0);
36  defineRunTimeSelectionTable(helpType, dictionary);
37 }
38 
39 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
40 
42 {
43  const dictionary& docDict = debug::controlDict().subDict("Documentation");
44  List<fileName> docDirs(docDict.lookup("doxyDocDirs"));
45 
46  label dirI = -1;
47  forAll(docDirs, i)
48  {
49  if (isDir(docDirs[i].expand()))
50  {
51  dirI = i;
52  break;
53  }
54  }
55 
56  if (dirI == -1)
57  {
58  Info<< "No Doxygen sources found under search paths: "
59  << docDirs << endl;
60  return fileName();
61  }
62 
63  return docDirs[dirI];
64 }
65 
66 
68 (
69  const string& searchStr,
70  const bool exactMatch,
71  const word& ext
72 ) const
73 {
74  fileName doxyPath(doxygenPath());
75 
76  if (doxyPath.empty())
77  {
78  return;
79  }
80 
81  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
82 
83  doxygenXmlParser parser
84  (
85  doxyPath/"../DTAGS",
86  "tagfile",
87  searchStr,
88  exactMatch,
89  ext
90  );
91 
92  if (debug)
93  {
94  Info<< parser;
95  }
96 
97  Info<< "Valid types:" << nl << parser.sortedToc();
98 }
99 
100 
102 (
103  const word& className,
104  const string& searchStr,
105  const bool exactMatch,
106  const word& ext
107 ) const
108 {
109  fileName doxyPath(doxygenPath());
110 
111  if (doxyPath.empty())
112  {
113  return;
114  }
115 
116  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
117 
118  string docBrowser = getEnv("FOAM_DOC_BROWSER");
119  if (docBrowser.empty())
120  {
121  const dictionary& docDict =
122  debug::controlDict().subDict("Documentation");
123  docDict.readEntry("docBrowser", docBrowser);
124  }
125 
126  doxygenXmlParser parser
127  (
128  doxyPath/"../DTAGS",
129  "tagfile",
130  searchStr,
131  exactMatch,
132  ext
133  );
134 
135  if (debug)
136  {
137  Info<< parser;
138  }
139 
140  if (parser.found(className))
141  {
142  fileName docFile
143  (
144  doxyPath/parser.subDict(className).get<fileName>("filename")
145  );
146 
147  // can use FOAM_DOC_BROWSER='application file://%f' if required
148  docBrowser.replaceAll("%f", docFile);
149 
150  fileName classDirectory
151  (
152  parser.subDict(className).get<fileName>("path")
153  );
154  const word classFile
155  (
156  parser.subDict(className).get<word>("name")
157  );
158 
159  Info<< "Showing documentation for type " << className << nl << endl;
160 
161  Info<< "Source file: " << classDirectory.c_str() << classFile << nl
162  << endl;
163 
164  Foam::system(docBrowser);
165  }
166  else
167  {
169  << "No help for type " << className << " found."
170  << " Valid options:" << parser.sortedToc()
171  << exit(FatalError);
172  }
173 }
174 
175 
176 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177 
179 {
181  (
182  "browse",
183  "word",
184  "Display documentation in browser"
185  );
186 }
187 
188 
189 // ************************************************************************* //
void displayDocOptions(const string &searchStr, const bool exactMatch, const word &ext) const
Display the list of documentation options.
A class for handling file names.
Definition: fileName.H:71
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition: POSIX.C:292
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:453
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:813
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
void displayDoc(const word &className, const string &searchStr, const bool exactMatch, const word &ext) const
Display the help documentation in a browser.
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:376
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
fileName doxygenPath() const
Return file path to the Doxygen sources (if available)
messageStream Info
Information stream (stdout output on master, null elsewhere)
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: POSIX.C:1655
dictionary & controlDict()
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Definition: debug.C:142
virtual void init()
Initialise - typically setting static variables,.
Namespace for OpenFOAM.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping and return the expanded string.
Definition: stringOps.C:705