X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/28468136d08dfa16a4052770a6c66e2c60663941..4fcd60c72f6b90f5063f7000ff5a80a9004055a3:/utils/HelpGen/src/HelpGen.cpp diff --git a/utils/HelpGen/src/HelpGen.cpp b/utils/HelpGen/src/HelpGen.cpp index 33ac212e03..6828f79252 100644 --- a/utils/HelpGen/src/HelpGen.cpp +++ b/utils/HelpGen/src/HelpGen.cpp @@ -55,9 +55,11 @@ #include #include #include + #include #endif // WX_PRECOMP #include +#include // C++ parsing classes #include "cjparser.h" @@ -66,19 +68,24 @@ #include #include +// argh, Windows defines this +#ifdef GetCurrentTime +#undef GetCurrentTime +#endif + // ----------------------------------------------------------------------------- // global vars // ----------------------------------------------------------------------------- -// just a copy of argv -static char **g_argv = NULL; - class HelpGenApp: public wxApp { public: HelpGenApp() {}; - bool OnInit(); + // don't let wxWin parse our cmd line, we do it ourselves + virtual bool OnInit() { return TRUE; } + + virtual int OnRun(); }; IMPLEMENT_APP(HelpGenApp); @@ -102,12 +109,11 @@ static wxString GetAllComments(const spContext& ctx); // get the string with current time (returns pointer to static buffer) // timeFormat is used for the call of strftime(3) -#ifdef GetCurrentTime -#undef GetCurrentTime -#endif - static const char *GetCurrentTime(const char *timeFormat); +// get the string containing the program version +static const wxString GetVersionString(); + // ----------------------------------------------------------------------------- // private classes // ----------------------------------------------------------------------------- @@ -118,6 +124,14 @@ class wxTeXFile : public wxFile public: wxTeXFile() { } + // write a string to file verbatim (should only be used for the strings + // inside verbatim environment) + bool WriteVerbatim(const wxString& s) + { + return wxFile::Write(s); + } + + // write a string quoting TeX specials in it bool WriteTeX(const wxString& s) { wxString t(s); @@ -242,10 +256,14 @@ protected: m_inFunction; // we're parsing a function declaration // holders for "saved" documentation - wxString m_textStoredEnums, - m_textStoredTypedefs, + wxString m_textStoredTypedefs, m_textStoredFunctionComment; + // for enums we have to use an array as we can't intermix the normal text + // and the text inside verbatim environment + wxArrayString m_storedEnums, + m_storedEnumsVerb; + // headers included by this file wxArrayString m_headers; @@ -430,16 +448,16 @@ private: // this function never returns static void usage() { - wxString prog = g_argv[0]; - wxString basename = prog.BeforeLast('/'); + wxString prog = wxTheApp->argv[0]; + wxString basename = prog.AfterLast('/'); #ifdef __WXMSW__ if ( !basename ) - basename = prog.BeforeLast('\\'); + basename = prog.AfterLast('\\'); #endif if ( !basename ) basename = prog; - wxLogError( + wxLogMessage( "usage: %s [global options] [mode options] \n" "\n" " where global options are:\n" @@ -466,12 +484,7 @@ static void usage() exit(1); } -/* -int main(int argc, char **argv) -{ -*/ - -bool HelpGenApp::OnInit() +int HelpGenApp::OnRun() { enum { @@ -480,8 +493,6 @@ bool HelpGenApp::OnInit() Mode_Diff } mode = Mode_None; - g_argv = argv; - if ( argc < 2 ) { usage(); } @@ -510,6 +521,14 @@ bool HelpGenApp::OnInit() case 'H': // help requested usage(); + // doesn't return + + case 'V': + // version requested + wxLogMessage("HelpGen version %s\n" + "(c) 1999-2001 Vadim Zeitlin\n", + GetVersionString().c_str()); + return 0; case 'i': current++; @@ -649,7 +668,7 @@ bool HelpGenApp::OnInit() wxLogError("Can't complete diff."); // failure - return false; + return FALSE; } DocManager docman(paramNames); @@ -669,7 +688,7 @@ bool HelpGenApp::OnInit() docman.DumpDifferences(ctxTop); } - return false; + return 0; } // ----------------------------------------------------------------------------- @@ -693,8 +712,10 @@ void HelpGenVisitor::Reset() m_inMethodSection = FALSE; m_textStoredTypedefs = - m_textStoredEnums = m_textStoredFunctionComment = ""; + + m_storedEnums.Empty(); + m_storedEnumsVerb.Empty(); m_headers.Empty(); } @@ -706,8 +727,15 @@ void HelpGenVisitor::InsertTypedefDocs() void HelpGenVisitor::InsertEnumDocs() { - m_file.WriteTeX(m_textStoredEnums); - m_textStoredEnums.Empty(); + size_t count = m_storedEnums.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + m_file.WriteTeX(m_storedEnums[n]); + m_file.WriteVerbatim(m_storedEnumsVerb[n] + '\n'); + } + + m_storedEnums.Empty(); + m_storedEnumsVerb.Empty(); } void HelpGenVisitor::InsertDataStructuresHeader() @@ -715,7 +743,7 @@ void HelpGenVisitor::InsertDataStructuresHeader() if ( !m_inTypesSection ) { m_inTypesSection = TRUE; - m_file.WriteTeX("\\wxheading{Data structures}\n\n"); + m_file.Write("\\wxheading{Data structures}\n\n"); } } @@ -724,7 +752,7 @@ void HelpGenVisitor::InsertMethodsHeader() if ( !m_inMethodSection ) { m_inMethodSection = TRUE; - m_file.WriteTeX( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n"); + m_file.Write( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n"); } } @@ -740,11 +768,10 @@ void HelpGenVisitor::CloseFunction() } totalText << "}\n\n"; + m_file.Write(totalText); if ( !m_textStoredFunctionComment.IsEmpty() ) - totalText << m_textStoredFunctionComment << '\n'; - - m_file.WriteTeX(totalText); + m_file.WriteTeX(m_textStoredFunctionComment + '\n'); } } @@ -779,7 +806,7 @@ void HelpGenVisitor::VisitClass( spClass& cl ) // the file name is built from the class name by removing the leading "wx" // if any and converting it to the lower case - wxString filename = m_directoryOut; + wxString filename; if ( name(0, 2) == "wx" ) { filename << name.c_str() + 2; } @@ -789,6 +816,7 @@ void HelpGenVisitor::VisitClass( spClass& cl ) filename.MakeLower(); filename += ".tex"; + filename.Prepend(m_directoryOut); if ( !m_overwrite && wxFile::Exists(filename) ) { wxLogError("Won't overwrite existing file '%s' - please use '-f'.", @@ -811,25 +839,26 @@ void HelpGenVisitor::VisitClass( spClass& cl ) wxLogInfo("Created new file '%s' for class '%s'.", filename.c_str(), name.c_str()); + // write out the header + wxString header; + header.Printf("%%\n" + "%% automatically generated by HelpGen %s from\n" + "%% %s at %s\n" + "%%\n" + "\n" + "\n" + "\\section{\\class{%s}}\\label{%s}\n\n", + GetVersionString().c_str(), + m_fileHeader.c_str(), + GetCurrentTime("%d/%b/%y %H:%M:%S"), + name.c_str(), + wxString(name).MakeLower().c_str()); + + m_file.Write(header); + // the entire text we're writing to file wxString totalText; - // write out the header - { - wxString header; - header.Printf("%%\n" - "%% automatically generated by HelpGen from\n" - "%% %s at %s\n" - "%%\n" - "\n" - "\n" - "\\section{\\class{%s}}\\label{%s}\n", - m_fileHeader.c_str(), GetCurrentTime("%d/%b/%y %H:%M:%S"), - name.c_str(), wxString(name).MakeLower().c_str()); - - totalText << header << '\n'; - } - // if the header includes other headers they must be related to it... try to // automatically generate the "See also" clause if ( !m_headers.IsEmpty() ) { @@ -951,25 +980,25 @@ void HelpGenVisitor::VisitEnumeration( spEnumeration& en ) } // simply copy the enum text in the docs - wxString enumeration = GetAllComments(en); - enumeration << "{\\small \\begin{verbatim}\n" - << en.mEnumContent - << "\n\\end{verbatim}}\n"; + wxString enumeration = GetAllComments(en), + enumerationVerb; + + enumerationVerb << "\\begin{verbatim}\n" + << en.mEnumContent + << "\n\\end{verbatim}\n"; // remember for later use if we're not inside a class yet if ( !m_inClass ) { - if ( !m_textStoredEnums.IsEmpty() ) { - m_textStoredEnums << '\n'; - } - - m_textStoredEnums << enumeration; + m_storedEnums.Add(enumeration); + m_storedEnumsVerb.Add(enumerationVerb); } else { // write the header for this section if not done yet InsertDataStructuresHeader(); - enumeration << '\n'; m_file.WriteTeX(enumeration); + m_file.WriteVerbatim(enumerationVerb); + m_file.Write('\n'); } } @@ -1875,21 +1904,33 @@ static wxString MakeHelpref(const char *argument) return helpref; } +static void TeXFilter(wxString* str) +{ + // TeX special which can be quoted (don't include backslash nor braces as + // we generate them + static wxRegEx reNonSpecialSpecials("[#$%&_]"), + reAccents("[~^]"); + + // just quote + reNonSpecialSpecials.ReplaceAll(str, "\\\\\\0"); + + // can't quote these ones as they produce accents when preceded by + // backslash, so put them inside verb + reAccents.ReplaceAll(str, "\\\\verb|\\0|"); +} + static void TeXUnfilter(wxString* str) { // FIXME may be done much more quickly str->Trim(TRUE); str->Trim(FALSE); - str->Replace("\\&", "&"); - str->Replace("\\_", "_"); -} + // undo TeXFilter + static wxRegEx reNonSpecialSpecials("\\\\([#$%&_{}])"), + reAccents("\\\\verb|([~^])|"); -static void TeXFilter(wxString* str) -{ - // FIXME may be done much more quickly - str->Replace("&", "\\&"); - str->Replace("_", "\\_"); + reNonSpecialSpecials.ReplaceAll(str, "\\1"); + reAccents.ReplaceAll(str, "\\1"); } static wxString GetAllComments(const spContext& ctx) @@ -1927,9 +1968,40 @@ static const char *GetCurrentTime(const char *timeFormat) return s_timeBuffer; } +static const wxString GetVersionString() +{ + wxString version = "$Revision$"; + wxRegEx("^\\$Revision$$").ReplaceFirst(&version, "\\1"); + return version; +} + /* $Log$ + Revision 1.14 2001/07/19 13:51:29 VZ + fixes to version string + + Revision 1.13 2001/07/19 13:44:57 VZ + 1. compilation fixes + 2. don't quote special characters inside verbatim environment + + Revision 1.12 2000/10/09 13:53:33 juliansmart + + Doc corrections; added HelpGen project files + + Revision 1.11 2000/07/15 19:50:42 cvsuser + merged 2.2 branch + + Revision 1.10.2.2 2000/03/27 15:33:10 VZ + don't trasnform output dir name to lower case + + Revision 1.10 2000/03/11 10:05:23 VS + now compiles with wxBase + + Revision 1.9 2000/01/16 13:25:21 VS + compilation fixes (gcc) + Revision 1.8 1999/09/13 14:29:39 JS + Made HelpGen into a wxWin app (still uses command-line args); moved includes into src for simplicity; added VC++ 5 project file