basctl/source/basicide/baside2b.cxx | 4 helpcompiler/Library_helplinker.mk | 9 helpcompiler/Package_inc.mk | 1 helpcompiler/inc/BasCodeTagger.hxx | 56 ++++++ helpcompiler/inc/HelpCompiler.hxx | 7 helpcompiler/source/BasCodeTagger.cxx | 236 ++++++++++++++++++++++++++ helpcompiler/source/HelpCompiler.cxx | 56 +++++- helpcompiler/source/HelpLinker.cxx | 2 svtools/inc/svtools/syntaxhighlight.hxx | 8 svtools/source/edit/editsyntaxhighlighter.cxx | 2 svtools/source/edit/syntaxhighlight.cxx | 235 ++++++------------------- 11 files changed, 423 insertions(+), 193 deletions(-)
New commits: commit b6eed8596485380484245a77344ad9a3bd476a73 Author: Andras Timar <ati...@suse.com> Date: Tue Feb 12 22:47:06 2013 +0100 fix a Basic keyword in syntax highlighter: withevent -> withevents Change-Id: I47b527ad6e68dba83ebb253bcc55a2717c7dd0ca diff --git a/svtools/source/edit/syntaxhighlight.cxx b/svtools/source/edit/syntaxhighlight.cxx index 8d33ac3..920bac5 100644 --- a/svtools/source/edit/syntaxhighlight.cxx +++ b/svtools/source/edit/syntaxhighlight.cxx @@ -152,7 +152,7 @@ static const char* strListBasicKeyWords[] = { "wend", "while", "with", - "withevent", + "withevents", "write", "xor" }; commit 67b8c0339e90c42dca402a925a624fce67f8ea5c Author: Andras Timar <ati...@suse.com> Date: Tue Feb 12 22:32:53 2013 +0100 fdo#41737 syntax highlighting of Basic code examples in offline help Change-Id: I7dc5b189e98a0351bac0eab28c1161b5893f5ef1 diff --git a/helpcompiler/inc/BasCodeTagger.hxx b/helpcompiler/inc/BasCodeTagger.hxx index 3cf9261..9ff376a 100644 --- a/helpcompiler/inc/BasCodeTagger.hxx +++ b/helpcompiler/inc/BasCodeTagger.hxx @@ -34,7 +34,6 @@ class L10N_DLLPUBLIC BasicCodeTagger BasicCodeTagger( xmlDocPtr rootDoc ); ~BasicCodeTagger(); void tagBasicCodes(); - void saveTreeToFile( const std::string& filePath, const std::string& encoding ); }; //================LibXmlTreeWalker=========================================================== diff --git a/helpcompiler/inc/HelpCompiler.hxx b/helpcompiler/inc/HelpCompiler.hxx index 034a629..8a5dda1 100644 --- a/helpcompiler/inc/HelpCompiler.hxx +++ b/helpcompiler/inc/HelpCompiler.hxx @@ -245,7 +245,8 @@ public: const std::string &entryName, const Hashtable &bytesToAdd); private: xmlDocPtr getSourceDocument(const fs::path &filePath); - void sourceDocumentPreWorks( xmlDocPtr doc , const fs::path &filePath); + void tagBasicCodeExamples(xmlDocPtr doc); + void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath); xmlNodePtr clone(xmlNodePtr node, const std::string& appl); StreamTable &streamTable; const fs::path inputFile, src, zipdir; diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index 339d96b..5852912 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -137,15 +137,9 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) } //3. create new paragraph content - String strLine( - OUString( - reinterpret_cast<const sal_Char*>(codeSnippet), - strlen( - reinterpret_cast<const char*>(codeSnippet) - ), - RTL_TEXTENCODING_UTF8 - ) - ) ; + OUString strLine( reinterpret_cast<const sal_Char*>(codeSnippet), + strlen(reinterpret_cast<const char*>(codeSnippet)), + RTL_TEXTENCODING_UTF8 ); m_Highlighter.notifyChange ( 0, 0, &strLine, 1 ); HighlightPortions portions; m_Highlighter.getHighlightPortions( 0, strLine, portions ); @@ -155,7 +149,7 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) for ( size_t i=0; i<portions.size(); i++ ) { HighlightPortion& r = portions[i]; - subStr = xmlStrsub( codeSnippet, r.nBegin, r.nEnd-r.nBegin ); + subStr = (xmlChar*) OUStringToOString( strLine.copy( r.nBegin, r.nEnd-r.nBegin ), RTL_TEXTENCODING_UTF8 ).getStr(); text = xmlNewText( subStr ); if ( r.tokenType != TT_WHITESPACE ) { @@ -185,7 +179,7 @@ void BasicCodeTagger::tagBasicCodes() { getBasicCodeContainerNodes(); } - catch (TaggerException ex) + catch (TaggerException &ex) { std::cout << "BasCodeTagger error occured. Error code:" << ex << std::endl; } @@ -229,7 +223,7 @@ xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) str = "operator"; break; case TT_KEYWORDS : - str = "keywords"; + str = "keyword"; break; case TT_PARAMETER : str = "parameter"; @@ -240,12 +234,3 @@ xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) } return xmlCharStrdup( str ); } - -//! Saves the current xml DOM to file with the provided libxml2 encoding string in an unformatted way. -void BasicCodeTagger::saveTreeToFile( const std::string& filePath, const std::string& encoding ) -{ - //saveDocument - int ret = xmlSaveFormatFileEnc( filePath.c_str(), m_pDocument, encoding.c_str(), 0 ); - if ( ret == -1 ) - throw FILE_WRITING; -} diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index 8c6f66b..3983f16 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -54,41 +54,50 @@ HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_input } } -void HelpCompiler::sourceDocumentPreWorks( xmlDocPtr doc, const fs::path &filePath ) +void HelpCompiler::tagBasicCodeExamples( xmlDocPtr doc ) { - if ( doc ) + try { - if ( module == "sbasic" ) - { - try - { - BasicCodeTagger bct( doc ); - bct.tagBasicCodes(); - } - catch ( BasicCodeTagger::TaggerException ex ) - { - if ( ex != BasicCodeTagger::EMPTY_DOCUMENT ) - throw; - } - //save document in ziptmp<modul>_<lang>/text directory - //1. construct new path - const std::string& pth = filePath.native_file_string(); - std::string sourceNativeXhpPath = pth.substr( pth.rfind( lang+"/text/" ) ).substr( lang.length() ); - std::string xhpFileName = sourceNativeXhpPath.substr( sourceNativeXhpPath.rfind( '/' ) + 1 ); - sourceNativeXhpPath = sourceNativeXhpPath.substr( 0, sourceNativeXhpPath.rfind( '/' ) ); - //2. save xml doc with the new path - // -create directory hierachy - fs::create_directory( fs::path( zipdir.native_file_string() + sourceNativeXhpPath, fs::native ) ); - // -save document - if ( -1 == xmlSaveFormatFileEnc( (zipdir.native_file_string() + sourceNativeXhpPath + '/' + xhpFileName).c_str(), doc, "utf-8", 0 ) ) - throw BasicCodeTagger::FILE_WRITING; - } + BasicCodeTagger bct( doc ); + bct.tagBasicCodes(); + } + catch ( BasicCodeTagger::TaggerException &ex ) + { + if ( ex != BasicCodeTagger::EMPTY_DOCUMENT ) + throw; } } +void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) +{ + //save processed xhp document in ziptmp<module>_<lang>/text directory +#ifdef WNT + std::string pathSep = "\\"; +#else + std::string pathSep = "/"; +#endif + const std::string& sourceXhpPath = filePath.native_file_string(); + std::string zipdirPath = zipdir.native_file_string(); + std::string jarXhpPath = sourceXhpPath.substr( sourceXhpPath.rfind( lang + pathSep + "text" + pathSep ) ).substr( lang.length() ); + std::string xhpFileName = jarXhpPath.substr( jarXhpPath.rfind( pathSep ) + 1 ); + jarXhpPath = jarXhpPath.substr( 0, jarXhpPath.rfind( pathSep ) ); + if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "sbasic" ) ) + { + tagBasicCodeExamples( doc ); + } + if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "shared" ) ) + { + size_t pos = zipdirPath.find( "ziptmp" ) + 6; + zipdirPath.replace( pos, module.length(), "shared" ); + } + fs::create_directory( fs::path( zipdirPath + jarXhpPath, fs::native ) ); + if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), doc, "utf-8", 0 ) ) + std::cerr << "Error saving file to " << (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str() << std::endl; +} + + xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) { - static const char *params[4 + 1]; static xsltStylesheetPtr cur = NULL; xmlDocPtr res; @@ -99,22 +108,19 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); res = xmlParseFile(filePath.native_file_string().c_str()); } - sourceDocumentPreWorks( res, filePath ); } else { + static const char *params[2 + 1]; if (!cur) { static std::string fsroot('\'' + src.toUTF8() + '\''); - static std::string esclang('\'' + lang + '\''); xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; cur = xsltParseStylesheetFile((const xmlChar *)resEmbStylesheet.native_file_string().c_str()); int nbparams = 0; - params[nbparams++] = "Language"; - params[nbparams++] = esclang.c_str(); params[nbparams++] = "fsroot"; params[nbparams++] = fsroot.c_str(); params[nbparams] = NULL; @@ -125,8 +131,8 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); doc = xmlParseFile(filePath.native_file_string().c_str()); } - sourceDocumentPreWorks( doc, filePath ); - //???res = xmlParseFile(filePath.native_file_string().c_str()); + + saveXhpForJar( doc, filePath ); res = xsltApplyStylesheet(cur, doc, params); xmlFreeDoc(doc); commit fb1f3db03df25bee8b17a85e26774e79483de791 Author: Andras Timar <ati...@suse.com> Date: Tue Feb 12 22:29:33 2013 +0100 String to OUString Change-Id: Ibb0b1808532622ffb2dfc55d533428f6d72b890c diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index bbb7baf..b2a0182 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -787,7 +787,7 @@ void EditorWindow::ImpDoHighlight( sal_uLong nLine ) { if ( bDoSyntaxHighlight ) { - String aLine( pEditEngine->GetText( nLine ) ); + OUString aLine( pEditEngine->GetText( nLine ) ); Range aChanges = aHighlighter.notifyChange( nLine, 0, &aLine, 1 ); if ( aChanges.Len() ) { @@ -935,7 +935,7 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, bool bInserted ) if ( bDoSyntaxHighlight ) { - String aDummy; + OUString aDummy; aHighlighter.notifyChange( nPara, bInserted ? 1 : (-1), &aDummy, 1 ); } } diff --git a/svtools/inc/svtools/syntaxhighlight.hxx b/svtools/inc/svtools/syntaxhighlight.hxx index 33d9149..60e917d 100644 --- a/svtools/inc/svtools/syntaxhighlight.hxx +++ b/svtools/inc/svtools/syntaxhighlight.hxx @@ -131,8 +131,8 @@ public: SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); ~SimpleTokenizer_Impl( void ); - sal_uInt16 parseLine( sal_uInt32 nLine, const String* aSource ); - void getHighlightPortions( sal_uInt32 nParseLine, const String& rLine, + sal_uInt16 parseLine( sal_uInt32 nLine, const OUString* aSource ); + void getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, /*out*/HighlightPortions& portions ); void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); }; @@ -165,9 +165,9 @@ public: void initialize( HighlighterLanguage eLanguage_ ); const Range notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, - const String* pChangedLines, sal_uInt32 nArrayLength); + const OUString* pChangedLines, sal_uInt32 nArrayLength); - void getHighlightPortions( sal_uInt32 nLine, const String& rLine, + void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, HighlightPortions& pPortions ); HighlighterLanguage GetLanguage() { return eLanguage;} diff --git a/svtools/source/edit/editsyntaxhighlighter.cxx b/svtools/source/edit/editsyntaxhighlighter.cxx index af68d05..62a7a25 100644 --- a/svtools/source/edit/editsyntaxhighlighter.cxx +++ b/svtools/source/edit/editsyntaxhighlighter.cxx @@ -167,7 +167,7 @@ void MultiLineEditSyntaxHighlight::UpdateData() sal_Bool bTempModified = GetTextEngine()->IsModified(); for (unsigned int nLine=0; nLine < GetTextEngine()->GetParagraphCount(); nLine++) { - String aLine( GetTextEngine()->GetText( nLine ) ); + OUString aLine( GetTextEngine()->GetText( nLine ) ); aHighlighter.notifyChange( nLine, 0, &aLine, 1 ); GetTextEngine()->RemoveAttribs( nLine, sal_True ); diff --git a/svtools/source/edit/syntaxhighlight.cxx b/svtools/source/edit/syntaxhighlight.cxx index 0d261d6..8d33ac3 100644 --- a/svtools/source/edit/syntaxhighlight.cxx +++ b/svtools/source/edit/syntaxhighlight.cxx @@ -636,10 +636,10 @@ SimpleTokenizer_Impl* getSimpleTokenizer( void ) return pSimpleTokenizer; } -sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const String* aSource ) +sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const OUString* aSource ) { // Set the position to the beginning of the source string - mpStringBegin = mpActualPos = aSource->GetBuffer(); + mpStringBegin = mpActualPos = aSource->getStr(); // Initialize row and column nLine = nParseLine; @@ -658,11 +658,11 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const String* return nTokenCount; } -void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const String& rLine, +void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, /*out*/HighlightPortions& portions ) { // Set the position to the beginning of the source string - mpStringBegin = mpActualPos = rLine.GetBuffer(); + mpStringBegin = mpActualPos = rLine.getStr(); // Initialize row and column nLine = nParseLine; @@ -722,7 +722,7 @@ void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) } const Range SyntaxHighlighter::notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, - const String* pChangedLines, sal_uInt32 nArrayLength) + const OUString* pChangedLines, sal_uInt32 nArrayLength) { (void)nLineCountDifference; @@ -732,7 +732,7 @@ const Range SyntaxHighlighter::notifyChange( sal_uInt32 nLine, sal_Int32 nLineCo return Range( nLine, nLine + nArrayLength-1 ); } -void SyntaxHighlighter::getHighlightPortions( sal_uInt32 nLine, const String& rLine, +void SyntaxHighlighter::getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, /*out*/HighlightPortions& portions ) { m_pSimpleTokenizer->getHighlightPortions( nLine, rLine, portions ); commit d25486b5a909ff2b3bdd6369dba035ec8df4dff6 Author: Andras Timar <ati...@suse.com> Date: Tue Feb 12 15:49:31 2013 +0100 remove rtl:: prefix Change-Id: I6b2c51c57a98046e30b2782dd2565ee02345379d diff --git a/svtools/source/edit/syntaxhighlight.cxx b/svtools/source/edit/syntaxhighlight.cxx index ce3fcf1..0d261d6 100644 --- a/svtools/source/edit/syntaxhighlight.cxx +++ b/svtools/source/edit/syntaxhighlight.cxx @@ -318,8 +318,8 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, if( bCanBeKeyword ) { - rtl::OUString aKWString(rpStartPos, nCount); - rtl::OString aByteStr = rtl::OUStringToOString(aKWString, + OUString aKWString(rpStartPos, nCount); + OString aByteStr = OUStringToOString(aKWString, RTL_TEXTENCODING_ASCII_US).toAsciiLowerCase(); if ( bsearch( aByteStr.getStr(), ppListKeyWords, nKeyWordCount, sizeof( char* ), compare_strings ) ) commit 6e4fd7ba9f4a02e130e817aadf0b977b8b8b6262 Author: Andras Timar <ati...@suse.com> Date: Tue Feb 12 15:39:09 2013 +0100 use u_isalpha() from ICU instead of home-grown solution plus German comments were translated Change-Id: Id9ff5d4835e4ea224c9e6232a1762822aa833d37 diff --git a/svtools/source/edit/syntaxhighlight.cxx b/svtools/source/edit/syntaxhighlight.cxx index 7db7b72..ce3fcf1 100644 --- a/svtools/source/edit/syntaxhighlight.cxx +++ b/svtools/source/edit/syntaxhighlight.cxx @@ -18,13 +18,12 @@ */ +#include <unicode/uchar.h> #include <svtools/syntaxhighlight.hxx> - -#include <unotools/charclass.hxx> #include <comphelper/string.hxx> // ########################################################################## -// ATTENTION: all these words needs to be in small caps +// ATTENTION: all these words need to be in lower case // ########################################################################## static const char* strListBasicKeyWords[] = { "access", @@ -232,111 +231,15 @@ extern "C" int CDECL compare_strings( const void *arg1, const void *arg2 ) namespace { - - class LetterTable - { - bool IsLetterTab[256]; - - public: - LetterTable( void ); - - inline bool isLetter( sal_Unicode c ) - { - bool bRet = (c < 256) ? IsLetterTab[c] : isLetterUnicode( c ); - return bRet; - } - bool isLetterUnicode( sal_Unicode c ); - }; - static bool isAlpha(sal_Unicode c) { if (comphelper::string::isalphaAscii(c)) return true; - static LetterTable aLetterTable; - return aLetterTable.isLetter(c); + return u_isalpha(c); } } -LetterTable::LetterTable( void ) -{ - for( int i = 0 ; i < 256 ; ++i ) - IsLetterTab[i] = false; - - IsLetterTab[0xC0] = true; // ?, CAPITAL LETTER A WITH GRAVE ACCENT - IsLetterTab[0xC1] = true; // ?, CAPITAL LETTER A WITH ACUTE ACCENT - IsLetterTab[0xC2] = true; // ?, CAPITAL LETTER A WITH CIRCUMFLEX ACCENT - IsLetterTab[0xC3] = true; // ?, CAPITAL LETTER A WITH TILDE - IsLetterTab[0xC4] = true; // ?, CAPITAL LETTER A WITH DIAERESIS - IsLetterTab[0xC5] = true; // ?, CAPITAL LETTER A WITH RING ABOVE - IsLetterTab[0xC6] = true; // ?, CAPITAL LIGATURE AE - IsLetterTab[0xC7] = true; // ?, CAPITAL LETTER C WITH CEDILLA - IsLetterTab[0xC8] = true; // ?, CAPITAL LETTER E WITH GRAVE ACCENT - IsLetterTab[0xC9] = true; // ?, CAPITAL LETTER E WITH ACUTE ACCENT - IsLetterTab[0xCA] = true; // ?, CAPITAL LETTER E WITH CIRCUMFLEX ACCENT - IsLetterTab[0xCB] = true; // ?, CAPITAL LETTER E WITH DIAERESIS - IsLetterTab[0xCC] = true; // ?, CAPITAL LETTER I WITH GRAVE ACCENT - IsLetterTab[0xCD] = true; // ?, CAPITAL LETTER I WITH ACUTE ACCENT - IsLetterTab[0xCE] = true; // ?, CAPITAL LETTER I WITH CIRCUMFLEX ACCENT - IsLetterTab[0xCF] = true; // ?, CAPITAL LETTER I WITH DIAERESIS - IsLetterTab[0xD0] = true; // ?, CAPITAL LETTER ETH - IsLetterTab[0xD1] = true; // ?, CAPITAL LETTER N WITH TILDE - IsLetterTab[0xD2] = true; // ?, CAPITAL LETTER O WITH GRAVE ACCENT - IsLetterTab[0xD3] = true; // ?, CAPITAL LETTER O WITH ACUTE ACCENT - IsLetterTab[0xD4] = true; // ?, CAPITAL LETTER O WITH CIRCUMFLEX ACCENT - IsLetterTab[0xD5] = true; // ?, CAPITAL LETTER O WITH TILDE - IsLetterTab[0xD6] = true; // ?, CAPITAL LETTER O WITH DIAERESIS - IsLetterTab[0xD8] = true; // ?, CAPITAL LETTER O WITH STROKE - IsLetterTab[0xD9] = true; // ?, CAPITAL LETTER U WITH GRAVE ACCENT - IsLetterTab[0xDA] = true; // ?, CAPITAL LETTER U WITH ACUTE ACCENT - IsLetterTab[0xDB] = true; // ?, CAPITAL LETTER U WITH CIRCUMFLEX ACCENT - IsLetterTab[0xDC] = true; // ?, CAPITAL LETTER U WITH DIAERESIS - IsLetterTab[0xDD] = true; // ?, CAPITAL LETTER Y WITH ACUTE ACCENT - IsLetterTab[0xDE] = true; // ?, CAPITAL LETTER THORN - IsLetterTab[0xDF] = true; // ?, SMALL LETTER SHARP S - IsLetterTab[0xE0] = true; // ?, SMALL LETTER A WITH GRAVE ACCENT - IsLetterTab[0xE1] = true; // ?, SMALL LETTER A WITH ACUTE ACCENT - IsLetterTab[0xE2] = true; // ?, SMALL LETTER A WITH CIRCUMFLEX ACCENT - IsLetterTab[0xE3] = true; // ?, SMALL LETTER A WITH TILDE - IsLetterTab[0xE4] = true; // ?, SMALL LETTER A WITH DIAERESIS - IsLetterTab[0xE5] = true; // ?, SMALL LETTER A WITH RING ABOVE - IsLetterTab[0xE6] = true; // ?, SMALL LIGATURE AE - IsLetterTab[0xE7] = true; // ?, SMALL LETTER C WITH CEDILLA - IsLetterTab[0xE8] = true; // ?, SMALL LETTER E WITH GRAVE ACCENT - IsLetterTab[0xE9] = true; // ?, SMALL LETTER E WITH ACUTE ACCENT - IsLetterTab[0xEA] = true; // ?, SMALL LETTER E WITH CIRCUMFLEX ACCENT - IsLetterTab[0xEB] = true; // ?, SMALL LETTER E WITH DIAERESIS - IsLetterTab[0xEC] = true; // ?, SMALL LETTER I WITH GRAVE ACCENT - IsLetterTab[0xED] = true; // ?, SMALL LETTER I WITH ACUTE ACCENT - IsLetterTab[0xEE] = true; // ?, SMALL LETTER I WITH CIRCUMFLEX ACCENT - IsLetterTab[0xEF] = true; // ?, SMALL LETTER I WITH DIAERESIS - IsLetterTab[0xF0] = true; // ?, SMALL LETTER ETH - IsLetterTab[0xF1] = true; // ?, SMALL LETTER N WITH TILDE - IsLetterTab[0xF2] = true; // ?, SMALL LETTER O WITH GRAVE ACCENT - IsLetterTab[0xF3] = true; // ?, SMALL LETTER O WITH ACUTE ACCENT - IsLetterTab[0xF4] = true; // ?, SMALL LETTER O WITH CIRCUMFLEX ACCENT - IsLetterTab[0xF5] = true; // ?, SMALL LETTER O WITH TILDE - IsLetterTab[0xF6] = true; // ?, SMALL LETTER O WITH DIAERESIS - IsLetterTab[0xF8] = true; // ?, SMALL LETTER O WITH OBLIQUE BAR - IsLetterTab[0xF9] = true; // ?, SMALL LETTER U WITH GRAVE ACCENT - IsLetterTab[0xFA] = true; // ?, SMALL LETTER U WITH ACUTE ACCENT - IsLetterTab[0xFB] = true; // ?, SMALL LETTER U WITH CIRCUMFLEX ACCENT - IsLetterTab[0xFC] = true; // ?, SMALL LETTER U WITH DIAERESIS - IsLetterTab[0xFD] = true; // ?, SMALL LETTER Y WITH ACUTE ACCENT - IsLetterTab[0xFE] = true; // ?, SMALL LETTER THORN - IsLetterTab[0xFF] = true; // � , SMALL LETTER Y WITH DIAERESIS -} - -bool LetterTable::isLetterUnicode( sal_Unicode c ) -{ - static CharClass* pCharClass = NULL; - if( pCharClass == NULL ) - pCharClass = new CharClass( Application::GetSettings().GetLanguageTag() ); - rtl::OUString aStr( c ); - bool bRet = pCharClass->isLetter( aStr, 0 ); - return bRet; -} - -// Hilfsfunktion: Zeichen-Flag Testen +// Helper function: test character flag sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ) { bool bRet = false; @@ -358,24 +261,20 @@ void SimpleTokenizer_Impl::setKeyWords( const char** ppKeyWords, sal_uInt16 nCou nKeyWordCount = nCount; } -// Neues Token holen sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ) { reType = TT_UNKNOWN; - // Position merken rpStartPos = mpActualPos; - // Zeichen untersuchen sal_Unicode c = peekChar(); if( c == CHAR_EOF ) return sal_False; - // Zeichen lesen getChar(); - //*** Alle Moeglichkeiten durchgehen *** + //*** Go through all possibilities *** // Space? if ( (testCharFlags( c, CHAR_SPACE ) == sal_True) ) { @@ -401,7 +300,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, reType = TT_IDENTIFIER; - // Schluesselwort-Tabelle + // Keyword table if (ppListKeyWords != NULL) { int nCount = mpActualPos - rpStartPos; @@ -429,7 +328,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, if (aByteStr.equalsL(RTL_CONSTASCII_STRINGPARAM("rem"))) { - // Alle Zeichen bis Zeilen-Ende oder EOF entfernen + // Remove all characters until end of line or EOF sal_Unicode cPeek = peekChar(); while( cPeek != CHAR_EOF && testCharFlags( cPeek, CHAR_EOL ) == sal_False ) { @@ -456,7 +355,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, sal_Bool bIdentifierChar; do { - // Naechstes Zeichen holen + // Get next character c = peekChar(); bIdentifierChar = isAlpha(c); if( bIdentifierChar ) @@ -471,7 +370,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, sal_Unicode cPeekNext = peekChar(); if (cPeekNext=='-') { - // Alle Zeichen bis Zeilen-Ende oder EOF entfernen + // Remove all characters until end of line or EOF while( cPeekNext != CHAR_EOF && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False ) { getChar(); @@ -485,7 +384,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, sal_Unicode cPeekNext = peekChar(); if (cPeekNext=='/') { - // Alle Zeichen bis Zeilen-Ende oder EOF entfernen + // Remove all characters until end of line or EOF while( cPeekNext != CHAR_EOF && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False ) { getChar(); @@ -496,12 +395,12 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, } else { - // Kommentar ? + // Comment? if ( c == '\'' ) { - c = getChar(); // '/' entfernen + c = getChar(); - // Alle Zeichen bis Zeilen-Ende oder EOF entfernen + // Remove all characters until end of line or EOF sal_Unicode cPeek = c; while( cPeek != CHAR_EOF && testCharFlags( cPeek, CHAR_EOL ) == sal_False ) { @@ -529,36 +428,36 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, reType = TT_OPERATOR; } - // Zahl? + // Number? else if( testCharFlags( c, CHAR_START_NUMBER ) == sal_True ) { reType = TT_NUMBER; - // Zahlensystem, 10 = normal, wird bei Oct/Hex geaendert + // Number system, 10 = normal, it is changed for Oct/Hex int nRadix = 10; - // Ist es eine Hex- oder Oct-Zahl? + // Is it an Oct or a Hex number? if( c == '&' ) { // Octal? if( peekChar() == 'o' || peekChar() == 'O' ) { - // o entfernen + // remove o getChar(); - nRadix = 8; // Octal-Basis + nRadix = 8; // Octal base - // Alle Ziffern einlesen + // Read all numbers while( testCharFlags( peekChar(), CHAR_IN_OCT_NUMBER ) ) c = getChar(); } - // Hex? + // Hexadecimal? else if( peekChar() == 'h' || peekChar() == 'H' ) { - // x entfernen + // remove x getChar(); - nRadix = 16; // Hex-Basis + nRadix = 16; // Hexadecimal base - // Alle Ziffern einlesen und puffern + // Read all numbers while( testCharFlags( peekChar(), CHAR_IN_HEX_NUMBER ) ) c = getChar(); } @@ -568,38 +467,36 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, } } - // Wenn nicht Oct oder Hex als double ansehen + // When it is not Oct or Hex, then it is double if( reType == TT_NUMBER && nRadix == 10 ) { - // Flag, ob das letzte Zeichen ein Exponent war + // Flag if the last character is an exponent sal_Bool bAfterExpChar = sal_False; - // Alle Ziffern einlesen + // Read all numbers while( testCharFlags( peekChar(), CHAR_IN_NUMBER ) || (bAfterExpChar && peekChar() == '+' ) || (bAfterExpChar && peekChar() == '-' ) ) - // Nach Exponent auch +/- OK + // After exponent +/- are OK, too { - c = getChar(); // Zeichen lesen + c = getChar(); bAfterExpChar = ( c == 'e' || c == 'E' ); } } - - // reType = TT_NUMBER; } // String? else if( testCharFlags( c, CHAR_START_STRING ) == sal_True ) { - // Merken, welches Zeichen den String eroeffnet hat + // Remember which character has opened the string sal_Unicode cEndString = c; if( c == '[' ) cEndString = ']'; - // Alle Ziffern einlesen und puffern + // Read all characters while( peekChar() != cEndString ) { - // #58846 EOF vor getChar() abfangen, damit EOF micht verloren geht + // Detect EOF before getChar(), so we do not loose EOF if( peekChar() == CHAR_EOF ) { // ERROR: unterminated string literal @@ -615,7 +512,6 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, } } - // Zeichen lesen if( reType != TT_ERROR ) { getChar(); @@ -626,25 +522,24 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, } } - // Zeilenende? + // End of line? else if( testCharFlags( c, CHAR_EOL ) == sal_True ) { - // Falls ein weiteres anderes EOL-Char folgt, weg damit + // If another EOL character comes, read it sal_Unicode cNext = peekChar(); if( cNext != c && testCharFlags( cNext, CHAR_EOL ) == sal_True ) getChar(); - // Positions-Daten auf Zeilen-Beginn setzen + // Set position data at the line start nCol = 0; nLine++; reType = TT_EOL; } - // Alles andere bleibt TT_UNKNOWN + // All other will remain TT_UNKNOWN - - // End-Position eintragen + // Save end position rpEndPos = mpActualPos; return sal_True; } @@ -653,49 +548,47 @@ SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLangua { memset( aCharTypeTab, 0, sizeof( aCharTypeTab ) ); - // Zeichen-Tabelle fuellen + // Fill character table sal_uInt16 i; - // Zulaessige Zeichen fuer Identifier + // Allowed characters for identifiers sal_uInt16 nHelpMask = (sal_uInt16)( CHAR_START_IDENTIFIER | CHAR_IN_IDENTIFIER ); for( i = 'a' ; i <= 'z' ; i++ ) aCharTypeTab[i] |= nHelpMask; for( i = 'A' ; i <= 'Z' ; i++ ) aCharTypeTab[i] |= nHelpMask; - // '_' extra eintragen aCharTypeTab[(int)'_'] |= nHelpMask; - // AB 23.6.97: '$' ist auch erlaubt aCharTypeTab[(int)'$'] |= nHelpMask; - // Ziffern (Identifier und Number ist moeglich) + // Digit (can be identifier and number) nHelpMask = (sal_uInt16)( CHAR_IN_IDENTIFIER | CHAR_START_NUMBER | CHAR_IN_NUMBER | CHAR_IN_HEX_NUMBER ); for( i = '0' ; i <= '9' ; i++ ) aCharTypeTab[i] |= nHelpMask; - // e und E sowie . von Hand ergaenzen + // Add e, E, . and & here manually aCharTypeTab[(int)'e'] |= CHAR_IN_NUMBER; aCharTypeTab[(int)'E'] |= CHAR_IN_NUMBER; aCharTypeTab[(int)'.'] |= (sal_uInt16)( CHAR_IN_NUMBER | CHAR_START_NUMBER ); aCharTypeTab[(int)'&'] |= CHAR_START_NUMBER; - // Hex-Ziffern + // Hexadecimal digit for( i = 'a' ; i <= 'f' ; i++ ) aCharTypeTab[i] |= CHAR_IN_HEX_NUMBER; for( i = 'A' ; i <= 'F' ; i++ ) aCharTypeTab[i] |= CHAR_IN_HEX_NUMBER; - // Oct-Ziffern + // Octal digit for( i = '0' ; i <= '7' ; i++ ) aCharTypeTab[i] |= CHAR_IN_OCT_NUMBER; - // String-Beginn/End-Zeichen + // String literal start/end characters aCharTypeTab[(int)'\''] |= CHAR_START_STRING; aCharTypeTab[(int)'\"'] |= CHAR_START_STRING; aCharTypeTab[(int)'['] |= CHAR_START_STRING; aCharTypeTab[(int)'`'] |= CHAR_START_STRING; - // Operator-Zeichen + // Operator characters aCharTypeTab[(int)'!'] |= CHAR_OPERATOR; aCharTypeTab[(int)'%'] |= CHAR_OPERATOR; // aCharTypeTab[(int)'&'] |= CHAR_OPERATOR; Removed because of #i14140 @@ -724,7 +617,7 @@ SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLangua aCharTypeTab[(int)' ' ] |= CHAR_SPACE; aCharTypeTab[(int)'\t'] |= CHAR_SPACE; - // Zeilen-Ende-Zeichen + // End of line characters aCharTypeTab[(int)'\r'] |= CHAR_EOL; aCharTypeTab[(int)'\n'] |= CHAR_EOL; @@ -743,22 +636,21 @@ SimpleTokenizer_Impl* getSimpleTokenizer( void ) return pSimpleTokenizer; } -// Heraussuchen der jeweils naechsten Funktion aus einem JavaScript-Modul sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const String* aSource ) { - // Position auf den Anfang des Source-Strings setzen + // Set the position to the beginning of the source string mpStringBegin = mpActualPos = aSource->GetBuffer(); - // Zeile und Spalte initialisieren + // Initialize row and column nLine = nParseLine; nCol = 0L; - // Variablen fuer die Out-Parameter + // Variables for the out parameter TokenTypes eType; const sal_Unicode* pStartPos; const sal_Unicode* pEndPos; - // Schleife ueber alle Tokens + // Loop over all the tokens sal_uInt16 nTokenCount = 0; while( getNextToken( eType, pStartPos, pEndPos ) ) nTokenCount++; @@ -769,19 +661,19 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const String* void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const String& rLine, /*out*/HighlightPortions& portions ) { - // Position auf den Anfang des Source-Strings setzen + // Set the position to the beginning of the source string mpStringBegin = mpActualPos = rLine.GetBuffer(); - // Zeile und Spalte initialisieren + // Initialize row and column nLine = nParseLine; nCol = 0L; - // Variablen fuer die Out-Parameter + // Variables for the out parameter TokenTypes eType; const sal_Unicode* pStartPos; const sal_Unicode* pEndPos; - // Schleife ueber alle Tokens + // Loop over all the tokens while( getNextToken( eType, pStartPos, pEndPos ) ) { HighlightPortion portion; @@ -795,9 +687,6 @@ void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const St } -////////////////////////////////////////////////////////////////////////// -// Implementierung des SyntaxHighlighter - SyntaxHighlighter::SyntaxHighlighter() { m_pSimpleTokenizer = 0; commit 4ab3d5bb6f6f095375c2eaf200dd285be516feda Author: Andras Timar <ati...@suse.com> Date: Mon Feb 11 19:08:01 2013 +0100 WaE: warning C4101: 'ex' : unreferenced local variable Change-Id: I99a66ac3af8e391b5feaeafbb3abd63dcdd2bb2b diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index 858db82..339d96b 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -187,7 +187,7 @@ void BasicCodeTagger::tagBasicCodes() } catch (TaggerException ex) { - std::cout << "Some kind of error occured." << std::endl; + std::cout << "BasCodeTagger error occured. Error code:" << ex << std::endl; } //tag basic code paragraphs in <bascode> tag commit d06c698b799e0e4ceaf3a3760c9589fe29dc29a9 Author: Dávid Vastag <davewwpub...@gmail.com> Date: Mon Feb 11 16:49:40 2013 +0100 Basic code syntaxhighlighting added to LibreOffice help Change-Id: Id47172d0386e7aa28d82178f04b5f626f0c441fe diff --git a/helpcompiler/Library_helplinker.mk b/helpcompiler/Library_helplinker.mk index 6820c3b..0d9be0b 100644 --- a/helpcompiler/Library_helplinker.mk +++ b/helpcompiler/Library_helplinker.mk @@ -43,8 +43,16 @@ endif $(eval $(call gb_Library_use_libraries,helplinker,\ sal \ + svt \ + tl \ )) +$(eval $(call gb_Library_use_internal_api,helplinker,\ + udkapi \ + offapi \ +)) + + $(eval $(call gb_Library_use_externals,helplinker,\ boost_headers \ expat_utf8 \ @@ -58,6 +66,7 @@ $(eval $(call gb_Library_add_exception_objects,helplinker,\ helpcompiler/source/LuceneHelper \ helpcompiler/source/HelpIndexer \ helpcompiler/source/HelpSearch \ + helpcompiler/source/BasCodeTagger \ )) ifeq ($(strip $(OS)$(CPU)$(COM)),MACOSXPGCC) diff --git a/helpcompiler/Package_inc.mk b/helpcompiler/Package_inc.mk index b0717b2..e532d95 100644 --- a/helpcompiler/Package_inc.mk +++ b/helpcompiler/Package_inc.mk @@ -15,5 +15,6 @@ $(eval $(call gb_Package_add_file,helpcompiler_inc,inc/helpcompiler/HelpCompiler $(eval $(call gb_Package_add_file,helpcompiler_inc,inc/helpcompiler/HelpIndexer.hxx,inc/HelpIndexer.hxx)) $(eval $(call gb_Package_add_file,helpcompiler_inc,inc/helpcompiler/HelpLinker.hxx,inc/HelpLinker.hxx)) $(eval $(call gb_Package_add_file,helpcompiler_inc,inc/helpcompiler/HelpSearch.hxx,inc/HelpSearch.hxx)) +$(eval $(call gb_Package_add_file,helpcompiler_inc,inc/helpcompiler/BasCodeTagger.hxx,inc/BasCodeTagger.hxx)) # vim: set noet sw=4 ts=4: diff --git a/helpcompiler/inc/BasCodeTagger.hxx b/helpcompiler/inc/BasCodeTagger.hxx new file mode 100644 index 0000000..3cf9261 --- /dev/null +++ b/helpcompiler/inc/BasCodeTagger.hxx @@ -0,0 +1,57 @@ +#ifndef BASCODETAGGER_HXX +#define BASCODETAGGER_HXX + +#include <iostream> +#include <cstdlib> +#include <string> +#include <list> +#include <libxml/xmlmemory.h> +#include <libxml/parser.h> +#include <rtl/ustring.hxx> +#include <svtools/syntaxhighlight.hxx> +#include <helpcompiler/dllapi.h> + +class BasicCodeTagger; +class LibXmlTreeWalker; + +//!Tagger class. +class L10N_DLLPUBLIC BasicCodeTagger +{ + private: + xmlDocPtr m_pDocument; + std::list<xmlNodePtr> m_BasicCodeContainerTags; + LibXmlTreeWalker *m_pXmlTreeWalker; + std::list<std::string> m_BasicCodeStringList; + SyntaxHighlighter m_Highlighter; + bool m_bTaggingCompleted; + void tagParagraph( xmlNodePtr paragraph ); + xmlChar* getTypeString( TokenTypes tokenType ); + void getBasicCodeContainerNodes(); + void tagBasCodeParagraphs(); + + public: + enum TaggerException { FILE_WRITING, NULL_DOCUMENT, EMPTY_DOCUMENT }; + BasicCodeTagger( xmlDocPtr rootDoc ); + ~BasicCodeTagger(); + void tagBasicCodes(); + void saveTreeToFile( const std::string& filePath, const std::string& encoding ); +}; + +//================LibXmlTreeWalker=========================================================== + +class L10N_DLLPUBLIC LibXmlTreeWalker +{ + private: + xmlNodePtr m_pCurrentNode; + std::list<xmlNodePtr> m_Queue; //!Queue for breath-first search + + public: + LibXmlTreeWalker( xmlDocPtr doc ); + ~LibXmlTreeWalker() {} + void nextNode(); + xmlNodePtr currentNode(); + bool end(); + void ignoreCurrNodesChildren(); +}; + +#endif diff --git a/helpcompiler/inc/HelpCompiler.hxx b/helpcompiler/inc/HelpCompiler.hxx index f0a4177..034a629 100644 --- a/helpcompiler/inc/HelpCompiler.hxx +++ b/helpcompiler/inc/HelpCompiler.hxx @@ -71,7 +71,6 @@ namespace fs { rtl::OUString sWorkingDir; osl_getProcessWorkingDir(&sWorkingDir.pData); - rtl::OString tmp(in.c_str()); rtl::OUString ustrSystemPath(rtl::OStringToOUString(tmp, getThreadTextEncoding())); osl::File::getFileURLFromSystemPath(ustrSystemPath, data); @@ -230,6 +229,7 @@ public: HelpCompiler(StreamTable &streamTable, const fs::path &in_inputFile, const fs::path &in_src, + const fs::path &in_zipdir, const fs::path &in_resEmbStylesheet, const std::string &in_module, const std::string &in_lang, @@ -245,9 +245,10 @@ public: const std::string &entryName, const Hashtable &bytesToAdd); private: xmlDocPtr getSourceDocument(const fs::path &filePath); + void sourceDocumentPreWorks( xmlDocPtr doc , const fs::path &filePath); xmlNodePtr clone(xmlNodePtr node, const std::string& appl); StreamTable &streamTable; - const fs::path inputFile, src; + const fs::path inputFile, src, zipdir; const std::string module, lang; const fs::path resEmbStylesheet; bool bExtensionMode; @@ -260,5 +261,4 @@ inline char tocharlower(char c) } #endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx new file mode 100644 index 0000000..858db82 --- /dev/null +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -0,0 +1,251 @@ +#include <helpcompiler/BasCodeTagger.hxx> + +LibXmlTreeWalker::LibXmlTreeWalker( xmlDocPtr doc ) +{ + if ( doc == NULL ) + throw BasicCodeTagger::NULL_DOCUMENT; + m_pCurrentNode = xmlDocGetRootElement( doc ); + if ( m_pCurrentNode == NULL ) + throw BasicCodeTagger::EMPTY_DOCUMENT; + else if ( m_pCurrentNode->xmlChildrenNode != NULL ) + m_Queue.push_back( m_pCurrentNode->xmlChildrenNode ); + nextNode(); +} + +void LibXmlTreeWalker::nextNode() +{ + + //next node + if ( m_pCurrentNode->next == NULL ) + { + m_pCurrentNode = m_Queue.front(); + m_Queue.pop_front(); + } + else + m_pCurrentNode = m_pCurrentNode->next; + //queue chiledren if they exist + if ( m_pCurrentNode->xmlChildrenNode != NULL ) + m_Queue.push_back( m_pCurrentNode->xmlChildrenNode ); +} + +void LibXmlTreeWalker::ignoreCurrNodesChildren() +{ + if ( m_pCurrentNode->xmlChildrenNode != NULL ) + m_Queue.pop_back(); +} + +bool LibXmlTreeWalker::end() +{ + return m_pCurrentNode->next == NULL && m_Queue.empty(); +} + +xmlNodePtr LibXmlTreeWalker::currentNode() +{ + return m_pCurrentNode; +} + +//====================================================== + +BasicCodeTagger::BasicCodeTagger( xmlDocPtr rootDoc ) +{ + if ( rootDoc == NULL ) + throw NULL_DOCUMENT; + m_pDocument = rootDoc; + m_pXmlTreeWalker = NULL; + m_Highlighter.initialize( HIGHLIGHT_BASIC ); + m_bTaggingCompleted = false; + +} + +BasicCodeTagger::~BasicCodeTagger() +{ + if ( m_pXmlTreeWalker != NULL ) + delete m_pXmlTreeWalker; +} +//!Gathers all the <bascode> tag nodes from xml tree. +/*! + * Assumes m_pDocument is valid. Handles m_pXmlTreeWalker and m_BasicCodeContainerTags members. + */ +void BasicCodeTagger::getBasicCodeContainerNodes() +{ + xmlNodePtr currentNode; + + m_BasicCodeContainerTags.clear(); + + if ( m_pXmlTreeWalker != NULL ) + delete m_pXmlTreeWalker; + m_pXmlTreeWalker = new LibXmlTreeWalker( m_pDocument ); + + currentNode = m_pXmlTreeWalker->currentNode(); + if ( !( xmlStrcmp( currentNode->name, (const xmlChar*) "bascode" ) ) ) + { //Found <bascode> + m_BasicCodeContainerTags.push_back( currentNode ); //it goes to the end of the list + } + while ( !m_pXmlTreeWalker->end() ) + { + m_pXmlTreeWalker->nextNode(); + if ( !( xmlStrcmp( m_pXmlTreeWalker->currentNode()->name, (const xmlChar*) "bascode" ) ) ) + { //Found <bascode> + m_BasicCodeContainerTags.push_back( m_pXmlTreeWalker->currentNode() ); //it goes to the end of the list + m_pXmlTreeWalker->ignoreCurrNodesChildren(); + } + } +} + +//! Extracts Basic Codes containted in <bascode> tags. +/*! + * For each <bascode> this method iterates trough it's <paragraph> tags and "inserts" <item> tags according + * to the Basic code syntax found in that paragraph. + */ +void BasicCodeTagger::tagBasCodeParagraphs() +{ + //helper variables + xmlNodePtr currBascodeNode; + xmlNodePtr currParagraph; + while ( !m_BasicCodeContainerTags.empty() ) + { + currBascodeNode = m_BasicCodeContainerTags.front(); + currParagraph = currBascodeNode->xmlChildrenNode; //first <paragraph> + while ( currParagraph != NULL ) + { + tagParagraph( currParagraph ); + currParagraph=currParagraph->next; + } + m_BasicCodeContainerTags.pop_front(); //next element + } +} + +//! Used by tagBasCodeParagraphs(). It does the work on the current paragraph containing Basic code. +void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) +{ + //1. get paragraph text + xmlChar* codeSnippet; + codeSnippet = xmlNodeListGetString( m_pDocument, paragraph->xmlChildrenNode, 1 ); + if ( codeSnippet == NULL ) + { + return; //no text, nothing more to do here + } + //2. delete every child from paragraph (except attributes) + xmlNodePtr curNode = paragraph->xmlChildrenNode; + xmlNodePtr sibling; + while ( curNode != NULL ) + { + sibling = curNode->next; + xmlUnlinkNode( curNode ); + xmlFreeNode( curNode ); + curNode = sibling; + } + + //3. create new paragraph content + String strLine( + OUString( + reinterpret_cast<const sal_Char*>(codeSnippet), + strlen( + reinterpret_cast<const char*>(codeSnippet) + ), + RTL_TEXTENCODING_UTF8 + ) + ) ; + m_Highlighter.notifyChange ( 0, 0, &strLine, 1 ); + HighlightPortions portions; + m_Highlighter.getHighlightPortions( 0, strLine, portions ); + xmlChar* subStr; + xmlChar* typeStr; + xmlNodePtr text; + for ( size_t i=0; i<portions.size(); i++ ) + { + HighlightPortion& r = portions[i]; + subStr = xmlStrsub( codeSnippet, r.nBegin, r.nEnd-r.nBegin ); + text = xmlNewText( subStr ); + if ( r.tokenType != TT_WHITESPACE ) + { + typeStr = getTypeString( r.tokenType ); + curNode = xmlNewTextChild( paragraph, 0, (xmlChar*)"item", 0 ); + xmlNewProp( curNode, (xmlChar*)"type", typeStr ); + xmlAddChild( curNode, text ); + xmlFree( typeStr ); + } + else + xmlAddChild( paragraph, text ); + xmlFree( subStr ); + } + xmlFree( codeSnippet ); +} + +//! Manages tagging process. +/*! + * This is the "main" function of BasicCodeTagger. + */ +void BasicCodeTagger::tagBasicCodes() +{ + if ( m_bTaggingCompleted ) + return; + //gather <bascode> nodes + try + { + getBasicCodeContainerNodes(); + } + catch (TaggerException ex) + { + std::cout << "Some kind of error occured." << std::endl; + } + + //tag basic code paragraphs in <bascode> tag + tagBasCodeParagraphs(); + m_bTaggingCompleted = true; +} + +//! Converts SyntaxHighlighter's TokenTypes enum to a type string for <item type=... > +xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) +{ + const char* str; + switch ( tokenType ) + { + case TT_UNKNOWN : + str = "unknown"; + break; + case TT_IDENTIFIER : + str = "identifier"; + break; + case TT_WHITESPACE : + str = "whitespace"; + break; + case TT_NUMBER : + str = "number"; + break; + case TT_STRING : + str = "string"; + break; + case TT_EOL : + str = "eol"; + break; + case TT_COMMENT : + str = "comment"; + break; + case TT_ERROR : + str = "error"; + break; + case TT_OPERATOR : + str = "operator"; + break; + case TT_KEYWORDS : + str = "keywords"; + break; + case TT_PARAMETER : + str = "parameter"; + break; + default : + str = "unknown"; + break; + } + return xmlCharStrdup( str ); +} + +//! Saves the current xml DOM to file with the provided libxml2 encoding string in an unformatted way. +void BasicCodeTagger::saveTreeToFile( const std::string& filePath, const std::string& encoding ) +{ + //saveDocument + int ret = xmlSaveFormatFileEnc( filePath.c_str(), m_pDocument, encoding.c_str(), 0 ); + if ( ret == -1 ) + throw FILE_WRITING; +} diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index 74b29f5..8c6f66b 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -19,6 +19,7 @@ #include <helpcompiler/HelpCompiler.hxx> +#include <helpcompiler/BasCodeTagger.hxx> #include <limits.h> #include <stdlib.h> #include <string.h> @@ -36,25 +37,55 @@ static void impl_sleep( sal_uInt32 nSec ) osl::Thread::wait( aTime ); } - HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_inputFile, - const fs::path &in_src, const fs::path &in_resEmbStylesheet, + const fs::path &in_src, const fs::path &in_zipdir, const fs::path &in_resEmbStylesheet, const std::string &in_module, const std::string &in_lang, bool in_bExtensionMode) : streamTable(in_streamTable), inputFile(in_inputFile), - src(in_src), module(in_module), lang(in_lang), resEmbStylesheet(in_resEmbStylesheet), + src(in_src), zipdir(in_zipdir), module(in_module), lang(in_lang), resEmbStylesheet(in_resEmbStylesheet), bExtensionMode( in_bExtensionMode ) { xmlKeepBlanksDefaultValue = 0; char* guitmp = getenv("GUI"); if (guitmp) { - // WTF? gui = (strcmp(guitmp, "UNX") ? gui : "UNIX"); gui = (strcmp(guitmp, "MAC") ? gui : "MAC"); gui = (strcmp(guitmp, "WNT") ? gui : "WIN"); } } +void HelpCompiler::sourceDocumentPreWorks( xmlDocPtr doc, const fs::path &filePath ) +{ + if ( doc ) + { + if ( module == "sbasic" ) + { + try + { + BasicCodeTagger bct( doc ); + bct.tagBasicCodes(); + } + catch ( BasicCodeTagger::TaggerException ex ) + { + if ( ex != BasicCodeTagger::EMPTY_DOCUMENT ) + throw; + } + //save document in ziptmp<modul>_<lang>/text directory + //1. construct new path + const std::string& pth = filePath.native_file_string(); + std::string sourceNativeXhpPath = pth.substr( pth.rfind( lang+"/text/" ) ).substr( lang.length() ); + std::string xhpFileName = sourceNativeXhpPath.substr( sourceNativeXhpPath.rfind( '/' ) + 1 ); + sourceNativeXhpPath = sourceNativeXhpPath.substr( 0, sourceNativeXhpPath.rfind( '/' ) ); + //2. save xml doc with the new path + // -create directory hierachy + fs::create_directory( fs::path( zipdir.native_file_string() + sourceNativeXhpPath, fs::native ) ); + // -save document + if ( -1 == xmlSaveFormatFileEnc( (zipdir.native_file_string() + sourceNativeXhpPath + '/' + xhpFileName).c_str(), doc, "utf-8", 0 ) ) + throw BasicCodeTagger::FILE_WRITING; + } + } +} + xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) { static const char *params[4 + 1]; @@ -68,6 +99,7 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); res = xmlParseFile(filePath.native_file_string().c_str()); } + sourceDocumentPreWorks( res, filePath ); } else { @@ -93,7 +125,7 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); doc = xmlParseFile(filePath.native_file_string().c_str()); } - + sourceDocumentPreWorks( doc, filePath ); //???res = xmlParseFile(filePath.native_file_string().c_str()); res = xsltApplyStylesheet(cur, doc, params); diff --git a/helpcompiler/source/HelpLinker.cxx b/helpcompiler/source/HelpLinker.cxx index 62d3645..4bbe2b6 100644 --- a/helpcompiler/source/HelpLinker.cxx +++ b/helpcompiler/source/HelpLinker.cxx @@ -377,7 +377,7 @@ void HelpLinker::link() throw( HelpProcessingException ) xhpFile = fs::path(xhpFileName, fs::native); } - HelpCompiler hc( streamTable, xhpFile, langsourceRoot, + HelpCompiler hc( streamTable, xhpFile, langsourceRoot, zipdir, embeddStylesheet, module, lang, bExtensionMode ); HCDBG(std::cerr << "before compile of " << xhpFileName << std::endl);
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits