[Libreoffice-commits] core.git: Branch 'distro/vector/vtext-6.5' - 2 commits - tools/source writerfilter/source

Tor Lillqvist tml at collabora.com
Fri Jul 25 04:24:41 PDT 2014


 tools/source/stream/stream.cxx              |   69 ++++++++++++++++++++++++++++
 writerfilter/source/rtftok/rtftokenizer.cxx |   34 +++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)

New commits:
commit 355f8a3c6540acc01c6874385fb63ce23ffa8c3f
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jul 25 04:13:44 2014 -0700

    Handle broken RTF files that have multiple top-level (\rtf) groups
    
    There exists in the wild RTF files that have two top-level groups
    (starting with the \rtf control word). Ignore the group-end '}' and
    the following group-start '{' in that case. Horrible hack, yes. But
    Word does not seem to require correctly formed RTF either, it handles
    this kind of files. So we should too. At least in this case of
    brokenness.
    
    Change-Id: Idd26a82f1da1e1f873c158367469eca7d9b0d652

diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index 3515c8b..fa4e234 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -122,6 +122,38 @@ int RTFTokenizer::resolveParse()
                         return ret;
                     break;
                 case '}':
+                    if (m_nGroup == 1)
+                    {
+                        // Handle bogus RTF documents that have
+                        // several top-level groups: Ignore the group
+                        // end and following group start characters,
+                        // i.e. pretend it is one group.
+                        bool bSkipping(true), bDidIt(false);
+                        char oldch(ch);
+                        while (bSkipping && ((Strm() >> ch, !Strm().IsEof())))
+                        {
+                            switch (ch)
+                            {
+                            case 0x0d:
+                                break; // ignore this
+                            case 0x0a:
+                                m_nLineNumber++;
+                                m_nLineStartPos = nCurrentPos;
+                                break;
+                            case '{':
+                                bSkipping = false;
+                                bDidIt = true;
+                                break;
+                            default:
+                                Strm().PutBack(ch);
+                                ch = oldch;
+                                bSkipping = false;
+                                break;
+                            }
+                        }
+                        if (bDidIt)
+                            break;
+                    }
                     ret = m_rImport.popState();
                     if (ret)
                         return ret;
@@ -295,7 +327,7 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
 {
     if (m_rImport.getState().nDestinationState == DESTINATION_SKIP)
         return 0;
-    /*SAL_INFO("writefilter", OSL_THIS_FUNC << ": keyword '\\" << rKeyword.getStr() <<
+    /*SAL_INFO("writerfilter", "keyword '\\" << rKeyword.getStr() <<
                "' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'");*/
     RTFSymbol aSymbol;
     aSymbol.sKeyword = rKeyword.getStr();
commit 1ca907bcd449544181e9897d403f127fcf869986
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Jul 25 04:01:47 2014 -0700

    Restore SvStream::PutBack(char)
    
    It was removed as unused in a3b0ee88be3c6bff94ec6fe908f209c1dbb9748d
    but the declaration was accidentally left in the <tools/stream.hxx>.
    Now I need it, so restore the implementation.
    
    Change-Id: I7da5bf74e6c8ac8375273db0dda267d1dec2ac14

diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 6ca4d07..4a455ca 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1485,6 +1485,75 @@ void SvStream::Flush()
         FlushData();
 }
 
+
+/*************************************************************************
+|*
+|*    Stream::PutBack()
+|*
+*************************************************************************/
+
+/*
+    4 Faelle :
+
+    1. Datenzeiger steht mitten im Puffer (nBufActualPos >= 1)
+    2. Datenzeiger auf Position 0, Puffer ist voll
+    3. Datenzeiger auf Position 0, Puffer ist teilweise gefuellt
+    4. Datenzeiger auf Position 0, Puffer ist leer -> Fehler!
+*/
+
+SvStream& SvStream::PutBack( char aCh )
+{
+    // wenn kein Buffer oder Zurueckscrollen nicht moeglich -> Fehler
+    if( !pRWBuf || !nBufActualLen || ( !nBufActualPos && !nBufFilePos ) )
+    {
+        // 4. Fall
+        SetError( SVSTREAM_GENERALERROR );
+        return *this;
+    }
+
+    // Flush() (Phys. Flushen aber nicht notwendig, deshalb selbst schreiben)
+    if( bIsConsistent && bIsDirty  )
+    {
+        SeekPos( nBufFilePos );
+        if( nCryptMask )
+            CryptAndWriteBuffer( pRWBuf, nBufActualLen );
+        else
+            PutData( pRWBuf, nBufActualLen );
+        bIsDirty = sal_False;
+    }
+    bIsConsistent = sal_False;  // Puffer enthaelt jetzt TRASH
+    if( nBufActualPos )
+    {
+        // 1. Fall
+        nBufActualPos--;
+        pBufPos--;
+        *pBufPos = aCh;
+        nBufFree++;
+    }
+    else  // Puffer muss verschoben werden
+    {
+        // Ist Puffer am Anschlag ?
+        if( nBufSize == nBufActualLen )
+        {
+            // 2. Fall
+            memmove( pRWBuf+1, pRWBuf, nBufSize-1 );
+            // nBufFree behaelt den Wert!
+        }
+        else
+        {
+            // 3. Fall -> Puffer vergroessern
+            memmove( pRWBuf+1, pRWBuf, (sal_uInt16)nBufActualLen );
+            nBufActualLen++;
+            nBufFree++;
+        }
+        nBufFilePos--;
+        *pRWBuf = aCh;
+    }
+    eIOMode = STREAM_IO_DONTKNOW;
+    bIsEof = sal_False;
+    return *this;
+}
+
 void SvStream::RefreshBuffer()
 {
     if( bIsDirty && bIsConsistent )


More information about the Libreoffice-commits mailing list