X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31dc7e4995ae83221268b24488ac724ab291b7fb..6ab5d4883f3b51e88ccdd3b59fb0e000b3b6ad0f:/utils/HelpGen/src/HelpGen.cpp diff --git a/utils/HelpGen/src/HelpGen.cpp b/utils/HelpGen/src/HelpGen.cpp index 28e9d4460c..5bd04744c7 100644 --- a/utils/HelpGen/src/HelpGen.cpp +++ b/utils/HelpGen/src/HelpGen.cpp @@ -48,22 +48,19 @@ // headers // ----------------------------------------------------------------------------- -// wxWindows +// wxWidgets #include "wx/wxprec.h" -#if wxUSE_GUI - #error "This is a console program and can be only compiled using wxBase" -#endif - #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/log.h" #include "wx/dynarray.h" - #include "wx/wx.h" + #include "wx/app.h" #endif // WX_PRECOMP #include "wx/file.h" #include "wx/regex.h" +#include "wx/hash.h" // C++ parsing classes #include "cjparser.h" @@ -77,23 +74,6 @@ #undef GetCurrentTime #endif -// ----------------------------------------------------------------------------- -// global vars -// ----------------------------------------------------------------------------- - -class HelpGenApp: public wxApp -{ -public: - HelpGenApp() {}; - - // don't let wxWin parse our cmd line, we do it ourselves - virtual bool OnInit() { return TRUE; } - - virtual int OnRun(); -}; - -// IMPLEMENT_APP(HelpGenApp); - // ----------------------------------------------------------------------------- // private functions // ----------------------------------------------------------------------------- @@ -280,8 +260,10 @@ protected: IgnoreListEntry *second); // for efficiency, let's sort it +public: // FIXME: macro requires it WX_DEFINE_SORTED_ARRAY(IgnoreListEntry *, ArrayNamesToIgnore); +protected: ArrayNamesToIgnore m_ignore; private: @@ -457,6 +439,8 @@ protected: wxString m_type; }; + friend class ParamInfo; // for access to TypeInfo + // info abotu a function parameter class ParamInfo { @@ -478,6 +462,7 @@ protected: wxString m_value; // default value }; +public: // FIXME: macro requires it WX_DEFINE_ARRAY(ParamInfo *, ArrayParamInfo); // info about a function @@ -523,6 +508,7 @@ protected: WX_DEFINE_ARRAY(MethodInfo *, ArrayMethodInfo); WX_DEFINE_ARRAY(ArrayMethodInfo *, ArrayMethodInfos); +private: // first array contains the names of all classes we found, the second has a // pointer to the array of methods of the given class at the same index as // the class name appears in m_classes @@ -541,10 +527,12 @@ private: // implementation // ============================================================================= +static char **g_argv = NULL; + // this function never returns static void usage() { - wxString prog = wxTheApp->argv[0]; + wxString prog = g_argv[0]; wxString basename = prog.AfterLast('/'); #ifdef __WXMSW__ if ( !basename ) @@ -580,8 +568,18 @@ static void usage() exit(1); } -int HelpGenApp::OnRun() +int main(int argc, char **argv) { + g_argv = argv; + + wxInitializer initializer; + if ( !initializer ) + { + fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); + + return -1; + } + enum { Mode_None, @@ -787,21 +785,6 @@ int HelpGenApp::OnRun() return 0; } -int main(int argc, char **argv) -{ - wxInitializer initializer; - if ( !initializer ) - { - fprintf(stderr, "Failed to initialize the wxWindows library, aborting."); - - return -1; - } - HelpGenApp app; - app.argc = argc; - app.argv = argv; - return app.OnRun(); -} - // ----------------------------------------------------------------------------- // HelpGenVisitor implementation // ----------------------------------------------------------------------------- @@ -893,13 +876,43 @@ void HelpGenVisitor::CloseFunction() void HelpGenVisitor::CloseClass() { + CloseFunction(); + if ( m_inClass ) { size_t count = m_arrayFuncDocs.GetCount(); if ( count ) { + size_t n; FunctionDocEntry::classname = m_classname; + m_arrayFuncDocs.Sort(FunctionDocEntry::Compare); - for ( size_t n = 0; n < count; n++ ) { + // Now examine each first line and if it's been seen, cut it + // off (it's a duplicate \membersection) + wxHashTable membersections(wxKEY_STRING); + + for ( n = 0; n < count; n++ ) + { + wxString section(m_arrayFuncDocs[n].text); + + // Strip leading whitespace + int pos = section.Find("\\membersection"); + if (pos > -1) + { + section = section.Mid(pos); + } + + wxString ms(section.BeforeFirst(wxT('\n'))); + if (membersections.Get(ms)) + { + m_arrayFuncDocs[n].text = section.AfterFirst(wxT('\n')); + } + else + { + membersections.Put(ms, & membersections); + } + } + + for ( n = 0; n < count; n++ ) { m_file.WriteTeX(m_arrayFuncDocs[n].text); } @@ -909,6 +922,7 @@ void HelpGenVisitor::CloseClass() m_inClass = FALSE; m_classname.clear(); } + m_file.FlushAll(); } void HelpGenVisitor::EndVisit() @@ -920,6 +934,11 @@ void HelpGenVisitor::EndVisit() m_fileHeader.Empty(); m_file.FlushAll(); + if (m_file.IsOpened()) + { + m_file.Flush(); + m_file.Close(); + } wxLogVerbose("%s: finished generating for the current file.", GetCurrentTime("%H:%M:%S")); @@ -936,6 +955,12 @@ void HelpGenVisitor::VisitClass( spClass& cl ) { CloseClass(); + if (m_file.IsOpened()) + { + m_file.Flush(); + m_file.Close(); + } + wxString name = cl.GetName(); if ( m_ignoreNames.IgnoreClass(name) ) { @@ -1002,7 +1027,7 @@ void HelpGenVisitor::VisitClass( spClass& cl ) // if the header includes other headers they must be related to it... try to // automatically generate the "See also" clause if ( !m_headers.IsEmpty() ) { - // correspondence between wxWindows headers and class names + // correspondence between wxWidgets headers and class names static const char *headers[] = { "object", "defs", @@ -1097,6 +1122,12 @@ void HelpGenVisitor::VisitClass( spClass& cl ) } totalText << derived << "\n\n"; + // include file section + wxString includeFile = "\\wxheading{Include files}\n\n"; + includeFile << "<" << m_fileHeader << ">"; + + totalText << includeFile << "\n\n"; + // write all this to file m_file.WriteTeX(totalText); @@ -1104,6 +1135,8 @@ void HelpGenVisitor::VisitClass( spClass& cl ) InsertDataStructuresHeader(); InsertTypedefDocs(); InsertEnumDocs(); + + //m_file.Flush(); } void HelpGenVisitor::VisitEnumeration( spEnumeration& en ) @@ -1245,21 +1278,24 @@ void HelpGenVisitor::VisitOperation( spOperation& op ) // check for the special case of dtor wxString dtor; - if ( (funcname[0] == '~') && (m_classname == funcname.c_str() + 1) ) { + if ( (funcname[0u] == '~') && (m_classname == funcname.c_str() + 1) ) { dtor.Printf("\\destruct{%s}", m_classname.c_str()); funcname = dtor; } - m_textFunc.Printf("\n" - "\\membersection{%s::%s}\\label{%s}\n" - "\n" + m_textFunc.Printf("\n" + "\\membersection{%s::%s}\\label{%s}\n", + m_classname.c_str(), funcname.c_str(), + MakeLabel(m_classname, funcname).c_str()); + + wxString func; + func.Printf("\n" "\\%sfunc{%s%s}{%s}{", - m_classname.c_str(), funcname.c_str(), - MakeLabel(m_classname, funcname).c_str(), op.mIsConstant ? "const" : "", op.mIsVirtual ? "virtual " : "", op.mRetType.c_str(), funcname.c_str()); + m_textFunc += func; } void HelpGenVisitor::VisitParameter( spParameter& param ) @@ -1394,7 +1430,7 @@ bool DocManager::ParseTeXFile(const wxString& filename) // the name of the class from the last "\membersection" command: we assume // that the following "\func" or "\constfunc" always documents a method of - // this class (and it should always be like that in wxWindows documentation) + // this class (and it should always be like that in wxWidgets documentation) wxString classname; for ( const char *current = buf; current - buf < len; current++ ) { @@ -2099,7 +2135,7 @@ static void TeXUnfilter(wxString* str) // undo TeXFilter static wxRegEx reNonSpecialSpecials("\\\\([#$%&_{}])"), - reAccents("\\\\verb|([~^])|"); + reAccents("\\\\verb\\|([~^])\\|"); reNonSpecialSpecials.ReplaceAll(str, "\\1"); reAccents.ReplaceAll(str, "\\1"); @@ -2149,6 +2185,38 @@ static const wxString GetVersionString() /* $Log$ + Revision 1.28 2004/05/25 11:19:57 JS + More name changes + + Revision 1.27 2003/10/13 17:21:30 MBN + Compilation fixes. + + Revision 1.26 2003/09/29 15:18:35 MBN + (Blind) compilation fix for Sun compiler. + + Revision 1.25 2003/09/03 17:39:27 MBN + Compilation fixes. + + Revision 1.24 2003/08/13 22:59:37 VZ + compilation fix + + Revision 1.23 2003/06/13 17:05:43 VZ + quote '|' inside regexes (fixes dump mode); fixed crash due to strange HelpGenApp code + + Revision 1.22 2002/01/21 21:18:50 JS + Now adds 'include file' heading + + Revision 1.21 2002/01/04 11:06:09 JS + Fixed missing membersections bug and also bug with functions not being written + in the right class + + Revision 1.20 2002/01/03 14:23:33 JS + Added code to make it not duplicate membersections for overloaded functions + + Revision 1.19 2002/01/03 13:34:12 JS + Added FlushAll to CloseClass, otherwise text was only flushed right at the end, + and appeared in one file. + Revision 1.18 2002/01/03 12:02:47 JS Added main() and corrected VC++ project settings @@ -2234,7 +2302,7 @@ static const wxString GetVersionString() date: 1999/01/08 17:45:55; author: VZ; state: Exp; HelpGen is a prototype of the tool for automatic generation of the .tex files - for wxWindows documentation from C++ headers + for wxWidgets documentation from C++ headers */ /* vi: set tw=80 et ts=4 sw=4: */