Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
33namespace Foam
34{
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// ************************************************************************* //
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:400
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
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,...
Parser for doxygen XML.
A class for handling file names.
Definition fileName.H:75
Base class for foam help classes.
Definition helpType.H:53
fileName doxygenPath() const
Return file path to the Doxygen sources (if available).
void displayDocOptions(const string &searchStr, const bool exactMatch, const word &ext) const
Display the list of documentation options.
void displayDoc(const word &className, const string &searchStr, const bool exactMatch, const word &ext) const
Display the help documentation in a browser.
virtual void init()
Initialise - typically setting static variables,.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for handling debugging switches.
Definition debug.C:45
dictionary & controlDict()
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Definition debug.C:142
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.
Namespace for OpenFOAM.
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition POSIX.C:341
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition POSIX.C:1704
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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)
Definition errorManip.H:125
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition POSIX.C:862
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299