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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::system
int system(const std::string &command, const bool bg=false)
Definition: POSIX.C:1548
Foam::helpType::init
virtual void init()
Foam::helpType::doxygenPath
fileName doxygenPath() const
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::getEnv
string getEnv(const std::string &envName)
Definition: POSIX.C:269
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
helpType.H
Foam::Info
messageStream Info
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:453
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:295
Foam::FatalError
error FatalError
Foam::helpType::displayDocOptions
void displayDocOptions(const string &searchStr, const bool exactMatch, const word &ext) const
Foam
Definition: atmBoundaryLayer.C:26
doxygenXmlParser.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::helpType::displayDoc
void displayDoc(const word &className, const string &searchStr, const bool exactMatch, const word &ext) const
Foam::debug::controlDict
dictionary & controlDict()
Definition: debug.C:139
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Definition: stringOps.C:711
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Definition: argList.C:328
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::isDir
bool isDir(const fileName &name, const bool followLink=true)
Definition: POSIX.C:775