#include <wx/string.h>
#include <wx/log.h>
#include <wx/dynarray.h>
+ #include <wx/wx.h>
#endif // WX_PRECOMP
#include <wx/file.h>
+#include <wx/regex.h>
// C++ parsing classes
#include "cjparser.h"
#include <stdio.h>
#include <time.h>
+// 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);
// 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
// -----------------------------------------------------------------------------
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);
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;
// 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> [mode options] <files...>\n"
"\n"
" where global options are:\n"
exit(1);
}
-/*
-int main(int argc, char **argv)
-{
-*/
-
-bool HelpGenApp::OnInit()
+int HelpGenApp::OnRun()
{
enum
{
Mode_Diff
} mode = Mode_None;
- g_argv = argv;
-
if ( argc < 2 ) {
usage();
}
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++;
wxLogError("Can't complete diff.");
// failure
- return false;
+ return FALSE;
}
DocManager docman(paramNames);
docman.DumpDifferences(ctxTop);
}
- return false;
+ return 0;
}
// -----------------------------------------------------------------------------
m_inMethodSection = FALSE;
m_textStoredTypedefs =
- m_textStoredEnums =
m_textStoredFunctionComment = "";
+
+ m_storedEnums.Empty();
+ m_storedEnumsVerb.Empty();
m_headers.Empty();
}
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()
if ( !m_inTypesSection ) {
m_inTypesSection = TRUE;
- m_file.WriteTeX("\\wxheading{Data structures}\n\n");
+ m_file.Write("\\wxheading{Data structures}\n\n");
}
}
if ( !m_inMethodSection ) {
m_inMethodSection = TRUE;
- m_file.WriteTeX( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n");
+ m_file.Write( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n");
}
}
}
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');
}
}
// 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;
}
filename.MakeLower();
filename += ".tex";
+ filename.Prepend(m_directoryOut);
if ( !m_overwrite && wxFile::Exists(filename) ) {
wxLogError("Won't overwrite existing file '%s' - please use '-f'.",
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() ) {
}
// 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');
}
}
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)
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