1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Main program file for HelpGen
4 // Author: Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Copyright: (c) 1999 VZ
10 /////////////////////////////////////////////////////////////////////////////
15 1. wx/string.h confuses C++ parser terribly
16 2. C++ parser doesn't know about virtual functions, nor static ones
17 3. param checking is not done for vararg functions
18 4. type comparison is dumb: it doesn't know that "char *" is the same
19 that "char []" nor that "const char *" is the same as "char const *"
21 TODO (+ means fixed), see also the change log at the end of the file.
23 (i) small fixes in the current version
25 +1. Quote special TeX characters like '&' and '_' (=> derive from wxFile)
27 3. Document global variables
30 6. Include file name/line number in the "diff" messages?
31 +7. Support for vararg functions
33 (ii) plans for version 2
34 1. Use wxTextFile for direct file access to avoid one scan method problems
35 2. Use command line parser class for the options
36 3. support for overloaded functions in diff mode (search for OVER)
38 (iii) plans for version 3
39 1. Merging with existing files
43 // =============================================================================
45 // =============================================================================
47 // -----------------------------------------------------------------------------
49 // -----------------------------------------------------------------------------
52 #include "wx/wxprec.h"
55 #error "This is a console program and can be only compiled using wxBase"
59 #include "wx/string.h"
61 #include "wx/dynarray.h"
69 // C++ parsing classes
76 // argh, Windows defines this
81 // -----------------------------------------------------------------------------
83 // -----------------------------------------------------------------------------
85 class HelpGenApp
: public wxApp
90 // don't let wxWin parse our cmd line, we do it ourselves
91 virtual bool OnInit() { return TRUE
; }
96 // IMPLEMENT_APP(HelpGenApp);
98 // -----------------------------------------------------------------------------
100 // -----------------------------------------------------------------------------
102 // return the label for the given function name (i.e. argument of \label)
103 static wxString
MakeLabel(const char *classname
, const char *funcname
= NULL
);
105 // return the whole \helpref{arg}{arg_label} string
106 static wxString
MakeHelpref(const char *argument
);
108 // [un]quote special TeX characters (in place)
109 static void TeXFilter(wxString
* str
);
110 static void TeXUnfilter(wxString
* str
); // also trims spaces
112 // get all comments associated with this context
113 static wxString
GetAllComments(const spContext
& ctx
);
115 // get the string with current time (returns pointer to static buffer)
116 // timeFormat is used for the call of strftime(3)
117 static const char *GetCurrentTime(const char *timeFormat
);
119 // get the string containing the program version
120 static const wxString
GetVersionString();
122 // -----------------------------------------------------------------------------
124 // -----------------------------------------------------------------------------
126 // a function documentation entry
127 struct FunctionDocEntry
129 FunctionDocEntry(const wxString
& name_
, const wxString
& text_
)
130 : name(name_
), text(text_
) { }
135 // the function doc text
139 static int Compare(FunctionDocEntry
**pp1
, FunctionDocEntry
**pp2
)
141 // the methods should appear in the following order: ctors, dtor, all
142 // the rest in the alphabetical order
143 bool isCtor1
= (*pp1
)->name
== classname
;
144 bool isCtor2
= (*pp2
)->name
== classname
;
148 // we don't order the ctors because we don't know how to do it
152 // ctor comes before non-ctor
157 // non-ctor must come after ctor
161 wxString dtorname
= wxString('~') + classname
;
163 // there is only one dtor, so the logic here is simpler
164 if ( (*pp1
)->name
== dtorname
) {
167 else if ( (*pp2
)->name
== dtorname
) {
171 // two normal methods
172 return strcmp((*pp1
)->name
, (*pp2
)->name
);
176 static wxString classname
;
179 wxString
FunctionDocEntry::classname
;
181 WX_DECLARE_OBJARRAY(FunctionDocEntry
, FunctionDocEntries
);
183 #include "wx/arrimpl.cpp"
185 WX_DEFINE_OBJARRAY(FunctionDocEntries
);
187 // add a function which sanitazes the string before writing it to the file and
188 // also capable of delaying output and sorting it before really writing it to
189 // the file (done from FlushAll())
190 class wxTeXFile
: public wxFile
195 // write a string to file verbatim (should only be used for the strings
196 // inside verbatim environment)
197 void WriteVerbatim(const wxString
& s
)
202 // write a string quoting TeX specials in it
203 void WriteTeX(const wxString
& s
)
211 // do write everything to file
214 if ( m_text
.empty() )
217 if ( !Write(m_text
) ) {
218 wxLogError("Failed to output generated documentation.");
229 wxTeXFile(const wxTeXFile
&);
230 wxTeXFile
& operator=(const wxTeXFile
&);
235 // helper class which manages the classes and function names to ignore for
236 // the documentation purposes (used by both HelpGenVisitor and DocManager)
237 class IgnoreNamesHandler
240 IgnoreNamesHandler() : m_ignore(CompareIgnoreListEntries
) { }
241 ~IgnoreNamesHandler() { WX_CLEAR_ARRAY(m_ignore
); }
243 // load file with classes/functions to ignore (add them to the names we
245 bool AddNamesFromFile(const wxString
& filename
);
247 // return TRUE if we ignore this function
248 bool IgnoreMethod(const wxString
& classname
,
249 const wxString
& funcname
) const
251 if ( IgnoreClass(classname
) )
254 IgnoreListEntry
ignore(classname
, funcname
);
256 return m_ignore
.Index(&ignore
) != wxNOT_FOUND
;
259 // return TRUE if we ignore this class entirely
260 bool IgnoreClass(const wxString
& classname
) const
262 IgnoreListEntry
ignore(classname
, "");
264 return m_ignore
.Index(&ignore
) != wxNOT_FOUND
;
268 struct IgnoreListEntry
270 IgnoreListEntry(const wxString
& classname
,
271 const wxString
& funcname
)
272 : m_classname(classname
), m_funcname(funcname
)
276 wxString m_classname
;
277 wxString m_funcname
; // if empty, ignore class entirely
280 static int CompareIgnoreListEntries(IgnoreListEntry
*first
,
281 IgnoreListEntry
*second
);
283 // for efficiency, let's sort it
284 WX_DEFINE_SORTED_ARRAY(IgnoreListEntry
*, ArrayNamesToIgnore
);
286 ArrayNamesToIgnore m_ignore
;
289 IgnoreNamesHandler(const IgnoreNamesHandler
&);
290 IgnoreNamesHandler
& operator=(const IgnoreNamesHandler
&);
293 // visitor implementation which writes all collected data to a .tex file
294 class HelpGenVisitor
: public spVisitor
298 HelpGenVisitor(const wxString
& directoryOut
, bool overwrite
);
300 virtual void VisitFile( spFile
& fl
);
301 virtual void VisitClass( spClass
& cl
);
302 virtual void VisitEnumeration( spEnumeration
& en
);
303 virtual void VisitTypeDef( spTypeDef
& td
);
304 virtual void VisitPreprocessorLine( spPreprocessorLine
& pd
);
305 virtual void VisitAttribute( spAttribute
& attr
);
306 virtual void VisitOperation( spOperation
& op
);
307 virtual void VisitParameter( spParameter
& param
);
311 // get our `ignore' object
312 IgnoreNamesHandler
& GetIgnoreHandler() { return m_ignoreNames
; }
314 // shut up g++ warning (ain't it stupid?)
315 virtual ~HelpGenVisitor() { }
318 // (re)initialize the state
321 // insert documentation for enums/typedefs coming immediately before the
322 // class declaration into the class documentation
323 void InsertTypedefDocs();
324 void InsertEnumDocs();
326 // write the headers for corresponding sections (only once)
327 void InsertDataStructuresHeader();
328 void InsertMethodsHeader();
330 // terminate the function documentation if it was started
331 void CloseFunction();
333 // write out all function docs when there are no more left in this class
334 // after sorting them in alphabetical order
337 wxString m_directoryOut
, // directory for the output
338 m_fileHeader
; // name of the .h file we parse
339 bool m_overwrite
; // overwrite existing files?
340 wxTeXFile m_file
; // file we're writing to now
343 bool m_inClass
, // TRUE after file successfully opened
344 m_inTypesSection
, // enums & typedefs go there
345 m_inMethodSection
, // functions go here
346 m_isFirstParam
; // first parameter of current function?
348 // non empty while parsing a class
349 wxString m_classname
;
351 // these are only non-empty while parsing a method:
352 wxString m_funcName
, // the function name
353 m_textFunc
; // the function doc text
355 // the array containing the documentation entries for the functions in the
356 // class currently being parsed
357 FunctionDocEntries m_arrayFuncDocs
;
359 // holders for "saved" documentation
360 wxString m_textStoredTypedefs
,
361 m_textStoredFunctionComment
;
363 // for enums we have to use an array as we can't intermix the normal text
364 // and the text inside verbatim environment
365 wxArrayString m_storedEnums
,
368 // headers included by this file
369 wxArrayString m_headers
;
371 // ignore handler: tells us which classes to ignore for doc generation
373 IgnoreNamesHandler m_ignoreNames
;
376 HelpGenVisitor(const HelpGenVisitor
&);
377 HelpGenVisitor
& operator=(const HelpGenVisitor
&);
380 // documentation manager - a class which parses TeX files and remembers the
381 // functions documented in them and can later compare them with all functions
382 // found under ctxTop by C++ parser
386 DocManager(bool checkParamNames
);
389 // returns FALSE on failure
390 bool ParseTeXFile(const wxString
& filename
);
392 // returns FALSE if there were any differences
393 bool DumpDifferences(spContext
*ctxTop
) const;
395 // get our `ignore' object
396 IgnoreNamesHandler
& GetIgnoreHandler() { return m_ignoreNames
; }
402 // returns the length of 'match' if the string 'str' starts with it or 0
404 static size_t TryMatch(const char *str
, const char *match
);
406 // skip spaces: returns pointer to first non space character (also
407 // updates the value of m_line)
408 const char *SkipSpaces(const char *p
)
410 while ( isspace(*p
) ) {
418 // skips characters until the next 'c' in '*pp' unless it ends before in
419 // which case FALSE is returned and pp points to '\0', otherwise TRUE is
420 // returned and pp points to 'c'
421 bool SkipUntil(const char **pp
, char c
);
423 // the same as SkipUntil() but only spaces are skipped: on first non space
424 // character different from 'c' the function stops and returns FALSE
425 bool SkipSpaceUntil(const char **pp
, char c
);
427 // extract the string between {} and modify '*pp' to point at the
428 // character immediately after the closing '}'. The returned string is empty
430 wxString
ExtractStringBetweenBraces(const char **pp
);
432 // the current file and line while we're in ParseTeXFile (for error
437 // functions and classes to ignore during diff
438 // -------------------------------------------
440 IgnoreNamesHandler m_ignoreNames
;
442 // information about all functions documented in the TeX file(s)
443 // -------------------------------------------------------------
445 // info about a type: for now stored as text string, but must be parsed
446 // further later (to know that "char *" == "char []" - TODO)
450 TypeInfo(const wxString
& type
) : m_type(type
) { }
452 bool operator==(const wxString
& type
) const { return m_type
== type
; }
453 bool operator!=(const wxString
& type
) const { return m_type
!= type
; }
455 const wxString
& GetName() const { return m_type
; }
461 // info abotu a function parameter
465 ParamInfo(const wxString
& type
,
466 const wxString
& name
,
467 const wxString
& value
)
468 : m_type(type
), m_name(name
), m_value(value
)
472 const TypeInfo
& GetType() const { return m_type
; }
473 const wxString
& GetName() const { return m_name
; }
474 const wxString
& GetDefValue() const { return m_value
; }
477 TypeInfo m_type
; // type of parameter
478 wxString m_name
; // name
479 wxString m_value
; // default value
482 WX_DEFINE_ARRAY(ParamInfo
*, ArrayParamInfo
);
484 // info about a function
497 MethodInfo(const wxString
& type
,
498 const wxString
& name
,
499 const ArrayParamInfo
& params
)
500 : m_typeRet(type
), m_name(name
), m_params(params
)
505 void SetFlag(MethodFlags flag
) { m_flags
|= flag
; }
507 const TypeInfo
& GetType() const { return m_typeRet
; }
508 const wxString
& GetName() const { return m_name
; }
509 const ParamInfo
& GetParam(size_t n
) const { return *(m_params
[n
]); }
510 size_t GetParamCount() const { return m_params
.GetCount(); }
512 bool HasFlag(MethodFlags flag
) const { return (m_flags
& flag
) != 0; }
514 ~MethodInfo() { WX_CLEAR_ARRAY(m_params
); }
517 TypeInfo m_typeRet
; // return type
519 int m_flags
; // bit mask of the value from the enum above
521 ArrayParamInfo m_params
;
524 WX_DEFINE_ARRAY(MethodInfo
*, ArrayMethodInfo
);
525 WX_DEFINE_ARRAY(ArrayMethodInfo
*, ArrayMethodInfos
);
527 // first array contains the names of all classes we found, the second has a
528 // pointer to the array of methods of the given class at the same index as
529 // the class name appears in m_classes
530 wxArrayString m_classes
;
531 ArrayMethodInfos m_methods
;
533 // are we checking parameter names?
534 bool m_checkParamNames
;
537 DocManager(const DocManager
&);
538 DocManager
& operator=(const DocManager
&);
541 // =============================================================================
543 // =============================================================================
545 // this function never returns
548 wxString prog
= wxTheApp
->argv
[0];
549 wxString basename
= prog
.AfterLast('/');
552 basename
= prog
.AfterLast('\\');
558 "usage: %s [global options] <mode> [mode options] <files...>\n"
560 " where global options are:\n"
563 " -H give this usage message\n"
564 " -V print the version info\n"
565 " -i file file with classes/function to ignore\n"
567 " where mode is one of: dump, diff\n"
569 " dump means generate .tex files for TeX2RTF converter from specified\n"
570 " headers files, mode options are:\n"
571 " -f overwrite existing files\n"
572 " -o outdir directory for generated files\n"
574 " diff means compare the set of methods documented .tex file with the\n"
575 " methods declared in the header:\n"
576 " %s diff <file.h> <files.tex...>.\n"
577 " mode specific options are:\n"
578 " -p do check parameter names (not done by default)\n"
579 "\n", basename
.c_str(), basename
.c_str());
584 int HelpGenApp::OnRun()
597 wxArrayString filesH
, filesTeX
;
598 wxString directoryOut
, // directory for 'dmup' output
599 ignoreFile
; // file with classes/functions to ignore
600 bool overwrite
= FALSE
, // overwrite existing files during 'dump'?
601 paramNames
= FALSE
; // check param names during 'diff'?
603 for ( int current
= 1; current
< argc
; current
++ ) {
604 // all options have one letter
605 if ( argv
[current
][0] == '-' ) {
606 if ( argv
[current
][2] == '\0' ) {
607 switch ( argv
[current
][1] ) {
610 wxLog::GetActiveTarget()->SetVerbose();
615 wxLog::GetActiveTarget()->SetVerbose(FALSE
);
625 wxLogMessage("HelpGen version %s\n"
626 "(c) 1999-2001 Vadim Zeitlin\n",
627 GetVersionString().c_str());
632 if ( current
>= argc
) {
633 wxLogError("-i option requires an argument.");
638 ignoreFile
= argv
[current
];
642 if ( mode
!= Mode_Diff
) {
643 wxLogError("-p is only valid with diff.");
652 if ( mode
!= Mode_Dump
) {
653 wxLogError("-f is only valid with dump.");
662 if ( mode
!= Mode_Dump
) {
663 wxLogError("-o is only valid with dump.");
669 if ( current
>= argc
) {
670 wxLogError("-o option requires an argument.");
675 directoryOut
= argv
[current
];
676 if ( !!directoryOut
) {
677 // terminate with a '/' if it doesn't have it
678 switch ( directoryOut
.Last() ) {
689 //else: it's empty, do nothing
694 wxLogError("unknown option '%s'", argv
[current
]);
699 wxLogError("only one letter options are allowed, not '%s'.",
703 // only get here after a break from switch or from else branch of if
708 if ( mode
== Mode_None
) {
709 if ( strcmp(argv
[current
], "diff") == 0 )
711 else if ( strcmp(argv
[current
], "dump") == 0 )
714 wxLogError("unknown mode '%s'.", argv
[current
]);
720 if ( mode
== Mode_Dump
|| filesH
.IsEmpty() ) {
721 filesH
.Add(argv
[current
]);
724 // 2nd files and further are TeX files in diff mode
725 wxASSERT( mode
== Mode_Diff
);
727 filesTeX
.Add(argv
[current
]);
733 // create a parser object and a visitor derivation
734 CJSourceParser parser
;
735 HelpGenVisitor
visitor(directoryOut
, overwrite
);
736 if ( !!ignoreFile
&& mode
== Mode_Dump
)
737 visitor
.GetIgnoreHandler().AddNamesFromFile(ignoreFile
);
739 spContext
*ctxTop
= NULL
;
741 // parse all header files
742 size_t nFiles
= filesH
.GetCount();
743 for ( size_t n
= 0; n
< nFiles
; n
++ ) {
744 wxString header
= filesH
[n
];
745 ctxTop
= parser
.ParseFile(header
);
747 wxLogWarning("Header file '%s' couldn't be processed.",
750 else if ( mode
== Mode_Dump
) {
751 ((spFile
*)ctxTop
)->mFileName
= header
;
752 visitor
.VisitAll(*ctxTop
);
759 #endif // __WXDEBUG__
762 // parse all TeX files
763 if ( mode
== Mode_Diff
) {
765 wxLogError("Can't complete diff.");
771 DocManager
docman(paramNames
);
773 size_t nFiles
= filesTeX
.GetCount();
774 for ( size_t n
= 0; n
< nFiles
; n
++ ) {
775 wxString file
= filesTeX
[n
];
776 if ( !docman
.ParseTeXFile(file
) ) {
777 wxLogWarning("TeX file '%s' couldn't be processed.",
783 docman
.GetIgnoreHandler().AddNamesFromFile(ignoreFile
);
785 docman
.DumpDifferences(ctxTop
);
791 int main(int argc
, char **argv
)
793 wxInitializer initializer
;
796 fprintf(stderr
, "Failed to initialize the wxWindows library, aborting.");
806 // -----------------------------------------------------------------------------
807 // HelpGenVisitor implementation
808 // -----------------------------------------------------------------------------
810 HelpGenVisitor::HelpGenVisitor(const wxString
& directoryOut
,
812 : m_directoryOut(directoryOut
)
814 m_overwrite
= overwrite
;
819 void HelpGenVisitor::Reset()
823 m_inMethodSection
= FALSE
;
828 m_textStoredTypedefs
=
829 m_textStoredFunctionComment
= "";
831 m_arrayFuncDocs
.Empty();
833 m_storedEnums
.Empty();
834 m_storedEnumsVerb
.Empty();
838 void HelpGenVisitor::InsertTypedefDocs()
840 m_file
.WriteTeX(m_textStoredTypedefs
);
841 m_textStoredTypedefs
.Empty();
844 void HelpGenVisitor::InsertEnumDocs()
846 size_t count
= m_storedEnums
.GetCount();
847 for ( size_t n
= 0; n
< count
; n
++ )
849 m_file
.WriteTeX(m_storedEnums
[n
]);
850 m_file
.WriteVerbatim(m_storedEnumsVerb
[n
] + '\n');
853 m_storedEnums
.Empty();
854 m_storedEnumsVerb
.Empty();
857 void HelpGenVisitor::InsertDataStructuresHeader()
859 if ( !m_inTypesSection
) {
860 m_inTypesSection
= TRUE
;
862 m_file
.WriteVerbatim("\\wxheading{Data structures}\n\n");
866 void HelpGenVisitor::InsertMethodsHeader()
868 if ( !m_inMethodSection
) {
869 m_inMethodSection
= TRUE
;
871 m_file
.WriteVerbatim( "\\latexignore{\\rtfignore{\\wxheading{Members}}}\n\n");
875 void HelpGenVisitor::CloseFunction()
877 if ( !m_funcName
.empty() ) {
878 if ( m_isFirstParam
) {
880 m_textFunc
<< "\\void";
883 m_textFunc
<< "}\n\n";
885 if ( !m_textStoredFunctionComment
.IsEmpty() ) {
886 m_textFunc
<< m_textStoredFunctionComment
<< '\n';
889 m_arrayFuncDocs
.Add(new FunctionDocEntry(m_funcName
, m_textFunc
));
895 void HelpGenVisitor::CloseClass()
898 size_t count
= m_arrayFuncDocs
.GetCount();
900 FunctionDocEntry::classname
= m_classname
;
901 m_arrayFuncDocs
.Sort(FunctionDocEntry::Compare
);
903 for ( size_t n
= 0; n
< count
; n
++ ) {
904 m_file
.WriteTeX(m_arrayFuncDocs
[n
].text
);
907 m_arrayFuncDocs
.Empty();
916 void HelpGenVisitor::EndVisit()
922 m_fileHeader
.Empty();
925 if (m_file
.IsOpened())
931 wxLogVerbose("%s: finished generating for the current file.",
932 GetCurrentTime("%H:%M:%S"));
935 void HelpGenVisitor::VisitFile( spFile
& file
)
937 m_fileHeader
= file
.mFileName
;
938 wxLogVerbose("%s: started generating docs for classes from file '%s'...",
939 GetCurrentTime("%H:%M:%S"), m_fileHeader
.c_str());
942 void HelpGenVisitor::VisitClass( spClass
& cl
)
946 if (m_file
.IsOpened())
952 wxString name
= cl
.GetName();
954 if ( m_ignoreNames
.IgnoreClass(name
) ) {
955 wxLogVerbose("Skipping ignored class '%s'.", name
.c_str());
960 // the file name is built from the class name by removing the leading "wx"
961 // if any and converting it to the lower case
963 if ( name(0, 2) == "wx" ) {
964 filename
<< name
.c_str() + 2;
970 filename
.MakeLower();
972 filename
.Prepend(m_directoryOut
);
974 if ( !m_overwrite
&& wxFile::Exists(filename
) ) {
975 wxLogError("Won't overwrite existing file '%s' - please use '-f'.",
981 m_inClass
= m_file
.Open(filename
, wxFile::write
);
983 wxLogError("Can't generate documentation for the class '%s'.",
990 m_inTypesSection
= FALSE
;
992 wxLogInfo("Created new file '%s' for class '%s'.",
993 filename
.c_str(), name
.c_str());
995 // write out the header
998 "%% automatically generated by HelpGen %s from\n"
1003 "\\section{\\class{%s}}\\label{%s}\n\n",
1004 GetVersionString().c_str(),
1005 m_fileHeader
.c_str(),
1006 GetCurrentTime("%d/%b/%y %H:%M:%S"),
1008 wxString(name
).MakeLower().c_str());
1010 m_file
.WriteVerbatim(header
);
1012 // the entire text we're writing to file
1015 // if the header includes other headers they must be related to it... try to
1016 // automatically generate the "See also" clause
1017 if ( !m_headers
.IsEmpty() ) {
1018 // correspondence between wxWindows headers and class names
1019 static const char *headers
[] = {
1028 // NULL here means not to insert anything in "See also" for the
1029 // corresponding header
1030 static const char *classes
[] = {
1039 wxASSERT_MSG( WXSIZEOF(headers
) == WXSIZEOF(classes
),
1040 "arrays must be in sync!" );
1042 wxArrayInt interestingClasses
;
1044 size_t count
= m_headers
.Count(), index
;
1045 for ( size_t n
= 0; n
< count
; n
++ ) {
1046 wxString baseHeaderName
= m_headers
[n
].Before('.');
1047 if ( baseHeaderName(0, 3) != "wx/" )
1050 baseHeaderName
.erase(0, 3);
1051 for ( index
= 0; index
< WXSIZEOF(headers
); index
++ ) {
1052 if ( Stricmp(baseHeaderName
, headers
[index
]) == 0 )
1056 if ( (index
< WXSIZEOF(headers
)) && classes
[index
] ) {
1057 // interesting header
1058 interestingClasses
.Add(index
);
1062 if ( !interestingClasses
.IsEmpty() ) {
1063 // do generate "See also" clause
1064 totalText
<< "\\wxheading{See also:}\n\n";
1066 count
= interestingClasses
.Count();
1067 for ( index
= 0; index
< count
; index
++ ) {
1071 totalText
<< MakeHelpref(classes
[interestingClasses
[index
]]);
1074 totalText
<< "\n\n";
1078 // the comment before the class generally explains what is it for so put it
1079 // in place of the class description
1080 if ( cl
.HasComments() ) {
1081 wxString comment
= GetAllComments(cl
);
1083 totalText
<< '\n' << comment
<< '\n';
1086 // derived from section
1087 wxString derived
= "\\wxheading{Derived from}\n\n";
1089 const StrListT
& baseClasses
= cl
.mSuperClassNames
;
1090 if ( baseClasses
.size() == 0 ) {
1091 derived
<< "No base class";
1095 for ( StrListT::const_iterator i
= baseClasses
.begin();
1096 i
!= baseClasses
.end();
1099 // separate from the previous one
1100 derived
<< "\\\\\n";
1106 wxString baseclass
= *i
;
1107 derived
<< "\\helpref{" << baseclass
<< "}";
1108 derived
<< "{" << baseclass
.MakeLower() << "}";
1111 totalText
<< derived
<< "\n\n";
1113 // write all this to file
1114 m_file
.WriteTeX(totalText
);
1116 // if there were any enums/typedefs before, insert their documentation now
1117 InsertDataStructuresHeader();
1118 InsertTypedefDocs();
1124 void HelpGenVisitor::VisitEnumeration( spEnumeration
& en
)
1128 if ( m_inMethodSection
) {
1129 // FIXME that's a bug, but tell the user aboit it nevertheless... we
1130 // should be smart enough to process even the enums which come after the
1132 wxLogWarning("enum '%s' ignored, please put it before the class "
1133 "methods.", en
.GetName().c_str());
1137 // simply copy the enum text in the docs
1138 wxString enumeration
= GetAllComments(en
),
1141 enumerationVerb
<< "\\begin{verbatim}\n"
1143 << "\n\\end{verbatim}\n";
1145 // remember for later use if we're not inside a class yet
1147 m_storedEnums
.Add(enumeration
);
1148 m_storedEnumsVerb
.Add(enumerationVerb
);
1151 // write the header for this section if not done yet
1152 InsertDataStructuresHeader();
1154 m_file
.WriteTeX(enumeration
);
1155 m_file
.WriteVerbatim(enumerationVerb
);
1156 m_file
.WriteVerbatim('\n');
1160 void HelpGenVisitor::VisitTypeDef( spTypeDef
& td
)
1164 if ( m_inMethodSection
) {
1165 // FIXME that's a bug, but tell the user aboit it nevertheless...
1166 wxLogWarning("typedef '%s' ignored, please put it before the class "
1167 "methods.", td
.GetName().c_str());
1171 wxString typedefdoc
;
1172 typedefdoc
<< "{\\small \\begin{verbatim}\n"
1173 << "typedef " << td
.mOriginalType
<< ' ' << td
.GetName()
1174 << "\n\\end{verbatim}}\n"
1175 << GetAllComments(td
);
1177 // remember for later use if we're not inside a class yet
1179 if ( !m_textStoredTypedefs
.IsEmpty() ) {
1180 m_textStoredTypedefs
<< '\n';
1183 m_textStoredTypedefs
<< typedefdoc
;
1186 // write the header for this section if not done yet
1187 InsertDataStructuresHeader();
1190 m_file
.WriteTeX(typedefdoc
);
1194 void HelpGenVisitor::VisitPreprocessorLine( spPreprocessorLine
& pd
)
1196 switch ( pd
.GetStatementType() ) {
1197 case SP_PREP_DEF_INCLUDE_FILE
:
1198 m_headers
.Add(pd
.CPP_GetIncludedFileNeme());
1201 case SP_PREP_DEF_DEFINE_SYMBOL
:
1202 // TODO decide if it's a constant and document it if it is
1207 void HelpGenVisitor::VisitAttribute( spAttribute
& attr
)
1211 // only document the public member variables
1212 if ( !m_inClass
|| !attr
.IsPublic() )
1215 wxLogWarning("Ignoring member variable '%s'.", attr
.GetName().c_str());
1218 void HelpGenVisitor::VisitOperation( spOperation
& op
)
1223 // we don't generate docs right now - either we ignore this class
1224 // entirely or we couldn't open the file
1228 if ( !op
.IsInClass() ) {
1229 // TODO document global functions
1230 wxLogWarning("skipped global function '%s'.", op
.GetName().c_str());
1235 if ( op
.mVisibility
== SP_VIS_PRIVATE
) {
1236 // FIXME should we document protected functions?
1240 m_classname
= op
.GetClass().GetName();
1241 wxString funcname
= op
.GetName();
1243 if ( m_ignoreNames
.IgnoreMethod(m_classname
, funcname
) ) {
1244 wxLogVerbose("Skipping ignored '%s::%s'.",
1245 m_classname
.c_str(), funcname
.c_str());
1250 InsertMethodsHeader();
1253 m_funcName
= funcname
;
1254 m_isFirstParam
= TRUE
;
1256 m_textStoredFunctionComment
= GetAllComments(op
);
1258 // start function documentation
1261 // check for the special case of dtor
1263 if ( (funcname
[0] == '~') && (m_classname
== funcname
.c_str() + 1) ) {
1264 dtor
.Printf("\\destruct{%s}", m_classname
.c_str());
1268 static wxHashTable
sg_MemberSectionsDone(wxKEY_STRING
);
1269 wxString memberSectionName
;
1270 memberSectionName
.Printf("%s::%s", m_classname
.c_str(), funcname
.c_str());
1272 m_textFunc
= wxEmptyString
;
1273 if (!sg_MemberSectionsDone
.Get(memberSectionName
))
1275 m_textFunc
.Printf("\n"
1276 "\\membersection{%s::%s}\\label{%s}\n",
1277 m_classname
.c_str(), funcname
.c_str(),
1278 MakeLabel(m_classname
, funcname
).c_str());
1279 sg_MemberSectionsDone
.Put(memberSectionName
, (wxObject
*) & sg_MemberSectionsDone
);
1284 "\\%sfunc{%s%s}{%s}{",
1285 op
.mIsConstant
? "const" : "",
1286 op
.mIsVirtual
? "virtual " : "",
1287 op
.mRetType
.c_str(),
1292 void HelpGenVisitor::VisitParameter( spParameter
& param
)
1294 if ( m_funcName
.empty() )
1297 if ( m_isFirstParam
) {
1298 m_isFirstParam
= FALSE
;
1304 m_textFunc
<< "\\param{" << param
.mType
<< " }{" << param
.GetName();
1305 wxString defvalue
= param
.mInitVal
;
1306 if ( !defvalue
.IsEmpty() ) {
1307 m_textFunc
<< " = " << defvalue
;
1313 // ---------------------------------------------------------------------------
1315 // ---------------------------------------------------------------------------
1317 DocManager::DocManager(bool checkParamNames
)
1319 m_checkParamNames
= checkParamNames
;
1322 size_t DocManager::TryMatch(const char *str
, const char *match
)
1324 size_t lenMatch
= 0;
1325 while ( str
[lenMatch
] == match
[lenMatch
] ) {
1328 if ( match
[lenMatch
] == '\0' )
1335 bool DocManager::SkipUntil(const char **pp
, char c
)
1337 const char *p
= *pp
;
1353 bool DocManager::SkipSpaceUntil(const char **pp
, char c
)
1355 const char *p
= *pp
;
1357 if ( !isspace(*p
) || *p
== '\0' )
1371 wxString
DocManager::ExtractStringBetweenBraces(const char **pp
)
1375 if ( !SkipSpaceUntil(pp
, '{') ) {
1376 wxLogWarning("file %s(%d): '{' expected after '\\param'",
1377 m_filename
.c_str(), m_line
);
1381 const char *startParam
= ++*pp
; // skip '{'
1383 if ( !SkipUntil(pp
, '}') ) {
1384 wxLogWarning("file %s(%d): '}' expected after '\\param'",
1385 m_filename
.c_str(), m_line
);
1388 result
= wxString(startParam
, (*pp
)++ - startParam
);
1395 bool DocManager::ParseTeXFile(const wxString
& filename
)
1397 m_filename
= filename
;
1399 wxFile
file(m_filename
, wxFile::read
);
1400 if ( !file
.IsOpened() )
1403 off_t len
= file
.Length();
1404 if ( len
== wxInvalidOffset
)
1407 char *buf
= new char[len
+ 1];
1410 if ( file
.Read(buf
, len
) == wxInvalidOffset
) {
1416 // reinit everything
1419 wxLogVerbose("%s: starting to parse doc file '%s'.",
1420 GetCurrentTime("%H:%M:%S"), m_filename
.c_str());
1422 // the name of the class from the last "\membersection" command: we assume
1423 // that the following "\func" or "\constfunc" always documents a method of
1424 // this class (and it should always be like that in wxWindows documentation)
1427 for ( const char *current
= buf
; current
- buf
< len
; current
++ ) {
1428 // FIXME parsing is awfully inefficient
1430 if ( *current
== '%' ) {
1431 // comment, skip until the end of line
1433 SkipUntil(¤t
, '\n');
1438 // all the command we're interested in start with '\\'
1439 while ( *current
!= '\\' && *current
!= '\0' ) {
1440 if ( *current
++ == '\n' )
1444 if ( *current
== '\0' ) {
1445 // no more TeX commands left
1449 current
++; // skip '\\'
1457 } foundCommand
= Nothing
;
1459 size_t lenMatch
= TryMatch(current
, "func");
1461 foundCommand
= Func
;
1464 lenMatch
= TryMatch(current
, "constfunc");
1466 foundCommand
= ConstFunc
;
1468 lenMatch
= TryMatch(current
, "membersection");
1471 foundCommand
= MemberSect
;
1475 if ( foundCommand
== Nothing
)
1478 current
+= lenMatch
;
1480 if ( !SkipSpaceUntil(¤t
, '{') ) {
1481 wxLogWarning("file %s(%d): '{' expected after \\func, "
1482 "\\constfunc or \\membersection.",
1483 m_filename
.c_str(), m_line
);
1490 if ( foundCommand
== MemberSect
) {
1491 // what follows has the form <classname>::<funcname>
1492 const char *startClass
= current
;
1493 if ( !SkipUntil(¤t
, ':') || *(current
+ 1) != ':' ) {
1494 wxLogWarning("file %s(%d): '::' expected after "
1495 "\\membersection.", m_filename
.c_str(), m_line
);
1498 classname
= wxString(startClass
, current
- startClass
);
1499 TeXUnfilter(&classname
);
1505 // extract the return type
1506 const char *startRetType
= current
;
1508 if ( !SkipUntil(¤t
, '}') ) {
1509 wxLogWarning("file %s(%d): '}' expected after return type",
1510 m_filename
.c_str(), m_line
);
1515 wxString returnType
= wxString(startRetType
, current
- startRetType
);
1516 TeXUnfilter(&returnType
);
1519 if ( !SkipSpaceUntil(¤t
, '{') ) {
1520 wxLogWarning("file %s(%d): '{' expected after return type",
1521 m_filename
.c_str(), m_line
);
1527 const char *funcEnd
= current
;
1528 if ( !SkipUntil(&funcEnd
, '}') ) {
1529 wxLogWarning("file %s(%d): '}' expected after function name",
1530 m_filename
.c_str(), m_line
);
1535 wxString funcName
= wxString(current
, funcEnd
- current
);
1536 current
= funcEnd
+ 1;
1538 // trim spaces from both sides
1539 funcName
.Trim(FALSE
);
1540 funcName
.Trim(TRUE
);
1542 // special cases: '$...$' may be used for LaTeX inline math, remove the
1544 if ( funcName
.Find('$') != wxNOT_FOUND
) {
1546 for ( const char *p
= funcName
.c_str(); *p
!= '\0'; p
++ ) {
1547 if ( *p
!= '$' && !isspace(*p
) )
1554 // \destruct{foo} is really ~foo
1555 if ( funcName
[0u] == '\\' ) {
1556 size_t len
= strlen("\\destruct{");
1557 if ( funcName(0, len
) != "\\destruct{" ) {
1558 wxLogWarning("file %s(%d): \\destruct expected",
1559 m_filename
.c_str(), m_line
);
1564 funcName
.erase(0, len
);
1565 funcName
.Prepend('~');
1567 if ( !SkipSpaceUntil(¤t
, '}') ) {
1568 wxLogWarning("file %s(%d): '}' expected after destructor",
1569 m_filename
.c_str(), m_line
);
1574 funcEnd
++; // there is an extra '}' to count
1577 TeXUnfilter(&funcName
);
1580 current
= funcEnd
+ 1; // skip '}'
1581 if ( !SkipSpaceUntil(¤t
, '{') ||
1582 (current
++, !SkipSpaceUntil(¤t
, '\\')) ) {
1583 wxLogWarning("file %s(%d): '\\param' or '\\void' expected",
1584 m_filename
.c_str(), m_line
);
1589 wxArrayString paramNames
, paramTypes
, paramValues
;
1591 bool isVararg
= FALSE
;
1593 current
++; // skip '\\'
1594 lenMatch
= TryMatch(current
, "void");
1596 lenMatch
= TryMatch(current
, "param");
1597 while ( lenMatch
&& (current
- buf
< len
) ) {
1598 current
+= lenMatch
;
1600 // now come {paramtype}{paramname}
1601 wxString paramType
= ExtractStringBetweenBraces(¤t
);
1602 if ( !!paramType
) {
1603 wxString paramText
= ExtractStringBetweenBraces(¤t
);
1604 if ( !!paramText
) {
1605 // the param declaration may contain default value
1606 wxString paramName
= paramText
.BeforeFirst('='),
1607 paramValue
= paramText
.AfterFirst('=');
1609 // sanitize all strings
1610 TeXUnfilter(¶mValue
);
1611 TeXUnfilter(¶mName
);
1612 TeXUnfilter(¶mType
);
1614 paramValues
.Add(paramValue
);
1615 paramNames
.Add(paramName
);
1616 paramTypes
.Add(paramType
);
1621 wxString paramText
= ExtractStringBetweenBraces(¤t
);
1622 if ( paramText
== "..." ) {
1626 wxLogWarning("Parameters of '%s::%s' are in "
1628 classname
.c_str(), funcName
.c_str());
1633 current
= SkipSpaces(current
);
1634 if ( *current
== ',' || *current
== '}' ) {
1635 current
= SkipSpaces(++current
);
1637 lenMatch
= TryMatch(current
, "\\param");
1640 wxLogWarning("file %s(%d): ',' or '}' expected after "
1641 "'\\param'", m_filename
.c_str(), m_line
);
1647 // if we got here there was no '\\void', so must have some params
1648 if ( paramNames
.IsEmpty() ) {
1649 wxLogWarning("file %s(%d): '\\param' or '\\void' expected",
1650 m_filename
.c_str(), m_line
);
1656 // verbose diagnostic output
1658 size_t param
, paramCount
= paramNames
.GetCount();
1659 for ( param
= 0; param
< paramCount
; param
++ ) {
1664 paramsAll
<< paramTypes
[param
] << ' ' << paramNames
[param
];
1667 wxLogVerbose("file %s(%d): found '%s %s::%s(%s)%s'",
1668 m_filename
.c_str(), m_line
,
1673 foundCommand
== ConstFunc
? " const" : "");
1675 // store the info about the just found function
1676 ArrayMethodInfo
*methods
;
1677 int index
= m_classes
.Index(classname
);
1678 if ( index
== wxNOT_FOUND
) {
1679 m_classes
.Add(classname
);
1681 methods
= new ArrayMethodInfo
;
1682 m_methods
.Add(methods
);
1685 methods
= m_methods
[(size_t)index
];
1688 ArrayParamInfo params
;
1689 for ( param
= 0; param
< paramCount
; param
++ ) {
1690 params
.Add(new ParamInfo(paramTypes
[param
],
1692 paramValues
[param
]));
1695 MethodInfo
*method
= new MethodInfo(returnType
, funcName
, params
);
1696 if ( foundCommand
== ConstFunc
)
1697 method
->SetFlag(MethodInfo::Const
);
1699 method
->SetFlag(MethodInfo::Vararg
);
1701 methods
->Add(method
);
1706 wxLogVerbose("%s: finished parsing doc file '%s'.\n",
1707 GetCurrentTime("%H:%M:%S"), m_filename
.c_str());
1712 bool DocManager::DumpDifferences(spContext
*ctxTop
) const
1714 typedef MMemberListT::const_iterator MemberIndex
;
1716 bool foundDiff
= FALSE
;
1718 // flag telling us whether the given class was found at all in the header
1719 size_t nClass
, countClassesInDocs
= m_classes
.GetCount();
1720 bool *classExists
= new bool[countClassesInDocs
];
1721 for ( nClass
= 0; nClass
< countClassesInDocs
; nClass
++ ) {
1722 classExists
[nClass
] = FALSE
;
1725 // ctxTop is normally an spFile
1726 wxASSERT( ctxTop
->GetContextType() == SP_CTX_FILE
);
1728 const MMemberListT
& classes
= ctxTop
->GetMembers();
1729 for ( MemberIndex i
= classes
.begin(); i
!= classes
.end(); i
++ ) {
1730 spContext
*ctx
= *i
;
1731 if ( ctx
->GetContextType() != SP_CTX_CLASS
) {
1732 // TODO process also global functions, macros, ...
1736 spClass
*ctxClass
= (spClass
*)ctx
;
1737 const wxString
& nameClass
= ctxClass
->mName
;
1738 int index
= m_classes
.Index(nameClass
);
1739 if ( index
== wxNOT_FOUND
) {
1740 if ( !m_ignoreNames
.IgnoreClass(nameClass
) ) {
1743 wxLogError("Class '%s' is not documented at all.",
1747 // it makes no sense to check for its functions
1751 classExists
[index
] = TRUE
;
1754 // array of method descriptions for this class
1755 const ArrayMethodInfo
& methods
= *(m_methods
[index
]);
1756 size_t nMethod
, countMethods
= methods
.GetCount();
1758 // flags telling if we already processed given function
1759 bool *methodExists
= new bool[countMethods
];
1760 for ( nMethod
= 0; nMethod
< countMethods
; nMethod
++ ) {
1761 methodExists
[nMethod
] = FALSE
;
1764 wxArrayString aOverloadedMethods
;
1766 const MMemberListT
& functions
= ctxClass
->GetMembers();
1767 for ( MemberIndex j
= functions
.begin(); j
!= functions
.end(); j
++ ) {
1769 if ( ctx
->GetContextType() != SP_CTX_OPERATION
)
1772 spOperation
*ctxMethod
= (spOperation
*)ctx
;
1773 const wxString
& nameMethod
= ctxMethod
->mName
;
1775 // find all functions with the same name
1776 wxArrayInt aMethodsWithSameName
;
1777 for ( nMethod
= 0; nMethod
< countMethods
; nMethod
++ ) {
1778 if ( methods
[nMethod
]->GetName() == nameMethod
)
1779 aMethodsWithSameName
.Add(nMethod
);
1782 if ( aMethodsWithSameName
.IsEmpty() && ctxMethod
->IsPublic() ) {
1783 if ( !m_ignoreNames
.IgnoreMethod(nameClass
, nameMethod
) ) {
1786 wxLogError("'%s::%s' is not documented.",
1788 nameMethod
.c_str());
1791 // don't check params
1794 else if ( aMethodsWithSameName
.GetCount() == 1 ) {
1795 index
= (size_t)aMethodsWithSameName
[0u];
1796 methodExists
[index
] = TRUE
;
1798 if ( m_ignoreNames
.IgnoreMethod(nameClass
, nameMethod
) )
1801 if ( !ctxMethod
->IsPublic() ) {
1802 wxLogWarning("'%s::%s' is documented but not public.",
1804 nameMethod
.c_str());
1807 // check that the flags match
1808 const MethodInfo
& method
= *(methods
[index
]);
1810 bool isVirtual
= ctxMethod
->mIsVirtual
;
1811 if ( isVirtual
!= method
.HasFlag(MethodInfo::Virtual
) ) {
1812 wxLogWarning("'%s::%s' is incorrectly documented as %s"
1816 isVirtual
? "not " : "");
1819 bool isConst
= ctxMethod
->mIsConstant
;
1820 if ( isConst
!= method
.HasFlag(MethodInfo::Const
) ) {
1821 wxLogWarning("'%s::%s' is incorrectly documented as %s"
1825 isConst
? "not " : "");
1828 // check that the params match
1829 const MMemberListT
& params
= ctxMethod
->GetMembers();
1831 if ( params
.size() != method
.GetParamCount() ) {
1832 wxLogError("Incorrect number of parameters for '%s::%s' "
1833 "in the docs: should be %d instead of %d.",
1836 params
.size(), method
.GetParamCount());
1840 for ( MemberIndex k
= params
.begin();
1845 // what else can a function have?
1846 wxASSERT( ctx
->GetContextType() == SP_CTX_PARAMETER
);
1848 spParameter
*ctxParam
= (spParameter
*)ctx
;
1849 const ParamInfo
& param
= method
.GetParam(nParam
);
1850 if ( m_checkParamNames
&&
1851 (param
.GetName() != ctxParam
->mName
) ) {
1854 wxLogError("Parameter #%d of '%s::%s' should be "
1855 "'%s' and not '%s'.",
1859 ctxParam
->mName
.c_str(),
1860 param
.GetName().c_str());
1865 if ( param
.GetType() != ctxParam
->mType
) {
1868 wxLogError("Type of parameter '%s' of '%s::%s' "
1869 "should be '%s' and not '%s'.",
1870 ctxParam
->mName
.c_str(),
1873 ctxParam
->mType
.c_str(),
1874 param
.GetType().GetName().c_str());
1879 if ( param
.GetDefValue() != ctxParam
->mInitVal
) {
1880 wxLogWarning("Default value of parameter '%s' of "
1881 "'%s::%s' should be '%s' and not "
1883 ctxParam
->mName
.c_str(),
1886 ctxParam
->mInitVal
.c_str(),
1887 param
.GetDefValue().c_str());
1893 // TODO OVER add real support for overloaded methods
1895 if ( m_ignoreNames
.IgnoreMethod(nameClass
, nameMethod
) )
1898 if ( aOverloadedMethods
.Index(nameMethod
) == wxNOT_FOUND
) {
1899 // mark all methods with this name as existing
1900 for ( nMethod
= 0; nMethod
< countMethods
; nMethod
++ ) {
1901 if ( methods
[nMethod
]->GetName() == nameMethod
)
1902 methodExists
[nMethod
] = TRUE
;
1905 aOverloadedMethods
.Add(nameMethod
);
1907 wxLogVerbose("'%s::%s' is overloaded and I'm too "
1908 "stupid to find the right match - skipping "
1909 "the param and flags checks.",
1911 nameMethod
.c_str());
1913 //else: warning already given
1917 for ( nMethod
= 0; nMethod
< countMethods
; nMethod
++ ) {
1918 if ( !methodExists
[nMethod
] ) {
1919 const wxString
& nameMethod
= methods
[nMethod
]->GetName();
1920 if ( !m_ignoreNames
.IgnoreMethod(nameClass
, nameMethod
) ) {
1923 wxLogError("'%s::%s' is documented but doesn't exist.",
1925 nameMethod
.c_str());
1930 delete [] methodExists
;
1933 // check that all classes we found in the docs really exist
1934 for ( nClass
= 0; nClass
< countClassesInDocs
; nClass
++ ) {
1935 if ( !classExists
[nClass
] ) {
1938 wxLogError("Class '%s' is documented but doesn't exist.",
1939 m_classes
[nClass
].c_str());
1943 delete [] classExists
;
1948 DocManager::~DocManager()
1950 WX_CLEAR_ARRAY(m_methods
);
1953 // ---------------------------------------------------------------------------
1954 // IgnoreNamesHandler implementation
1955 // ---------------------------------------------------------------------------
1957 int IgnoreNamesHandler::CompareIgnoreListEntries(IgnoreListEntry
*first
,
1958 IgnoreListEntry
*second
)
1960 // first compare the classes
1961 int rc
= first
->m_classname
.Cmp(second
->m_classname
);
1963 rc
= first
->m_funcname
.Cmp(second
->m_funcname
);
1968 bool IgnoreNamesHandler::AddNamesFromFile(const wxString
& filename
)
1970 wxFile
file(filename
, wxFile::read
);
1971 if ( !file
.IsOpened() )
1974 off_t len
= file
.Length();
1975 if ( len
== wxInvalidOffset
)
1978 char *buf
= new char[len
+ 1];
1981 if ( file
.Read(buf
, len
) == wxInvalidOffset
) {
1988 for ( const char *current
= buf
; ; current
++ ) {
1990 // skip DOS line separator
1991 if ( *current
== '\r' )
1995 if ( *current
== '\n' || *current
== '\0' ) {
1996 if ( line
[0u] != '#' ) {
1997 if ( line
.Find(':') != wxNOT_FOUND
) {
1998 wxString classname
= line
.BeforeFirst(':'),
1999 funcname
= line
.AfterLast(':');
2000 m_ignore
.Add(new IgnoreListEntry(classname
, funcname
));
2004 m_ignore
.Add(new IgnoreListEntry(line
, ""));
2009 if ( *current
== '\0' )
2024 // -----------------------------------------------------------------------------
2025 // global function implementation
2026 // -----------------------------------------------------------------------------
2028 static wxString
MakeLabel(const char *classname
, const char *funcname
)
2030 wxString
label(classname
);
2031 if ( funcname
&& funcname
[0] == '\\' ) {
2032 // we may have some special TeX macro - so far only \destruct exists,
2033 // but may be later others will be added
2034 static const char *macros
[] = { "destruct" };
2035 static const char *replacement
[] = { "dtor" };
2038 for ( n
= 0; n
< WXSIZEOF(macros
); n
++ ) {
2039 if ( strncmp(funcname
+ 1, macros
[n
], strlen(macros
[n
])) == 0 ) {
2045 if ( n
== WXSIZEOF(macros
) ) {
2046 wxLogWarning("unknown function name '%s' - leaving as is.",
2050 funcname
= replacement
[n
];
2055 // special treatment for operatorXXX() stuff because the C operators
2056 // are not valid in LaTeX labels
2058 if ( wxString(funcname
).StartsWith("operator", &oper
) ) {
2059 label
<< "operator";
2072 for ( n
= 0; n
< WXSIZEOF(operatorNames
); n
++ ) {
2073 if ( oper
== operatorNames
[n
].oper
) {
2074 label
<< operatorNames
[n
].name
;
2080 if ( n
== WXSIZEOF(operatorNames
) ) {
2081 wxLogWarning("unknown operator '%s' - making dummy label.",
2087 else // simply use the func name
2098 static wxString
MakeHelpref(const char *argument
)
2101 helpref
<< "\\helpref{" << argument
<< "}{" << MakeLabel(argument
) << '}';
2106 static void TeXFilter(wxString
* str
)
2108 // TeX special which can be quoted (don't include backslash nor braces as
2110 static wxRegEx
reNonSpecialSpecials("[#$%&_]"),
2114 reNonSpecialSpecials
.ReplaceAll(str
, "\\\\\\0");
2116 // can't quote these ones as they produce accents when preceded by
2117 // backslash, so put them inside verb
2118 reAccents
.ReplaceAll(str
, "\\\\verb|\\0|");
2121 static void TeXUnfilter(wxString
* str
)
2123 // FIXME may be done much more quickly
2128 static wxRegEx
reNonSpecialSpecials("\\\\([#$%&_{}])"),
2129 reAccents("\\\\verb|([~^])|");
2131 reNonSpecialSpecials
.ReplaceAll(str
, "\\1");
2132 reAccents
.ReplaceAll(str
, "\\1");
2135 static wxString
GetAllComments(const spContext
& ctx
)
2138 const MCommentListT
& commentsList
= ctx
.GetCommentList();
2139 for ( MCommentListT::const_iterator i
= commentsList
.begin();
2140 i
!= commentsList
.end();
2142 wxString comment
= (*i
)->GetText();
2144 // don't take comments like "// ----------" &c
2145 comment
.Trim(FALSE
);
2147 comment
== wxString(comment
[0u], comment
.length() - 1) + '\n' )
2150 comments
<< comment
;
2156 static const char *GetCurrentTime(const char *timeFormat
)
2158 static char s_timeBuffer
[128];
2163 ptmNow
= localtime(&timeNow
);
2165 strftime(s_timeBuffer
, WXSIZEOF(s_timeBuffer
), timeFormat
, ptmNow
);
2167 return s_timeBuffer
;
2170 static const wxString
GetVersionString()
2172 wxString version
= "$Revision$";
2173 wxRegEx("^\\$Revision$$").ReplaceFirst(&version
, "\\1");
2179 Revision 1.20 2002/01/03 14:23:33 JS
2180 Added code to make it not duplicate membersections for overloaded functions
2182 Revision 1.19 2002/01/03 13:34:12 JS
2183 Added FlushAll to CloseClass, otherwise text was only flushed right at the end,
2184 and appeared in one file.
2186 Revision 1.18 2002/01/03 12:02:47 JS
2187 Added main() and corrected VC++ project settings
2189 Revision 1.17 2001/11/30 21:43:35 VZ
2190 now the methods are sorted in the correct order in the generated docs
2192 Revision 1.16 2001/11/28 19:27:33 VZ
2193 HelpGen doesn't work in GUI mode
2195 Revision 1.15 2001/11/22 21:59:58 GD
2196 use "..." instead of <...> for wx headers
2198 Revision 1.14 2001/07/19 13:51:29 VZ
2199 fixes to version string
2201 Revision 1.13 2001/07/19 13:44:57 VZ
2202 1. compilation fixes
2203 2. don't quote special characters inside verbatim environment
2205 Revision 1.12 2000/10/09 13:53:33 juliansmart
2207 Doc corrections; added HelpGen project files
2209 Revision 1.11 2000/07/15 19:50:42 cvsuser
2212 Revision 1.10.2.2 2000/03/27 15:33:10 VZ
2213 don't trasnform output dir name to lower case
2215 Revision 1.10 2000/03/11 10:05:23 VS
2216 now compiles with wxBase
2218 Revision 1.9 2000/01/16 13:25:21 VS
2219 compilation fixes (gcc)
2221 Revision 1.8 1999/09/13 14:29:39 JS
2223 Made HelpGen into a wxWin app (still uses command-line args); moved includes
2224 into src for simplicity; added VC++ 5 project file
2226 Revision 1.7 1999/02/21 22:32:32 VZ
2227 1. more C++ parser fixes - now it almost parses wx/string.h
2228 a) #if/#ifdef/#else (very) limited support
2229 b) param type fix - now indirection chars are correctly handled
2230 c) class/struct/union distinction
2231 d) public/private fixes
2232 e) Dump() function added - very useful for debugging
2234 2. option to ignore parameter names during 'diff' (in fact, they're ignored
2235 by default, and this option switches it on)
2237 Revision 1.6 1999/02/20 23:00:26 VZ
2238 1. new 'diff' mode which seems to work
2239 2. output files are not overwritten in 'dmup' mode
2240 3. fixes for better handling of const functions and operators
2241 ----------------------------
2243 date: 1999/02/15 23:07:25; author: VZ; state: Exp; lines: +106 -45
2244 1. Parser improvements
2245 a) const and virtual methods are parsed correctly (not static yet)
2246 b) "const" which is part of the return type is not swallowed
2248 2. HelpGen improvements: -o outputdir parameter added to the cmd line,
2249 "//---------" kind comments discarded now.
2250 ----------------------------
2252 date: 1999/01/13 14:23:31; author: JS; state: Exp; lines: +4 -4
2254 some tweaks to HelpGen
2255 ----------------------------
2257 date: 1999/01/09 20:18:03; author: JS; state: Exp; lines: +7 -2
2259 HelpGen starting to compile with VC++
2260 ----------------------------
2262 date: 1999/01/08 19:46:22; author: VZ; state: Exp; lines: +208 -35
2264 supports typedefs, generates "See also:" and adds "virtual " for virtual
2266 ----------------------------
2268 date: 1999/01/08 17:45:55; author: VZ; state: Exp;
2270 HelpGen is a prototype of the tool for automatic generation of the .tex files
2271 for wxWindows documentation from C++ headers
2274 /* vi: set tw=80 et ts=4 sw=4: */