Commit 37f35ed1 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: command-line -doc, -srcDoc display online documentation

- browser is spawned as a background process to avoid blocking the
  command-line
parent 63433cad
......@@ -18,17 +18,15 @@ FoamFile
Documentation
{
docBrowser "firefox %f";
docBrowser "firefox -new-tab %f";
doxySourceFileExt "_8C.html";
// Places to search for documentation, http is last in the list
doxyDocDirs
(
"$WM_PROJECT_USER_DIR/html"
"~OpenFOAM/html"
"$WM_PROJECT_DIR/doc/Doxygen/html"
);
doxySourceFileExts
(
"App_8C.html"
"_8C.html"
"https://www.openfoam.com/documentation/cpp-guide/html"
);
}
......
......@@ -38,6 +38,8 @@ License
#include "sigQuit.H"
#include "sigSegv.H"
#include "foamVersion.H"
#include "stringOps.H"
#include "CStringList.H"
#include "uncollatedFileOperation.H"
#include "masterUncollatedFileOperation.H"
......@@ -657,14 +659,14 @@ void Foam::argList::parse
}
// Only display one or the other
if (options_.found("srcDoc"))
if (options_.found("doc"))
{
displayDoc(true);
displayDoc(false);
quickExit = true;
}
else if (options_.found("doc"))
else if (options_.found("srcDoc"))
{
displayDoc(false);
displayDoc(true);
quickExit = true;
}
......@@ -1362,59 +1364,72 @@ void Foam::argList::displayDoc(bool source) const
{
const dictionary& docDict = debug::controlDict().subDict("Documentation");
List<fileName> docDirs(docDict.lookup("doxyDocDirs"));
List<fileName> docExts(docDict.lookup("doxySourceFileExts"));
fileName docExt(docDict.lookup("doxySourceFileExt"));
// For source code: change foo_8C.html to foo_8C_source.html
// For source code: change xxx_8C.html to xxx_8C_source.html
if (source)
{
for (fileName& ext : docExts)
{
ext.replace(".", "_source.");
}
docExt.replace(".", "_source.");
}
fileName docFile;
bool found = false;
fileName url;
for (const fileName& dir : docDirs)
{
for (const fileName& ext : docExts)
// http protocols are last in the list
if (dir.startsWith("http:") || dir.startsWith("https:"))
{
docFile = dir/executable_ + ext;
docFile.expand();
if (isFile(docFile))
{
found = true;
break;
}
url = dir/executable_ + docExt;
break;
}
if (found)
fileName docFile = stringOps::expand(dir/executable_ + docExt);
if
(
docFile.startsWith("file://")
? isFile(docFile.substr(7)) // check part after "file://"
: isFile(docFile)
)
{
url = std::move(docFile);
break;
}
}
if (found)
if (url.empty())
{
string docBrowser = getEnv("FOAM_DOC_BROWSER");
if (docBrowser.empty())
{
docDict.lookup("docBrowser") >> docBrowser;
}
// Can use FOAM_DOC_BROWSER='application file://%f' if required
docBrowser.replaceAll("%f", docFile);
Info<< nl
<< "No documentation found for " << executable_
<< ", but you can use -help to display the usage\n" << endl;
Info<< "Show documentation: " << docBrowser.c_str() << endl;
return;
}
string docBrowser = getEnv("FOAM_DOC_BROWSER");
if (docBrowser.empty())
{
docDict.lookup("docBrowser") >> docBrowser;
}
Foam::system(docBrowser);
// Can use FOAM_DOC_BROWSER='application file://%f' if required
if (docBrowser.find("%f") != std::string::npos)
{
docBrowser.replace("%f", url);
}
else
{
Info<< nl
<< "No documentation found for " << executable_
<< ", but you can use -help to display the usage\n" << endl;
docBrowser += " " + url;
}
// Split on whitespace to use safer version of Foam::system()
CStringList command(stringOps::splitSpace(docBrowser));
Info<<"OpenFOAM-" << Foam::FOAMversion << " documentation:" << nl
<< " " << command << nl << endl;
Foam::system(command, true);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment