1. compilation fixes

2. don't quote special characters inside verbatim environment


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11102 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-07-19 13:44:57 +00:00
parent dee5b92f9c
commit a7adaedae8
3 changed files with 118 additions and 75 deletions

View File

@@ -54,6 +54,7 @@
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include <wx/string.h> #include <wx/string.h>
#include <wx/log.h> #include <wx/log.h>
#include <wx/regex.h>
#include <wx/dynarray.h> #include <wx/dynarray.h>
#include <wx/wx.h> #include <wx/wx.h>
#endif // WX_PRECOMP #endif // WX_PRECOMP
@@ -67,23 +68,30 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
// argh, Windows defines this
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
#define VERSION_STRING "$Revision$"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// global vars // global vars
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// just a copy of argv
static char **g_argv = NULL;
class HelpGenApp: public wxApp class HelpGenApp: public wxApp
{ {
public: public:
HelpGenApp() {}; HelpGenApp() {};
#if wxUSE_GUI // don't let wxWin parse our cmd line, we do it ourselves
bool OnInit(); virtual bool OnInit() { return TRUE; }
#else
int OnRun(); virtual int OnRun();
#endif
}; };
IMPLEMENT_APP(HelpGenApp); IMPLEMENT_APP(HelpGenApp);
@@ -107,10 +115,6 @@ static wxString GetAllComments(const spContext& ctx);
// get the string with current time (returns pointer to static buffer) // get the string with current time (returns pointer to static buffer)
// timeFormat is used for the call of strftime(3) // timeFormat is used for the call of strftime(3)
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
static const char *GetCurrentTime(const char *timeFormat); static const char *GetCurrentTime(const char *timeFormat);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -123,6 +127,14 @@ class wxTeXFile : public wxFile
public: public:
wxTeXFile() { } 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) bool WriteTeX(const wxString& s)
{ {
wxString t(s); wxString t(s);
@@ -247,10 +259,14 @@ protected:
m_inFunction; // we're parsing a function declaration m_inFunction; // we're parsing a function declaration
// holders for "saved" documentation // holders for "saved" documentation
wxString m_textStoredEnums, wxString m_textStoredTypedefs,
m_textStoredTypedefs,
m_textStoredFunctionComment; 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 // headers included by this file
wxArrayString m_headers; wxArrayString m_headers;
@@ -435,7 +451,7 @@ private:
// this function never returns // this function never returns
static void usage() static void usage()
{ {
wxString prog = g_argv[0]; wxString prog = wxTheApp->argv[0];
wxString basename = prog.AfterLast('/'); wxString basename = prog.AfterLast('/');
#ifdef __WXMSW__ #ifdef __WXMSW__
if ( !basename ) if ( !basename )
@@ -444,7 +460,7 @@ static void usage()
if ( !basename ) if ( !basename )
basename = prog; basename = prog;
wxLogError( wxLogMessage(
"usage: %s [global options] <mode> [mode options] <files...>\n" "usage: %s [global options] <mode> [mode options] <files...>\n"
"\n" "\n"
" where global options are:\n" " where global options are:\n"
@@ -467,21 +483,11 @@ static void usage()
" mode specific options are:\n" " mode specific options are:\n"
" -p do check parameter names (not done by default)\n" " -p do check parameter names (not done by default)\n"
"\n", basename.c_str(), basename.c_str()); "\n", basename.c_str(), basename.c_str());
#ifndef wxUSE_GUI
exit(1); exit(1);
#endif
} }
/*
int main(int argc, char **argv)
{
*/
#if wxUSE_GUI
bool HelpGenApp::OnInit()
#else
int HelpGenApp::OnRun() int HelpGenApp::OnRun()
#endif
{ {
enum enum
{ {
@@ -490,8 +496,6 @@ int HelpGenApp::OnRun()
Mode_Diff Mode_Diff
} mode = Mode_None; } mode = Mode_None;
g_argv = argv;
if ( argc < 2 ) { if ( argc < 2 ) {
usage(); usage();
} }
@@ -520,6 +524,14 @@ int HelpGenApp::OnRun()
case 'H': case 'H':
// help requested // help requested
usage(); usage();
// doesn't return
case 'V':
// version requested
wxLogMessage("HelpGen version %s\n"
"(c) 1999-2001 Vadim Zeitlin\n",
VERSION_STRING);
return 0;
case 'i': case 'i':
current++; current++;
@@ -659,7 +671,7 @@ int HelpGenApp::OnRun()
wxLogError("Can't complete diff."); wxLogError("Can't complete diff.");
// failure // failure
return false; return FALSE;
} }
DocManager docman(paramNames); DocManager docman(paramNames);
@@ -679,7 +691,7 @@ int HelpGenApp::OnRun()
docman.DumpDifferences(ctxTop); docman.DumpDifferences(ctxTop);
} }
return false; return 0;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -703,8 +715,10 @@ void HelpGenVisitor::Reset()
m_inMethodSection = FALSE; m_inMethodSection = FALSE;
m_textStoredTypedefs = m_textStoredTypedefs =
m_textStoredEnums =
m_textStoredFunctionComment = ""; m_textStoredFunctionComment = "";
m_storedEnums.Empty();
m_storedEnumsVerb.Empty();
m_headers.Empty(); m_headers.Empty();
} }
@@ -716,8 +730,15 @@ void HelpGenVisitor::InsertTypedefDocs()
void HelpGenVisitor::InsertEnumDocs() void HelpGenVisitor::InsertEnumDocs()
{ {
m_file.WriteTeX(m_textStoredEnums); size_t count = m_storedEnums.GetCount();
m_textStoredEnums.Empty(); 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() void HelpGenVisitor::InsertDataStructuresHeader()
@@ -725,7 +746,7 @@ void HelpGenVisitor::InsertDataStructuresHeader()
if ( !m_inTypesSection ) { if ( !m_inTypesSection ) {
m_inTypesSection = TRUE; m_inTypesSection = TRUE;
m_file.WriteTeX("\\wxheading{Data structures}\n\n"); m_file.Write("\\wxheading{Data structures}\n\n");
} }
} }
@@ -734,7 +755,7 @@ void HelpGenVisitor::InsertMethodsHeader()
if ( !m_inMethodSection ) { if ( !m_inMethodSection ) {
m_inMethodSection = TRUE; m_inMethodSection = TRUE;
m_file.WriteTeX( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n"); m_file.Write( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n");
} }
} }
@@ -750,11 +771,10 @@ void HelpGenVisitor::CloseFunction()
} }
totalText << "}\n\n"; totalText << "}\n\n";
m_file.Write(totalText);
if ( !m_textStoredFunctionComment.IsEmpty() ) if ( !m_textStoredFunctionComment.IsEmpty() )
totalText << m_textStoredFunctionComment << '\n'; m_file.WriteTeX(m_textStoredFunctionComment + '\n');
m_file.WriteTeX(totalText);
} }
} }
@@ -822,25 +842,26 @@ void HelpGenVisitor::VisitClass( spClass& cl )
wxLogInfo("Created new file '%s' for class '%s'.", wxLogInfo("Created new file '%s' for class '%s'.",
filename.c_str(), name.c_str()); 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",
VERSION_STRING,
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 // the entire text we're writing to file
wxString totalText; 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 // if the header includes other headers they must be related to it... try to
// automatically generate the "See also" clause // automatically generate the "See also" clause
if ( !m_headers.IsEmpty() ) { if ( !m_headers.IsEmpty() ) {
@@ -962,25 +983,25 @@ void HelpGenVisitor::VisitEnumeration( spEnumeration& en )
} }
// simply copy the enum text in the docs // simply copy the enum text in the docs
wxString enumeration = GetAllComments(en); wxString enumeration = GetAllComments(en),
enumeration << "{\\small \\begin{verbatim}\n" enumerationVerb;
<< en.mEnumContent
<< "\n\\end{verbatim}}\n"; enumerationVerb << "\\begin{verbatim}\n"
<< en.mEnumContent
<< "\n\\end{verbatim}\n";
// remember for later use if we're not inside a class yet // remember for later use if we're not inside a class yet
if ( !m_inClass ) { if ( !m_inClass ) {
if ( !m_textStoredEnums.IsEmpty() ) { m_storedEnums.Add(enumeration);
m_textStoredEnums << '\n'; m_storedEnumsVerb.Add(enumerationVerb);
}
m_textStoredEnums << enumeration;
} }
else { else {
// write the header for this section if not done yet // write the header for this section if not done yet
InsertDataStructuresHeader(); InsertDataStructuresHeader();
enumeration << '\n';
m_file.WriteTeX(enumeration); m_file.WriteTeX(enumeration);
m_file.WriteVerbatim(enumerationVerb);
m_file.Write('\n');
} }
} }
@@ -1886,21 +1907,33 @@ static wxString MakeHelpref(const char *argument)
return helpref; 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) static void TeXUnfilter(wxString* str)
{ {
// FIXME may be done much more quickly // FIXME may be done much more quickly
str->Trim(TRUE); str->Trim(TRUE);
str->Trim(FALSE); str->Trim(FALSE);
str->Replace("\\&", "&"); // undo TeXFilter
str->Replace("\\_", "_"); static wxRegEx reNonSpecialSpecials("\\\\([#$%&_{}])"),
} reAccents("\\\\verb|([~^])|");
static void TeXFilter(wxString* str) reNonSpecialSpecials.ReplaceAll(str, "\\1");
{ reAccents.ReplaceAll(str, "\\1");
// FIXME may be done much more quickly
str->Replace("&", "\\&");
str->Replace("_", "\\_");
} }
static wxString GetAllComments(const spContext& ctx) static wxString GetAllComments(const spContext& ctx)
@@ -1940,7 +1973,12 @@ static const char *GetCurrentTime(const char *timeFormat)
/* /*
$Log$ $Log$
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 Revision 1.12 2000/10/09 13:53:33 juliansmart
Doc corrections; added HelpGen project files Doc corrections; added HelpGen project files
Revision 1.11 2000/07/15 19:50:42 cvsuser Revision 1.11 2000/07/15 19:50:42 cvsuser

View File

@@ -15,11 +15,16 @@
#include "srcparser.h" #include "srcparser.h"
#include "wx/ioswrap.h"
#include <memory.h> #include <memory.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#if wxUSE_IOSTREAMH
#include <iostream.h>
#else
#include <iostream>
#endif
// class parses given "memory-resident" Java or C++ source code // class parses given "memory-resident" Java or C++ source code
// and captures information about classes/attrubutes/methods/ // and captures information about classes/attrubutes/methods/
// arguments/etc into structures. Conforms with SourceParserBase // arguments/etc into structures. Conforms with SourceParserBase

View File

@@ -403,9 +403,9 @@ void check_keyword_map( int keywordMapNr )
// "make sure" the address of the first member of non-polimorphic class // "make sure" the address of the first member of non-polimorphic class
// coinsides with the address of the instance // coinsides with the address of the instance
/*
KeywordT dummy; KeywordT dummy;
/*
if ( (char*)& dummy != &dummy.keyWord[0] ) if ( (char*)& dummy != &dummy.keyWord[0] )
throw; throw;
*/ */