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
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;
}