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 #include "SortableList.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(helpType, 0);
37  defineRunTimeSelectionTable(helpType, dictionary);
38 }
39 
40 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41 
43 {
44  const dictionary& docDict = debug::controlDict().subDict("Documentation");
45  List<fileName> docDirs(docDict.lookup("doxyDocDirs"));
46 
47  label dirI = -1;
48  forAll(docDirs, i)
49  {
50  if (isDir(docDirs[i].expand()))
51  {
52  dirI = i;
53  break;
54  }
55  }
56 
57  if (dirI == -1)
58  {
59  Info<< "No Doxygen sources found under search paths: "
60  << docDirs << endl;
61  return fileName();
62  }
63 
64  return docDirs[dirI];
65 }
66 
67 
69 (
70  const string& searchStr,
71  const bool exactMatch,
72  const word& ext
73 ) const
74 {
75  fileName doxyPath(doxygenPath());
76 
77  if (doxyPath.empty())
78  {
79  return;
80  }
81 
82  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
83 
84  doxygenXmlParser parser
85  (
86  doxyPath/"../DTAGS",
87  "tagfile",
88  searchStr,
89  exactMatch,
90  ext
91  );
92 
93  if (debug)
94  {
95  Info<< parser;
96  }
97 
98  Info<< "Valid types include:" << nl << SortableList<word>(parser.toc());
99 }
100 
101 
103 (
104  const word& className,
105  const string& searchStr,
106  const bool exactMatch,
107  const word& ext
108 ) const
109 {
110  fileName doxyPath(doxygenPath());
111 
112  if (doxyPath.empty())
113  {
114  return;
115  }
116 
117  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
118 
119  string docBrowser = getEnv("FOAM_DOC_BROWSER");
120  if (docBrowser.empty())
121  {
122  const dictionary& docDict =
123  debug::controlDict().subDict("Documentation");
124  docDict.readEntry("docBrowser", docBrowser);
125  }
126 
127  doxygenXmlParser parser
128  (
129  doxyPath/"../DTAGS",
130  "tagfile",
131  searchStr,
132  exactMatch,
133  ext
134  );
135 
136  if (debug)
137  {
138  Info<< parser;
139  }
140 
141  if (parser.found(className))
142  {
143  fileName docFile
144  (
145  doxyPath/parser.subDict(className).get<fileName>("filename")
146  );
147 
148  // can use FOAM_DOC_BROWSER='application file://%f' if required
149  docBrowser.replaceAll("%f", docFile);
150 
151  fileName classDirectory
152  (
153  parser.subDict(className).get<fileName>("path")
154  );
155  const word classFile
156  (
157  parser.subDict(className).get<word>("name")
158  );
159 
160  Info<< "Showing documentation for type " << className << nl << endl;
161 
162  Info<< "Source file: " << classDirectory.c_str() << classFile << nl
163  << endl;
164 
165  Foam::system(docBrowser);
166  }
167  else
168  {
170  << "No help for type " << className << " found."
171  << " Valid options include:" << SortableList<word>(parser.toc())
172  << exit(FatalError);
173  }
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 
180 {}
181 
182 
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
192 {
194  (
195  "browse",
196  "word",
197  "Display documentation in browser"
198  );
199 }
200 
201 
202 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::helpType::~helpType
virtual ~helpType()
Destructor.
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::system
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: MSwindows.C:1140
Foam::helpType::init
virtual void init()
Initialise - typically setting static variables,.
Foam::helpType::doxygenPath
fileName doxygenPath() const
Return file path to the Doxygen sources (if available)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::getEnv
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition: MSwindows.C:371
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Definition: stringOps.C:720
SortableList.H
helpType.H
Foam::helpType::helpType
helpType()
Constructor.
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::FatalError
error FatalError
Foam::helpType::displayDocOptions
void displayDocOptions(const string &searchStr, const bool exactMatch, const word &ext) const
Display the list of documentation options.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
doxygenXmlParser.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::helpType::displayDoc
void displayDoc(const word &className, const string &searchStr, const bool exactMatch, const word &ext) const
Display the help documentation in a browser.
Foam::debug::controlDict
dictionary & controlDict()
Definition: debug.C:143
Foam::argList::addOption
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:336
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
Definition: MSwindows.C:643