From 099117dd2a545ac4f6e2b22da614cfa6201834d9 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 13 Jun 2008 18:21:36 +0200 Subject: [PATCH] argList + IOobject write-headers modifications * new -srcDoc option to display doxygen-processed source code * display standard options -help/-doc/-srcDoc at end of usage * consolidate code when writing IOobject headers * drop writeLogbanner and add optional bool to writeBanner * minor formatting changes --- src/OpenFOAM/db/IOobject/IOobject.H | 7 +-- src/OpenFOAM/db/IOobject/IOobjectI.H | 38 +++++---------- .../db/IOobject/IOobjectWriteHeader.C | 14 +++--- src/OpenFOAM/global/argList/argList.C | 47 +++++++++++++------ src/OpenFOAM/global/argList/argList.H | 22 +++++---- 5 files changed, 65 insertions(+), 63 deletions(-) diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 0c35bd7f1a5..e08a56a1a87 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -329,12 +329,9 @@ public: // Writing //- Write the standard OpenFOAM file/dictionary banner + // Optionally without -*- C++ -*- editor hint (eg, for logs) template<class Stream> - static inline void writeBanner(Stream& os); - - //- Write the standard OpenFOAM log banner - template<class Stream> - static inline void writeLogBanner(Stream& os); + static inline void writeBanner(Stream& os, bool noHint=false); //- Write the standard file section divider template<class Stream> diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index 09a64ff8964..7ffff5ede50 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -29,48 +29,34 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Stream> -inline void Foam::IOobject::writeBanner(Stream& os) +inline void Foam::IOobject::writeBanner(Stream& os, bool noHint) { static bool spacesSet = false; - static char spaces[80]; + static char spaces[40]; if (!spacesSet) { - memset(spaces, ' ', 80); + memset(spaces, ' ', 40); spaces[38 - strlen(Foam::FOAMversion)] = '\0'; spacesSet = true; } - os << - "/*--------------------------------*- C++ -*----------------------------------*\\\n" - "| ========= | |\n" - "| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n" - "| \\\\ / O peration | Version: " << FOAMversion << spaces << "|\n" - "| \\\\ / A nd | Web: http://www.openfoam.org |\n" - "| \\\\/ M anipulation | |\n" - "\\*---------------------------------------------------------------------------*/\n"; -} - - -template<class Stream> -inline void Foam::IOobject::writeLogBanner(Stream& os) -{ - static bool spacesSet = false; - static char spaces[80]; - - if (!spacesSet) + if (noHint) { - memset(spaces, ' ', 80); - spaces[38 - strlen(Foam::FOAMversion)] = '\0'; - spacesSet = true; + os << + "/*---------------------------------------------------------------------------*\\\n"; + } + else + { + os << + "/*--------------------------------*- C++ -*----------------------------------*\\\n"; } os << - "/*---------------------------------------------------------------------------*\\\n" "| ========= | |\n" "| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n" "| \\\\ / O peration | Version: " << FOAMversion << spaces << "|\n" - "| \\\\ / A nd | Web: http://www.openfoam.org |\n" + "| \\\\ / A nd | Web: http://www.OpenFOAM.org |\n" "| \\\\/ M anipulation | |\n" "\\*---------------------------------------------------------------------------*/\n"; } diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 8846dd1d44c..6e647c9ca5e 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -37,8 +37,8 @@ bool Foam::IOobject::writeHeader(Ostream& os) const if (!os.good()) { Info<< "IOobject::writeHeader(Ostream&) : " - << "no stream open for write" - << endl << os.info() << endl; + << "no stream open for write" << nl + << os.info() << endl; return false; } @@ -49,16 +49,14 @@ bool Foam::IOobject::writeHeader(Ostream& os) const << " format " << os.format() << ";\n" << " class " << type() << ";\n"; + // outdent for visibility and more space if (note().size()) { - os << " note " << note() << ";\n"; + os << " note " << note() << ";\n"; } - // writing without quotes would look nicer - os << " object " << name() << ";\n" - //<< " instance " << instance()/local() << ";\n" - //<< " local " << local() << ";\n" - << " location " << instance()/local() << ";\n" + os << " location " << instance()/local() << ";\n" + << " object " << name() << ";\n" << "}" << nl; writeDivider(os); diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 8e1738a7347..59ee6e57b55 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -186,7 +186,7 @@ Foam::argList::argList // Print the banner once only for parallel runs if (Pstream::master()) { - IOobject::writeLogBanner(Info); + IOobject::writeBanner(Info, true); } // convert argv -> args_ and capture ( ... ) lists @@ -252,19 +252,30 @@ Foam::argList::argList args_.setSize(nArgs); - // Help options: - // -doc display the documentation in browser - // -help print the usage - if (options_.found("doc") || options_.found("help")) + // Help/documentation options: + // -help print the usage + // -doc display application documentation in browser + // -srcDoc display source code in browser + if + ( + options_.found("help") + || options_.found("doc") + || options_.found("srcDoc") + ) { if (options_.found("help")) { printUsage(); } - if (options_.found("doc")) + // only display one or the other + if (options_.found("srcDoc")) + { + displayDoc(true); + } + else if (options_.found("doc")) { - displayDoc(); + displayDoc(false); } ::exit(0); @@ -578,12 +589,9 @@ void Foam::argList::printUsage() const ++iter ) { - Info<< ' ' << '<' << iter().c_str() << '>'; + Info<< " <" << iter().c_str() << '>'; } - // place -doc and -help up front - Info<< " [-doc] [-help]"; - for ( HashTable<string>::iterator iter = validOptions.begin(); @@ -601,16 +609,27 @@ void Foam::argList::printUsage() const Info<< ']'; } - Info<< endl; + // place help/doc options of the way at the end, + // but with an extra space to separate it a little + Info<< " [-help] [-doc] [-srcDoc]" << endl; } -void Foam::argList::displayDoc() const +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")); + // for source code: change foo_8C.html to foo_8C-source.html + if (source) + { + forAll(docExts, extI) + { + docExts[extI].replace(".", "-source."); + } + } + fileName docFile; bool found = false; @@ -618,7 +637,7 @@ void Foam::argList::displayDoc() const { forAll(docExts, extI) { - docFile = docDirs[dirI]/executable() + docExts[extI]; + docFile = docDirs[dirI]/executable_ + docExts[extI]; docFile.expand(); if (exists(docFile)) diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index 3068e042c90..f79d6d5d171 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -27,18 +27,18 @@ Class Description Extract command arguments and options from the supplied - @a argc and @a argv. + @a argc and @a argv parameters. Sequences with "(" ... ")" are transformed into a stringList. For example, @verbatim program -listFiles \( *.txt \) @endverbatim - in which the backslash-escaping has been used to avoid shell expansions, would create a stringList: @verbatim ( "file1.txt" "file2.txt" ... "fileN.txt" ) @endverbatim + The backslash-escaping has been used to avoid shell expansions. @par Default command-line options @param -case \<dir\> \n @@ -47,6 +47,8 @@ Description specify case as a parallel job @param -doc \n display the documentation in browser + @param -srcDoc \n + display the source documentation in browser @param -help \n print the usage @@ -130,14 +132,14 @@ public: //- A list of valid parallel options static HashTable<string> validParOptions; - //! @cond ignore documentation for this class + //! @cond ignoreDocumentation class initValidTables { public: initValidTables(); }; - //! @endcond + //! @endcond ignoreDocumentation // Constructors @@ -148,8 +150,8 @@ public: ( int& argc, char**& argv, - bool checkArgs = true, - bool checkOpts = true + bool checkArgs=true, + bool checkOpts=true ); @@ -196,8 +198,7 @@ public: return globalCase_; } - //- Return case name for parallel run - // or the global case for a serial run + //- Return case name for parallel run or the global case for a serial run const fileName& caseName() const { return case_; @@ -222,13 +223,14 @@ public: void printUsage() const; //- Display documentation in browser - void displayDoc() const; + // Optionally display the application source code + void displayDoc(bool source=false) const; // Check //- Check argument list - bool check(bool checkArgs = true, bool checkOpts = true) const; + bool check(bool checkArgs=true, bool checkOpts=true) const; //- Check root path and case path bool checkRootCase() const; -- GitLab