X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d5939a20fd8f506225296ebe7de0180c7adb088e..d77836e48cf1a0f7575cd1ce66f59f5bc07e5b56:/utils/HelpGen/src/ifcontext.cpp diff --git a/utils/HelpGen/src/ifcontext.cpp b/utils/HelpGen/src/ifcontext.cpp index 295aab86dc..12caefa20a 100644 --- a/utils/HelpGen/src/ifcontext.cpp +++ b/utils/HelpGen/src/ifcontext.cpp @@ -6,13 +6,9 @@ // Created: 27/12/98 // RCS-ID: $Id$ // Copyright: (c) Aleskandars Gluchovas -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -# pragma implementation "ifcontext.h" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -33,24 +29,27 @@ /***** Implementation for class spInterFileContext *****/ -size_t spInterFileContext::GetFileNo( const string& fname ) +size_t spInterFileContext::GetFileNo( const wxString& fname ) { - for( size_t i = 0; i != mFiles.size(); ++i ) + for ( size_t i = 0; i != m_Files.size(); ++i ) + { + if ( fname == m_Files[i] ) + return i; + } - if ( fname == mFiles[i] ) return i; + wxFAIL_MSG("File not found in array in function spInterFileContext::GetFileNo()"); - wxASSERT(0); // DBG:: - return 0; + return 0; } size_t spInterFileContext::GetFileNoOfContext( spContext& ctx ) { - spContext* pCtx = ctx.GetEnclosingContext( SP_CTX_FILE ); + spContext* pCtx = ctx.GetEnclosingContext( SP_CTX_FILE ); - // DBG:: outer-file context should be present - wxASSERT( pCtx && pCtx->GetType() == SP_CTX_FILE ); + // DBG:: outer-file context should be present + wxASSERT( pCtx && pCtx->GetType() == SP_CTX_FILE ); - return GetFileNo( ((spFile*)pCtx)->mFileName ); + return GetFileNo( ((spFile*)pCtx)->m_FileName ); } /*** public interface ***/ @@ -61,236 +60,234 @@ spInterFileContext::spInterFileContext() spInterFileContext::~spInterFileContext() {} -void spInterFileContext::AddFile( const string& fname, const string& content ) +void spInterFileContext::AddFile( const wxString& fname, const wxString& content ) { - mFiles.push_back( fname ); - mContents.push_back( content ); + m_Files.push_back( fname ); + m_Contents.push_back( content ); } void spInterFileContext::RemoveContext( spContext& ctx ) { - wxASSERT( ctx.PositionIsKnown() ); // DBG:: should be checked by-user code + wxASSERT( ctx.PositionIsKnown() ); // DBG:: should be checked by-user code - size_t fNo = GetFileNoOfContext( ctx ); + size_t fNo = GetFileNoOfContext( ctx ); - mDeletionMarks.push_back( spBookmark( ctx.mSrcOffset, ctx.mContextLength, fNo ) ); + 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 ) + 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( wxString& source, + wxString& result, + size_t pos, size_t len ) { - mFiltered.erase( mFiltered.begin(), mFiltered.end() ); + mFiltered.erase( mFiltered.begin(), mFiltered.end() ); + + size_t i; - size_t i; + for( i = 0; i != mDeletionMarks.size(); ++i ) + { + spBookmark& mark = mDeletionMarks[i]; - for( i = 0; i != mDeletionMarks.size(); ++i ) - { - spBookmark& mark = mDeletionMarks[i]; + if ( mark.mFileNo == mCurFileNo && + mark.mFrom >= pos && mark.mFrom < pos + len ) - if ( mark.mFileNo == mCurFileNo && - mark.mFrom >= pos && mark.mFrom < pos + len ) - - InsertBookmarkSorted( mFiltered, mark ); - } + InsertBookmarkSorted( mFiltered, mark ); + } - size_t cur = pos; - - for( i = 0; i != mFiltered.size(); ++ i ) - { - spBookmark& mark = mFiltered[i]; + size_t cur = pos; - result.append( source, cur, ( (size_t)mark.mFrom - cur ) ); + for( i = 0; i != mFiltered.size(); ++ i ) + { + spBookmark& mark = mFiltered[i]; - cur = size_t( mark.mFrom + mark.mLen ); + result.append( source, cur, ( (size_t)mark.mFrom - cur ) ); - 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; - } - } + cur = size_t( mark.mFrom + mark.mLen ); - result.append( source, cur, ( pos + len ) - cur ); + if ( cur >= pos + len ) // check if we've overstepped the current source-fragment + { +// wxASSERT(0); // DBG:: with current imp. this should not happen + wxFAIL_MSG("Overstepped the current source fragment in function\nspInterFileContext::DoAppendSourceFragment()"); + 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 ) +void spInterFileContext::GenerateContextBody( spContext& ctx, + wxString& source, + wxString& result, + size_t& lastSavedPos, + size_t& lastKnownPos ) { - if ( ctx.PositionIsKnown() ) - - lastKnownPos = ctx.mSrcOffset; + if ( ctx.PositionIsKnown() ) + lastKnownPos = ctx.mSrcOffset; - if ( ctx.IsVirtualContext() ) - { - // add fragment accumulated before this context + if ( ctx.IsVirtualContext() ) + { + // add fragment accumulated before this context - DoAppendSourceFragment( source, result, - size_t(lastSavedPos), - size_t(lastKnownPos - lastSavedPos) ); + DoAppendSourceFragment( source, result, + size_t(lastSavedPos), + size_t(lastKnownPos - lastSavedPos) ); - // add context body + // add context body - result += ctx.GetVirtualContextBody(); + result += ctx.GetVirtualContextBody(); - lastSavedPos = lastKnownPos; + lastSavedPos = lastKnownPos; - if ( ctx.PositionIsKnown() ) - { - if ( ctx.VitualContextHasChildren() ) - { - lastKnownPos = ctx.mSrcOffset + ctx.mHeaderLength; + if ( ctx.PositionIsKnown() ) + { + if ( ctx.VitualContextHasChildren() ) + { + lastKnownPos = ctx.mSrcOffset + ctx.mHeaderLength; - lastSavedPos = lastKnownPos; - } - else - { - lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; + lastSavedPos = lastKnownPos; + } + else + { + lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; - lastSavedPos = lastKnownPos; + lastSavedPos = lastKnownPos; - return; // have not children - } - } - } + return; // have not children + } + } + } - MMemberListT& lst = ctx.GetMembers(); + 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() && + for( size_t i = 0; i != lst.size(); ++i ) + { + GenerateContextBody( *lst[i], source, result, lastSavedPos, lastKnownPos ); + } - ctx.GetFooterOfVirtualContextBody() != "" ) - { - // append the reminder space after children of the context + if ( ctx.IsVirtualContext() ) + { + if ( ctx.VitualContextHasChildren() && !ctx.GetFooterOfVirtualContextBody().empty() ) + { + // append the reminder space after children of the context - DoAppendSourceFragment( result, source, - size_t(lastSavedPos), - size_t(lastKnownPos - lastSavedPos) ); + DoAppendSourceFragment( result, source, + size_t(lastSavedPos), + size_t(lastKnownPos - lastSavedPos) ); - // add footer - result += ctx.GetFooterOfVirtualContextBody(); + // add footer + result += ctx.GetFooterOfVirtualContextBody(); - lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; + lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; - lastSavedPos = lastKnownPos; - } - } + lastSavedPos = lastKnownPos; + } + } - if ( ctx.PositionIsKnown() ) + if ( ctx.PositionIsKnown() ) - lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; + lastKnownPos = ctx.mSrcOffset + ctx.mContextLength; } void spInterFileContext::GenrateContents() { - MMemberListT& lst = GetMembers(); + MMemberListT& lst = GetMembers(); - for( size_t f = 0; f != lst.size(); ++f ) - { - string& fname = ((spFile*)lst[f])->mFileName; + for( size_t f = 0; f != lst.size(); ++f ) + { + wxString& fname = ((spFile*)lst[f])->m_FileName; - size_t fileNo = GetFileNo( fname ); + size_t fileNo = GetFileNo( fname ); - string& source = mContents[ fileNo ]; + wxString& source = m_Contents[ fileNo ]; - string result; + wxString result; - size_t lastKnownPos = 0, // the begining of the file is always "known" - lastSavedPos = 0; + size_t lastKnownPos = 0, // the begining of the file is always "known" + lastSavedPos = 0; - mCurFileNo = fileNo; + mCurFileNo = fileNo; - GenerateContextBody( *lst[f], source, result, lastSavedPos, lastKnownPos ); + GenerateContextBody( *lst[f], source, result, lastSavedPos, lastKnownPos ); - // the end of file is always known + // the end of file is always known - lastKnownPos = mContents[ fileNo ].length(); + lastKnownPos = m_Contents[ fileNo ].length(); - // append the reminder + // append the reminder - DoAppendSourceFragment( source, result, - size_t(lastSavedPos), - size_t(lastKnownPos - lastSavedPos) ); + DoAppendSourceFragment( source, result, + size_t(lastSavedPos), + size_t(lastKnownPos - lastSavedPos) ); - // replace original contnet with newly generated one + // replace original contnet with newly generated one - mContents[ fileNo ] = result; - } + m_Contents[ fileNo ] = result; + } } void spInterFileContext::ParseContents( SourceParserPlugin* pPlugin ) { - mDeletionMarks.erase( mDeletionMarks.begin(), mDeletionMarks.end() ); + mDeletionMarks.erase( mDeletionMarks.begin(), mDeletionMarks.end() ); - RemoveChildren(); // clean up top-level context + RemoveChildren(); // clean up top-level context - mParser.SetPlugin( pPlugin ); + mParser.SetPlugin( pPlugin ); - for( size_t i = 0; i != mFiles.size(); ++i ) - { - char* s = (char*)(mContents[i].c_str()); + for( size_t i = 0; i != m_Files.size(); ++i ) + { + wxChar* s = (char*)(m_Contents[i].c_str()); - spFile* pFCtx = mParser.Parse( s, s + mContents[i].length() ); + spFile* pFCtx = mParser.Parse( s, s + m_Contents[i].length() ); - pFCtx->mFileName = mFiles[i]; + pFCtx->m_FileName = m_Files[i]; - AddMember( pFCtx ); - } + AddMember( pFCtx ); + } } void spInterFileContext::WriteToFiles() { - for( size_t i = 0; i != mFiles.size(); ++i ) - { - FILE* fp = fopen( mFiles[i].c_str(), "w+t" ); + for( size_t i = 0; i != m_Files.size(); ++i ) + { + FILE* fp = fopen( m_Files[i].c_str(), "w+t" ); - if ( int(fp) > 0 ) - { - fwrite( mContents[i].c_str(), sizeof(char), mContents[i].length(), fp ); + if ( fp != NULL ) + { + fwrite( m_Contents[i].c_str(), sizeof(char), m_Contents[i].length(), fp ); - fclose( fp ); - } - } + fclose( fp ); + } + } } -string spInterFileContext::GetBody( spContext* pCtx ) +wxString spInterFileContext::GetBody( spContext* pCtx ) { - wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code + wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code - string& source = mContents[ GetFileNoOfContext( *pCtx ) ]; + wxString& source = m_Contents[ GetFileNoOfContext( *pCtx ) ]; - return string( source.c_str() + pCtx->mSrcOffset, pCtx->mContextLength ); + return wxString( source.c_str() + pCtx->mSrcOffset, pCtx->mContextLength ); } -string spInterFileContext::GetHeader( spContext* pCtx ) +wxString spInterFileContext::GetHeader( spContext* pCtx ) { - wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code + wxASSERT( pCtx->PositionIsKnown() ); // DBG:: should be checked by-user code - wxASSERT( pCtx->mHeaderLength != -1 ); // DBG:: -/- + wxASSERT( pCtx->mHeaderLength != -1 ); // DBG:: -/- - string& source = mContents[ GetFileNoOfContext( *pCtx ) ]; + wxString& source = m_Contents[ GetFileNoOfContext( *pCtx ) ]; - return string( source.c_str() + pCtx->mSrcOffset, pCtx->mHeaderLength ); + return wxString( source.c_str() + pCtx->mSrcOffset, pCtx->mHeaderLength ); }