HelpGen is a prototype of the tool for automatic generation of the .tex files

for wxWindows documentation from C++ headers


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1347 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-01-08 17:46:08 +00:00
parent cde9f08e1f
commit cecfc5e7e5
21 changed files with 10005 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+125
View File
@@ -0,0 +1,125 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Implementation of C++/Java parser
// compatible with SourceParserBase interface
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __CJPARSESR_G__
#define __CJPARSESR_G__
#include "srcparser.h"
#include <iostream.h>
#include <memory.h>
#include <stdlib.h>
#include <stdio.h>
// class parses given "memory-resident" Java or C++ source code
// and captures information about classes/attrubutes/methods/
// arguments/etc into structures. Conforms with SourceParserBase
// interface requirements.
class CJSourceParser : public SourceParserBase
{
protected:
// begining of the full-text area of the source file
char* mpStart;
// points to first character after the end
// of teh full-text area
char* mpEnd;
// current "privacy level"
int mCurVis;
// current parsing position int full-text area
char* cur;
// about the current class
bool mIsVirtaul;
bool mIsTemplate;
size_t mNestingLevel;
// context data for which is currently being collected
spContext* mpCurCtx;
int mCurCtxType; // type of the current context
bool mCommentsOn;
bool mMacrosOn;
protected:
void AttachComments( spContext& ctx, char* cur );
void ParseKeyword( char*& cur );
bool ParseNameAndRetVal( char*& cur, bool& isAMacro );
bool ParseArguments( char*& cur );
void ParseMemberVar( char*& cur );
void SkipFunction( char*& cur );
void SkipFunctionBody( char*& cur );
bool CheckVisibilty( char*& cur );
void AddClassNode( char*& cur );
void AddMacroNode( char*& cur );
void AddEnumNode( char*& cur );
void AddTypeDefNode( char*& cur );
void DumpOperationInfo( spOperation& info, const string& tab, ostream& os );
void DumpClassHeader( spClass& info, ostream& os );
void DumpClassBody( spClass& info, ostream& os );
public:
// NOTE:: discarding of macros or comments improves performance and
// decreases memory usage
CJSourceParser(bool collectCommnets = 1,
bool collectMacros = 1);
// returns the root-node of the created context tree
// (user is responsible for releasing it from the heep)
// "end" should point to the last (character + 1) of the
// source text
virtual spFile* Parse( char* start, char* end );
};
// inline'ed helpers used (just info):
/*
static inline void skip_to_eol( char*& cur );
static inline void skip_eol( char*& cur );
static inline bool skip_to_next_comment_in_the_line( char*& cur );
static void skip_to_prev_line( char*& cur );
static inline void skip_comments( char*& cur );
static inline void clear_commets_queue();
static inline void skip_quoted_string( char*& cur );
static inline bool get_next_token( char*& cur );
static inline void skip_preprocessor_dir( char*& cur );
static void skip_token( char*& cur );
static inline size_t get_token_len( char* tok );
static inline bool cmp_tokens( char* tok1, char* tok2 );
static inline bool cmp_tokens_fast( char* tok1, char* tok2, size_t len );
static inline void skip_tempalate_statement( char*& cur );
static inline void skip_statement( char*& cur );
static inline void skip_token_back( char*& cur );
static inline void skip_next_token_back( char*& cur );
static string get_token_str( char* cur );
static size_t skip_block( char*& cur );
static inline bool skip_imp_block( char*& cur );
static bool is_class_token( char*& cur );
inline static bool is_forward_decl( char* cur );
inline static bool is_function( char* cur, bool& isAMacro );
static inline void skip_scope_block( char*& cur );
static void arrange_indirection_tokens_between( string& type, string& identifier );
static bool is_keyword( char* cur );
static inline void get_string_between( char* start, char* end, string* pStr );
static char* set_comment_text( string& text, char* start );
*/
#endif
+157
View File
@@ -0,0 +1,157 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __DOCRIPPER_G__
#define __DOCRIPPER_G__
#include "scriptbinder.h"
#include "srcparser.h"
#include "sourcepainter.h"
#if defined( wxUSE_TEMPLATE_STL )
#include <vector>
typedef vector<ScriptTemplate*> STemplateListT;
#else
#include "wxstlvec.h"
typedef ScriptTemplate* ScriptTemplatePtrT;
typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptTemplatePtrT) STemplateListT;
#endif
// specific DocGenerator class for "Ripper",
// also acts as source code visitor
class RipperDocGen : public DocGeneratorBase, public spVisitor
{
protected:
// templates for various sections
ScriptTemplate mTopTempl;
ScriptTemplate mContentIdxTempl;
ScriptTemplate mSuperContentTempl;
ScriptTemplate mSubContentTempl;
ScriptTemplate mOutLineTempl;
ScriptTemplate mOutLine1Templ;
// template used for corss-references
ScriptTemplate mRefTempl;
// template used to show not-existing sections
ScriptTemplate mDeadRefTempl;
// template collection for generation of class-tree
STemplateListT mTreeTemplates;
// pointers to all major index sections
ScriptSection* mpTopIdx;
ScriptSection* mpClassIdx;
ScriptSection* mpEnumIdx;
ScriptSection* mpTypeDefIdx;
ScriptSection* mpMacroIdx;
ScriptSection* mpGlobalVarsIdx;
ScriptSection* mpGlobalFuncIdx;
ScriptSection* mpConstIdx;
// parser set up from user-code for sepcific language
SourceParserBase* mpParser;
// class section, which is currently being
// assembled
ScriptSection* mpCurClassSect;
// source syntax heighlighter object
SourcePainter mSrcPainter;
// context, to which all file contexts
// are assembled
spContext* mpFileBinderCtx;
// script tags set up from usesr code
MarkupTagsT mTags;
protected:
// helpers
void AppendComments( spContext& fromContext, string& str );
void AppendMulitilineStr( string& st, string& mlStr );
void AppendHighlightedSource( string& st, string source );
// returns TRUE, if no comments found in the context,
// plus, creates dummy(empty) section, and puts a
// reference woth "dead-link" template to it in the
// given index-section "toSect"
bool CheckIfUncommented( spContext& ctx, ScriptSection& toSect );
// checks if context has any comments, then returns
// template of normal reference, otherwise of dead reference
ScriptTemplate* GetRefTemplFor( spContext& ctx );
// adds "someClass::" perfix to the context name,
// if it's not in the file scope (i.e. if it's not global)
string GetScopedName( spContext& ofCtx );
// adds section to currently assembled class section
// and places references to it from "public", "protected"
// or "private" indexing-subsections of the class, depending
// on the visibility of the context
void AddToCurrentClass( ScriptSection* pSection, spContext& ctx,
const char* subSectionName );
// called, after all files are processed, to
// resolve possible super/derived class relations,
// and put cross references to them - where resolution was
// successful
void LinkSuperClassRefs();
// implementations of "visiting procedures", declared in spVisitor
virtual void VisitClass( spClass& cl );
virtual void VisitEnumeration( spEnumeration& en );
virtual void VisitTypeDef( spTypeDef& td );
virtual void VisitPreprocessorLine( spPreprocessorLine& pd );
virtual void VisitAttribute( spAttribute& attr );
virtual void VisitOperation( spOperation& op );
// overriden member of DocGernatorBase
virtual bool OnSaveDocument( ScriptStream& stm );
virtual ScriptSection* GetTopSection()
{ return mpTopIdx; }
public:
RipperDocGen();
~RipperDocGen();
// should be called onece to set user-code provided,
// parser for specific source code language
// (NOTE:: it's the user-code's responsibility to
// relseas memory of pParser)
void Init( SourceParserBase* pParser );
// should be called on each file
void ProcessFile( const char* sourceFile );
};
#endif
+100
View File
@@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 27/12/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __IFCONTEXT_G__
#define __IFCONTEXT_G__
#include "srcparser.h"
#include "cjparser.h"
class spBookmark
{
public:
size_t mFrom;
size_t mLen;
size_t mFileNo;
inline spBookmark() {}
inline spBookmark( int from, int len, int fileNo )
: mFrom( from ), mLen( len ), mFileNo( fileNo )
{}
};
#if defined( wxUSE_TEMPLATE_STL )
typedef vector<spBookmark) BookmarkListT
#else
typedef WXSTL_VECTOR_SHALLOW_COPY(spBookmark) BookmarkListT;
#endif
class spInterFileContext : public spContext
{
protected:
BookmarkListT mDeletionMarks;
BookmarkListT mFiltered;
size_t mCurFileNo;
CJSourceParser mParser;
protected:
size_t GetFileNoOfContext( spContext& ctx );
size_t GetFileNo( const string& fname );
void InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark );
void DoAppendSourceFragment( string& source,
string& result,
size_t pos, size_t len );
void GenerateContextBody( spContext& ctx,
string& source,
string& result,
size_t& lastSavedPos,
size_t& lastKnownPos );
public:
StrListT mFiles;
StrListT mContents;
public:
spInterFileContext();
~spInterFileContext();
void AddFile( const string& fname, const string& content );
void RemoveContext( spContext& ctx );
void GenrateContents();
void ParseContents( SourceParserPlugin* pPlugin = NULL );
void WriteToFiles();
// overriden method of the base class (finds out the source fragment)
virtual string GetBody( spContext* pCtx = NULL );
virtual string GetHeader( spContext* pCtx = NULL );
};
#endif
+51
View File
@@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __MARKUP_G__
#define __MARKUP_G__
// indicies for the MarkupTagsT array
#define TAG_BOLD 0
#define TAG_ITALIC 1
#define TAG_FIXED_FONT 2
#define TAG_BLACK_FONT 3
#define TAG_RED_FONT 4
#define TAG_GREEN_FONT 5
#define TAG_BLUE_FONT 6
#define TAG_PARAGRAPH 7
#define TAG_NEW_LINE 8
#define TAG_HEADING_1 9
#define TAG_HEADING_2 10
#define TAG_HEADING_3 11
#define TAG_ITEM_LIST 12
#define TAG_LIST_ITEM 13
struct TagStructT
{
char* start; // tag that starts style
char* end; // tag that finishes style
};
// tag array
typedef TagStructT* MarkupTagsT;
// returns array of TagStructT with tag strings for HTML
MarkupTagsT get_HTML_markup_tags();
// MarkupTagsT get_PostScript_markup_tags();
// MarkupTagsT get_Latex_markup_tags();
#endif
+377
View File
@@ -0,0 +1,377 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __SCRIPTBINDER_G__
#define __SCRIPTBINDER_G__
#if defined( wxUSE_TEMPLATE_STL )
#include <vector>
#ifdef WIN32
#include <bstring.h>
#else
#include <strclass.h>
#include <string.h>
#endif
#else
#include "wxstlvec.h"
#include "wx/string.h"
// FIXME:: dirty!
typedef wxString string;
#endif
#ifndef ASSERT
// assert yourself
#define ASSERT(x) if (!(x) ) throw;
#endif
#include "markup.h"
// just another portable stream class...
class ScriptStream
{
protected:
char* mpBuf;
size_t mSize;
size_t mCapacity;
public:
ScriptStream();
~ScriptStream();
void WriteBytes( const void* srcBuf, size_t count );
ScriptStream& operator<<( const char* str );
ScriptStream& operator<<( const string& str );
ScriptStream& operator<<( char ch );
void endl();
inline char* GetBuf() { return mpBuf; }
inline size_t GetBufSize() { return mSize; }
// clears current contents of the stream
void Reset() { mSize = 0; }
};
class ScriptTemplate;
// used internally by ScriptTemplate
enum TEMPLATE_VARIABLE_TYPES
{
TVAR_INTEGER,
TVAR_STRING,
TVAR_DOUBLE,
TVAR_REF_ARRAY
};
// helper structures used only by ScriptTemplate
struct TVarInfo
{
public:
const char* mName;
int mType;
int mOfs;
TVarInfo( const char* name, int ofs, int varType )
: mName(name),
mType( varType ),
mOfs( ofs )
{}
};
struct TArrayInfo : public TVarInfo
{
public:
int mRefOfs;
int mSizeIntOfs;
int mObjRefTemplOfs;
TArrayInfo( const char* name )
: TVarInfo( name, 0, TVAR_REF_ARRAY )
{}
};
// stores offset of the given member (of the given class)
// to (*pOfs), though the use of template classes would have
// solved this problem in much clearer fashion
// FOR NOW:: obtaining physical offset of class member
// does not appeare to be protable across compilers?
// FIXME:: +/- 1 problem
#ifdef __UNIX__
#define WEIRD_OFFSET 1
#else
#define WEIRD_OFFSET 0
#endif
#define GET_VAR_OFS( className, varName, pOfs ) \
{ \
int* className::* varPtr; \
varPtr = (int* className::*)&className::varName; \
\
(*pOfs) = int(*(int*)&varPtr)-WEIRD_OFFSET; \
}
class ScriptSection;
#if defined( wxUSE_TEMPLATE_STL )
typedef vector<TVarInfo*> TVarListT;
// container class for sections
typedef vector<ScriptSection*> SectListT;
#else
typedef TVarInfo* TVarInfoPtrT;
typedef ScriptSection* ScriptSectionPtrT;
typedef WXSTL_VECTOR_SHALLOW_COPY(TVarInfoPtrT) TVarListT;
// container class for sections
typedef WXSTL_VECTOR_SHALLOW_COPY(ScriptSectionPtrT) SectListT;
#endif
// class performs preprocessing of arbitrary scripts,
// replaces identifiers enclosed in $(..) tag, whith
// values of the corresponding class member variables
class ScriptTemplate
{
protected:
// do not use string object here - parsing of
// C string can be much faster (in debug v.)
char* mTText;
TVarListT mVars;
inline void PrintVar( TVarInfo* pInfo,
void* dataObj,
ScriptStream& stm );
public:
ScriptTemplate( const string& templateText );
virtual ~ScriptTemplate();
bool HasVar( const char* name );
// Member variables registration methods.
// NOTE:: GET_VAR_OFS() macro should be used
// to get offset of the class member (see #define above)
void AddStringVar ( const char* name, int ofs );
void AddIntegerVar( const char* name, int ofs );
void AddDoubleVar ( const char* name, int ofs );
void AddObjectRefArray( const char* name,
int ofsRefToFirstObj,
int ofsObjSizeInt,
int ofsObjRefTempl
);
// reads the script, replaces $(..) tags with values
// of registered members of dataObj object, and outputs
// the result to given text stream
void PrintScript( void* dataObj, ScriptStream& stm );
};
class ScriptSection;
// class manages section and aggregated sections of
// inter-linked documents
class ScriptSection
{
protected:
// NOTE:: "$(NAME)", $(ID), "$(BODY)" and "$(REFLIST)" aree
// reseved template variables of ScriptSection
// the below there members are registered to ScriptTemplate,
// GUID within the section tree (numeric)
ScriptSection* mpParent;
string mId; // $(ID)
string mName; // $(NAME)
string mBody; // $(BODY)
// NULL, if this section is not aggregated anywhere
SectListT mSubsections; // aggregated sectons
SectListT mReferences; // registered as $(REFLIST)
bool mAutoHide; // see autoHide arg, in constructor
bool mSortOn; // TRUE, if sort subsectons by naem
// tempalte for this section
ScriptTemplate* mpSectTempl;
// template used for links (or references) to this section
ScriptTemplate* mpRefTempl;
// do not call destructor of this object,
// call RemoveRef() instead
int mRefCount;
static int mIdCounter; // generator of GUIDs
// fields registered and used by ScriptTemplate object
void* mRefFirst;
int mArrSize;
protected:
virtual void AddRef();
virtual void RemoveRef();
void DoRemoveEmptySections(int& nRemoved, SectListT& removedLst);
void DoRemoveDeadLinks( SectListT& removedLst);
public:
// NOTE:: pass NULL to certain template, if your sure
// this kind of template will never be used,
// e.g. if section is contained but never referrenced,
// then pReferenceTemplate can be NULL
// if autoHide option is TRUE, the section will be automatically
// collapsed (not shown) if it doesn't contain any references
// to other sections (e.g. could be usefull for autoamically
// hiding empty index-sections).
ScriptSection( const string& name = "",
const string& body = "",
ScriptTemplate* pSectionTemplate = NULL,
ScriptTemplate* pReferenceTemplate = NULL,
bool autoHide = FALSE,
bool sorted = FALSE
);
// calls RemoveRef() to all aggreagated sections first,
// then to all referenced section - this way all
// sections (even not aggregated ones) become "garbage-collected"
// NOTE:: do not call destructor directlly, call RemoveRef()
// instead
virtual ~ScriptSection();
// if addToReferencesToo is TRUE, section is aggregated and
// also added to reference list of this section
void AddSection( ScriptSection* pSection, bool addToReferencesToo = FALSE );
// add cross-reference to this given section
void AddReference( ScriptSection* pReferredSection );
// subsection may be given of variable depth level,
// e.g. "publications/reviews/software"
ScriptSection* GetSubsection( const char* name );
// returns list aggregated sections
SectListT& GetSubsections();
// binds reserved template names ( $(..) ) to member
// vairalbes in the ScriptSection class, should be called
// to initialize each user-code provided script template
static void RegisterTemplate( ScriptTemplate& sectionTempalte );
// prints out section tree to the stream, starting from
// this section as a root node
virtual void Print( ScriptStream& stm );
// searches empty sections which has autoHide == TRUE,
// and colapses them (this method should be called )
// on the root-section of the sections tree
// NOTE:: does not work properly, yet!
void RemoveEmptySections();
};
// base class for documnetation generators
// (allows user code set up target script type,
// independently of documentation type)
class DocGeneratorBase
{
protected:
MarkupTagsT mTags;
// override this method to do some post processing
// after generation of document, or even write some
// data into output stream, before the section tree
// is flushed into it.
// return FALSE, if something has gone wrong and
// document cannot be saved now
virtual bool OnSaveDocument( ScriptStream& stm )
{ return 1; }
// override this method to provide reference to
// the top section of the document (used as default
// starting section when saving a document)
virtual ScriptSection* GetTopSection()
{ return 0; }
public:
DocGeneratorBase()
: mTags(0) // no defaul script
{}
// dectrouctors of polymorphic classes SHOULD be virtual
virtual ~DocGeneratorBase() {}
// returns tags, being used for specific target script
MarkupTagsT GetScriptMarkupTags() { return mTags; }
// sets tag array for specific script
// NOTE:: Why virtual? since approach with MarkupTagsT is
// "flowless" only in theory. Overriding this method
// allows document generators to check the type of the
// target script, and perhaps make some modifications
// to generator's tamplates, to match the specific script
virtual void SetScriptMarkupTags( MarkupTagsT tags )
{ mTags = tags; }
// seves document to file starting from the root-node of
// the document (provided by GetTopSection() method),
// or from "pFromSection" if it's not NULL.
// fopenOptions arg. is string passed to fopen() method,
// returns TRUE, if saving was successfull
virtual bool SaveDocument( const char* fname,
const char* fopenOptions = "w",
ScriptSection* pFromSection = NULL
);
};
#endif
+104
View File
@@ -0,0 +1,104 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __SOURCEPAINTER_G__
#define __SOURCEPAINTER_G__
#ifndef ASSERT
#define ASSERT(x) if (!(x)) throw
#endif
#if defined( wxUSE_TEMPLATE_STL )
#include <vector.h>
typedef vector<int> SPBlockListT;
#ifdef WIN32
#include <bstring.h>
#else
#include <strclass.h>
#include <string.h>
#endif
#else
#include "wxstlvec.h"
#include "wx/string.h"
// FIXME:: dirty!
#define string wxString
typedef WXSTL_VECTOR_SHALLOW_COPY(int) SPBlockListT;
#endif
#include "markup.h" // import MarkupTagsT definition
// "colored" codes for highlighted blocks
#define RANK_BLACK 0 // common source fragments
#define RANK_BLUE 1 // basic types
#define RANK_RED 2 // reserved words
#define RANK_GREEN 3 // comments
// colored block description format :
// int( ( rank << 16 ) | ( source_range_len ) )
// FOR NOW:: no lagnguage-map selection
// source code syntax heighlighter (CPP+JAVA+VB+PASCAL)
class SourcePainter
{
protected:
string mResultStr;
SPBlockListT mBlocks;
bool mCollectResultsOn;
// state variables
bool mIsInComment;
bool mCommentIsMultiline;
public:
// assembleResultString == TRUE - instructs painter
// to collect each chunk of srouce passed to ProcessSource(),
// so that results cann be futher obtained in a single string
// instead of vector of block descriptions
SourcePainter( bool assembleResultString = TRUE );
virtual ~SourcePainter() {}
// can be called multiple times (e.g. on each source line)
void ProcessSource( char* src, int srcLen );
// method, for manually adjusting state of source painter
void SetState( bool isInComment,
bool commentIsMultiline );
// reinitializes object - clears results of previouse processing
void Init( bool assembleResultString = TRUE );
// generates string of highlighted source for the scipting
// language given by "tags" argument
virtual void GetResultString(string& result, MarkupTagsT tags);
// returns vector of block descriptors, see SPBlockListT definition
// (block descriptors can be used for fast custom hightlighted text generation)
SPBlockListT& GetBlocks();
// NOTE:: static method
// returns if the given word is a reserved word or basic type identifier
static bool IsKeyword( char* word, int wordLen );
};
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+295
View File
@@ -0,0 +1,295 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 27/12/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "ifcontext.h"
#pragma interface
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <malloc.h>
#include <stdio.h>
#include "ifcontext.h"
/***** Implementation for class spInterFileContext *****/
size_t spInterFileContext::GetFileNo( const string& fname )
{
for( size_t i = 0; i != mFiles.size(); ++i )
if ( fname == mFiles[i] ) return i;
wxASSERT(0); // DBG::
return 0;
}
size_t spInterFileContext::GetFileNoOfContext( spContext& ctx )
{
spContext* pCtx = ctx.GetEnclosingContext( SP_CTX_FILE );
// DBG:: outer-file context should be present
wxASSERT( pCtx && pCtx->GetType() == SP_CTX_FILE );
return GetFileNo( ((spFile*)pCtx)->mFileName );
}
/*** public interface ***/
spInterFileContext::spInterFileContext()
{}
spInterFileContext::~spInterFileContext()
{}
void spInterFileContext::AddFile( const string& fname, const string& content )
{
mFiles.push_back( fname );
mContents.push_back( content );
}
void spInterFileContext::RemoveContext( spContext& ctx )
{
wxASSERT( ctx.PositionIsKnown() ); // DBG:: should be checked by-user code
size_t fNo = GetFileNoOfContext( ctx );
mDeletionMarks.push_back( spBookmark( ctx.mSrcOffset, ctx.mContextLength, fNo ) );
}
void spInterFileContext::InsertBookmarkSorted( BookmarkListT& lst, spBookmark& mark )
{
for( size_t i = 0; i != lst.size(); ++i )
if ( lst[i].mFrom > mark.mFrom )
{
lst.insert( &lst[i], mark );
return;
}
lst.push_back( mark );
}
void spInterFileContext::DoAppendSourceFragment( string& source,
string& result,
size_t pos, size_t len )
{
mFiltered.erase( mFiltered.begin(), mFiltered.end() );
size_t i;
for( i = 0; i != mDeletionMarks.size(); ++i )
{
spBookmark& mark = mDeletionMarks[i];
if ( mark.mFileNo == mCurFileNo &&
mark.mFrom >= pos && mark.mFrom < pos + len )
InsertBookmarkSorted( mFiltered, mark );
}
size_t cur = pos;
for( i = 0; i != mFiltered.size(); ++ i )
{
spBookmark& mark = mFiltered[i];
result.append( source, cur, ( (size_t)mark.mFrom - cur ) );
cur = size_t( mark.mFrom + mark.mLen );
if ( cur >= pos + len ) // check if we've overstepped the current source-fragment
{
wxASSERT(0); // DBG:: with current imp. this should not happen
cur = pos + len; break;
}
}
result.append( source, cur, ( pos + len ) - cur );
}
void spInterFileContext::GenerateContextBody( spContext& ctx,
string& source,
string& result,
size_t& lastSavedPos,
size_t& lastKnownPos )
{
if ( ctx.PositionIsKnown() )
lastKnownPos = ctx.mSrcOffset;
if ( ctx.IsVirtualContext() )
{
// add fragment accumulated before this context
DoAppendSourceFragment( source, result,
size_t(lastSavedPos),
size_t(lastKnownPos - lastSavedPos) );
// add context body
result += ctx.GetVirtualContextBody();
lastSavedPos = lastKnownPos;
if ( ctx.PositionIsKnown() )
{
if ( ctx.VitualContextHasChildren() )
{
lastKnownPos = ctx.mSrcOffset + ctx.mHeaderLength;
lastSavedPos = lastKnownPos;
}
else
{
lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
lastSavedPos = lastKnownPos;
return; // have not children
}
}
}
MMemberListT& lst = ctx.GetMembers();
for( size_t i = 0; i != lst.size(); ++i )
GenerateContextBody( *lst[i], source, result, lastSavedPos, lastKnownPos );
if ( ctx.IsVirtualContext() )
{
if ( ctx.VitualContextHasChildren() &&
ctx.GetFooterOfVirtualContextBody() != "" )
{
// append the reminder space after children of the context
DoAppendSourceFragment( result, source,
size_t(lastSavedPos),
size_t(lastKnownPos - lastSavedPos) );
// add footer
result += ctx.GetFooterOfVirtualContextBody();
lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
lastSavedPos = lastKnownPos;
}
}
if ( ctx.PositionIsKnown() )
lastKnownPos = ctx.mSrcOffset + ctx.mContextLength;
}
void spInterFileContext::GenrateContents()
{
MMemberListT& lst = GetMembers();
for( size_t f = 0; f != lst.size(); ++f )
{
string& fname = ((spFile*)lst[f])->mFileName;
size_t fileNo = GetFileNo( fname );
string& source = mContents[ fileNo ];
string result;
size_t lastKnownPos = 0, // the begining of the file is always "known"
lastSavedPos = 0;
mCurFileNo = fileNo;
GenerateContextBody( *lst[f], source, result, lastSavedPos, lastKnownPos );
// the end of file is always known
lastKnownPos = mContents[ fileNo ].length();
// append the reminder
DoAppendSourceFragment( source, result,
size_t(lastSavedPos),
size_t(lastKnownPos - lastSavedPos) );
// replace original contnet with newly generated one
mContents[ fileNo ] = result;
}
}
void spInterFileContext::ParseContents( SourceParserPlugin* pPlugin )
{
mDeletionMarks.erase( mDeletionMarks.begin(), mDeletionMarks.end() );
RemoveChildren(); // clean up top-level context
mParser.SetPlugin( pPlugin );
for( size_t i = 0; i != mFiles.size(); ++i )
{
char* s = (char*)(mContents[i].c_str());
spFile* pFCtx = mParser.Parse( s, s + mContents[i].length() );
pFCtx->mFileName = mFiles[i];
AddMember( pFCtx );
}
}
void spInterFileContext::WriteToFiles()
{
for( size_t i = 0; i != mFiles.size(); ++i )
{
FILE* fp = fopen( mFiles[i].c_str(), "w+t" );
if ( int(fp) > 0 )
{
fwrite( mContents[i].c_str(), sizeof(char), mContents[i].length(), fp );
fclose( fp );
}
}
}
string spInterFileContext::GetBody( spContext* pCtx )
{
wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
string& source = mContents[ GetFileNoOfContext( *pCtx ) ];
return string( source.c_str() + pCtx->mSrcOffset, pCtx->mContextLength );
}
string spInterFileContext::GetHeader( spContext* pCtx )
{
wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code
wxASSERT( pCtx->mHeaderLength != -1 ); // DBG:: -/-
string& source = mContents[ GetFileNoOfContext( *pCtx ) ];
return string( source.c_str() + pCtx->mSrcOffset, pCtx->mHeaderLength );
}
+46
View File
@@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "markup.h"
static TagStructT htmlTags[] =
{
{ "<b>","</b>" }, // 0
{ "<i>","</i>" }, // 1
{ "<pre>","</pre>" }, // 2
{ "<font color=\"#000000\">","</font>" }, // 3
{ "<font color=\"#8F0000\">","</font>" }, // 4
{ "<font color=\"#008F00\">","</font>" }, // 5
{ "<font color=\"#0000CF\">","</font>" }, // 6
{ "<p>","</p>" }, // 7
{ "<br>","" }, // 8
{ "<h1>","</h1>" }, // 9
{ "<h2>","</h2>" }, // 10
{ "<h3>","</h3>" }, // 11
{ "<ul>","</ul>" }, // 12
{ "<li>","</li>" }, // 13
};
MarkupTagsT get_HTML_markup_tags()
{
return htmlTags;
}
+157
View File
@@ -0,0 +1,157 @@
/////////////////////////////////////////////////////////////////////////////
// Name: No names yet.
// Purpose: Contrib. demo
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 22/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleskandars Gluchovas
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#ifdef WIN32
#include <io.h>
#endif
#include <stdio.h>
#include "markup.h" // get_HTML_markup_tags() will be used
#include "docripper.h"
#include "cjparser.h" // C++/Java will be parsed here
/***** Main funciton *****/
#ifdef WIN32
// NOTE:: under Windows this generator parses all .h files
// int the current directory
#include "direct.h"
void main(int argc, char** argv)
{
cout << "C++/JAVA Source Documentation Generator (\"wxDocRipper\")" << endl
<< "(C) 1998, Aleksandras Gluchovas (mailto:alex@soften.ktu.lt)"
<< endl << endl;
RipperDocGen gen;
// set up target script
gen.SetScriptMarkupTags( get_HTML_markup_tags() );
// setup source langauge
CJSourceParser* pParser = new CJSourceParser();
gen.Init( pParser );
// read process all files in the current directory
struct _finddata_t c_file; // NT-specific?
long hFile;
hFile = _findfirst( "*.h", &c_file );
int total = 0;
while( hFile != -1L )
{
gen.ProcessFile( c_file.name );
++total;
if ( _findnext( hFile, &c_file ) == -1L )
break;
}
if ( total )
{
cout << endl
<< "*** storing source documenation into ./srcref.html ***"
<< endl << endl;
if ( !gen.SaveDocument( "srcref.html" ) )
cout << "\nERROR: document cannot be saved" << endl;
}
else
{
cout << "\nno .h files found in this directory - You must be running Windows now :-)"
<< endl;
return;
}
printf( "\nTotal %d file(s) processed, done.\n", total );
}
#else
// NOTE:: on platfroms other then Windows this generator parses all files
// given from the command line
int main(int argc, char** argv)
{
cout << "C++/JAVA Source Documentation Generator (\"wxDocRipper\")" << endl
<< "(C) 1998, Aleksandras Gluchovas (mailto:alex@soften.ktu.lt)"
<< endl << endl;
if ( argc < 2 )
{
cout << "Usage: list of files with .h, .hpp, .cpp or .java extentions"
<< endl;
return 1;
}
int from = 1, no_dump = 0;
if ( strcmp( argv[1], "-x" ) == 0 )
{
from = 2;
no_dump = 1;
}
RipperDocGen gen;
// set up target script
gen.SetScriptMarkupTags( get_HTML_markup_tags() );
// setup source langauge
CJSourceParser* pParser = new CJSourceParser();
gen.Init( pParser );
for( int i = from; i != argc; ++i )
gen.ProcessFile( argv[i] );
if ( !no_dump )
{
cout << endl
<< "*** storing source documenation into ./srcref.html ***"
<< endl << endl;
if ( !gen.SaveDocument( "srcref.html" ) )
cout << "\nERROR: document cannot be saved" << endl;
}
printf( "\nTotal %d file(s) processed, done.\n", argc-from );
return 0;
}
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+31
View File
@@ -0,0 +1,31 @@
////////////////////
//
// craeted by Alex
//
////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include <memory.h>
#ifndef WX_PRECOMP
#include "wx/defs.h"
#endif
char *
copystring (const char *s)
{
if (s == NULL) s = "";
size_t len = strlen (s) + 1;
char *news = new char[len];
memcpy (news, s, len); // Should be the fastest
return news;
}
const char *wxGetTranslation(const char *str)
{
return str;
}