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 | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "helpType.H"
27 #include "doxygenXmlParser.H"
28 #include "SortableList.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(helpType, 0);
35  defineRunTimeSelectionTable(helpType, dictionary);
36 }
37 
38 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
39 
41 {
42  const dictionary& docDict = debug::controlDict().subDict("Documentation");
43  List<fileName> docDirs(docDict.lookup("doxyDocDirs"));
44 
45  label dirI = -1;
46  forAll(docDirs, i)
47  {
48  if (isDir(docDirs[i].expand()))
49  {
50  dirI = i;
51  break;
52  }
53  }
54 
55  if (dirI == -1)
56  {
57  Info<< "No Doxygen sources found under search paths: "
58  << docDirs << endl;
59  return fileName();
60  }
61 
62  return docDirs[dirI];
63 }
64 
65 
67 (
68  const string& searchStr,
69  const bool exactMatch,
70  const word& ext
71 ) const
72 {
73  fileName doxyPath(doxygenPath());
74 
75  if (doxyPath.empty())
76  {
77  return;
78  }
79 
80  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
81 
82  doxygenXmlParser parser
83  (
84  doxyPath/"../DTAGS",
85  "tagfile",
86  searchStr,
87  exactMatch,
88  ext
89  );
90 
91  if (debug)
92  {
93  Info<< parser;
94  }
95 
96  Info<< "Valid types include:" << nl << SortableList<word>(parser.toc());
97 }
98 
99 
101 (
102  const word& className,
103  const string& searchStr,
104  const bool exactMatch,
105  const word& ext
106 ) const
107 {
108  fileName doxyPath(doxygenPath());
109 
110  if (doxyPath.empty())
111  {
112  return;
113  }
114 
115  Info<< "Found doxygen help in " << doxyPath.c_str() << nl << endl;
116 
117  string docBrowser = getEnv("FOAM_DOC_BROWSER");
118  if (docBrowser.empty())
119  {
120  const dictionary& docDict =
121  debug::controlDict().subDict("Documentation");
122  docDict.lookup("docBrowser") >> docBrowser;
123  }
124 
125  doxygenXmlParser parser
126  (
127  doxyPath/"../DTAGS",
128  "tagfile",
129  searchStr,
130  exactMatch,
131  ext
132  );
133 
134  if (debug)
135  {
136  Info<< parser;
137  }
138 
139  if (parser.found(className))
140  {
141  fileName docFile(doxyPath/parser.subDict(className).lookup("filename"));
142 
143  // can use FOAM_DOC_BROWSER='application file://%f' if required
144  docBrowser.replaceAll("%f", docFile);
145 
146  fileName classDirectory(parser.subDict(className).lookup("path"));
147  word classFile(parser.subDict(className).lookup("name"));
148 
149  Info<< "Showing documentation for type " << className << nl << endl;
150 
151  Info<< "Source file: " << classDirectory.c_str() << classFile << nl
152  << endl;
153 
154  system(docBrowser);
155  }
156  else
157  {
159  << "No help for type " << className << " found."
160  << " Valid options include:" << SortableList<word>(parser.toc())
161  << exit(FatalError);
162  }
163 }
164 
165 
166 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
167 
169 {}
170 
171 
172 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
173 
175 {}
176 
177 
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
179 
181 {
183  (
184  "browse",
185  "word",
186  "display documentation in browser"
187  );
188 }
189 
190 
191 // ************************************************************************* //
Foam::helpType::~helpType
virtual ~helpType()
Destructor.
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::helpType::init
virtual void init()
Initialise - typically setting static variables,.
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
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:251
SortableList.H
helpType.H
Foam::getEnv
string getEnv(const word &)
Return environment variable of given name.
Definition: POSIX.C:101
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::helpType::helpType
helpType()
Constructor.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
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: combustionModel.C:30
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
doxygenXmlParser.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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.
List
Definition: Test.C:19
Foam::debug::controlDict
dictionary & controlDict()
The central control dictionary.
Definition: debug.C:90
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::system
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1155
Foam::stringOps::expand
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurences of variables according to the mapping.
Definition: stringOps.C:74