LCOV - code coverage report
Current view: top level - sc/source/filter/lotus - filter.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 80 65.0 %
Date: 2014-04-11 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : //  Das geht:   Versionserkennung WKS, WK1 und WK3
      21             : //              ...Rest steht in op.cpp
      22             : 
      23             : #include <string.h>
      24             : #include <map>
      25             : 
      26             : #include "filter.hxx"
      27             : #include "document.hxx"
      28             : #include "compiler.hxx"
      29             : #include "scerrors.hxx"
      30             : 
      31             : #include "root.hxx"
      32             : #include "lotrange.hxx"
      33             : #include "optab.h"
      34             : #include "scmem.h"
      35             : #include "decl.h"
      36             : #include "tool.h"
      37             : 
      38             : #include "fprogressbar.hxx"
      39             : 
      40             : #include "op.h"
      41             : 
      42             : // Konstanten
      43             : const sal_uInt16        nBOF = 0x0000;
      44             : 
      45             : // externe Variablen
      46             : extern WKTYP        eTyp;   // Typ der gerade in bearbeitung befindlichen Datei
      47             : WKTYP               eTyp;
      48             : 
      49             : extern sal_Bool         bEOF;           // zeigt Ende der Datei
      50             : sal_Bool                bEOF;
      51             : 
      52             : extern rtl_TextEncoding eCharVon;
      53             : rtl_TextEncoding        eCharVon;
      54             : 
      55             : extern ScDocument*  pDoc;           // Aufhaenger zum Dokumentzugriff
      56             : ScDocument*         pDoc;
      57             : 
      58             : 
      59             : extern OPCODE_FKT   pOpFkt[ FKT_LIMIT ];
      60             :                                     // -> optab.cxx, Tabelle moeglicher Opcodes
      61             : extern OPCODE_FKT   pOpFkt123[ FKT_LIMIT123 ];
      62             :                                     // -> optab.cxx, Table of possible Opcodes
      63             : 
      64             : LOTUS_ROOT*         pLotusRoot = NULL;
      65             : 
      66             : 
      67           6 : std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
      68             : 
      69             : static FltError
      70           1 : generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
      71             :                   ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
      72             : {
      73             :     OPCODE_FKT *pOps;
      74             :     int         nOps;
      75             : 
      76           1 :     switch(eType)
      77             :     {
      78             :         case eWK_1:
      79             :         case eWK_2:
      80           0 :         pOps = pOpFkt;
      81           0 :         nOps = FKT_LIMIT;
      82           0 :         break;
      83             :         case eWK123:
      84           1 :         pOps = pOpFkt123;
      85           1 :         nOps = FKT_LIMIT123;
      86           1 :         break;
      87           0 :         case eWK3:      return eERR_NI;
      88           0 :         case eWK_Error: return eERR_FORMAT;
      89           0 :         default:        return eERR_UNKN_WK;
      90             :      }
      91             : 
      92             :     // #i76299# seems that SvStream::IsEof() does not work correctly
      93           1 :     aStream.Seek( STREAM_SEEK_TO_END );
      94           1 :     sal_Size nStrmSize = aStream.Tell();
      95           1 :     aStream.Seek( STREAM_SEEK_TO_BEGIN );
      96         269 :     while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
      97             :     {
      98             :         sal_uInt16 nOpcode, nLength;
      99             : 
     100         267 :         aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
     101         267 :         aPrgrsBar.Progress();
     102         267 :         if( nOpcode == LOTUS_EOF )
     103           1 :         bEOF = sal_True;
     104             : 
     105         266 :         else if( nOpcode == LOTUS_FILEPASSWD )
     106           0 :         return eERR_FILEPASSWD;
     107             : 
     108         266 :         else if( nOpcode < nOps )
     109          52 :         pOps[ nOpcode ] ( aStream, nLength );
     110             : 
     111         428 :         else if( eType == eWK123 &&
     112         214 :              nOpcode == LOTUS_PATTERN )
     113             :             {
     114             :         // This is really ugly - needs re-factoring ...
     115           2 :         aStream.SeekRel(nLength);
     116           2 :         aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
     117           4 :         if ( nOpcode == 0x29a)
     118             :         {
     119           1 :             aStream.SeekRel(nLength);
     120           1 :             aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
     121           1 :             if ( nOpcode == 0x804 )
     122             :             {
     123           1 :             aStream.SeekRel(nLength);
     124           1 :             OP_ApplyPatternArea123(aStream);
     125             :             }
     126             :             else
     127           0 :             aStream.SeekRel(nLength);
     128             :         }
     129             :         else
     130           1 :             aStream.SeekRel(nLength);
     131             :         }
     132             :         else
     133         212 :         aStream.SeekRel( nLength );
     134             :     }
     135             : 
     136           1 :     MemDelete();
     137             : 
     138           1 :     rDoc.CalcAfterLoad();
     139             : 
     140           1 :     return eERR_OK;
     141             : }
     142             : 
     143           1 : WKTYP ScanVersion( SvStream& aStream )
     144             : {
     145             :     // PREC:    pWKDatei:   Zeiger auf offene Datei
     146             :     // POST:    return:     Typ der Datei
     147             :     sal_uInt16          nOpcode, nVersNr, nRecLen;
     148             : 
     149             :     // erstes Byte muss wegen BOF zwingend 0 sein!
     150           1 :     aStream.ReadUInt16( nOpcode );
     151           1 :     if( nOpcode != nBOF )
     152           0 :         return eWK_UNKNOWN;
     153             : 
     154           1 :     aStream.ReadUInt16( nRecLen ).ReadUInt16( nVersNr );
     155             : 
     156           1 :     if( aStream.IsEof() )
     157           0 :         return eWK_Error;
     158             : 
     159           1 :     switch( nVersNr )
     160             :     {
     161             :         case 0x0404:
     162           0 :             if( nRecLen == 2 )
     163           0 :                 return eWK_1;
     164             :             else
     165           0 :                 return eWK_UNKNOWN;
     166             : 
     167             :         case 0x0406:
     168           0 :             if( nRecLen == 2 )
     169           0 :                 return eWK_2;
     170             :             else
     171           0 :                 return eWK_UNKNOWN;
     172             : 
     173             :         case 0x1000:
     174           0 :             aStream.ReadUInt16( nVersNr );
     175           0 :             if( aStream.IsEof() ) return eWK_Error;
     176           0 :             if( nVersNr == 0x0004 && nRecLen == 26 )
     177             :                         {       // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
     178             :                 sal_Char aDummy[22];
     179           0 :                 aStream.Read( aDummy, 22 );
     180           0 :                 return aStream.IsEof() ? eWK_Error : eWK3;
     181             :             }
     182           0 :             break;
     183             :         case 0x1003:
     184           1 :             if( nRecLen == 0x1a )
     185           1 :                 return eWK123;
     186             :             else
     187           0 :                 return eWK_UNKNOWN;
     188             :         case 0x1005:
     189           0 :             if( nRecLen == 0x1a )
     190           0 :                 return eWK123;
     191             :             else
     192           0 :                 return eWK_UNKNOWN;
     193             :     }
     194             : 
     195           0 :     return eWK_UNKNOWN;
     196             : }
     197             : 
     198           1 : FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, rtl_TextEncoding eSrc )
     199             : {
     200           1 :     aStream.Seek( 0UL );
     201             : 
     202             :     // Zeiger auf Dokument global machen
     203           1 :     pDoc = pDocument;
     204             : 
     205           1 :     bEOF = false;
     206             : 
     207           1 :     eCharVon = eSrc;
     208             : 
     209             :     // Speicher besorgen
     210           1 :     if( !MemNew() )
     211           0 :         return eERR_NOMEM;
     212             : 
     213           1 :     InitPage(); // Seitenformat initialisieren (nur Tab 0!)
     214             : 
     215             :         // Progressbar starten
     216           1 :     ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
     217             : 
     218             :     // Datei-Typ ermitteln
     219           1 :     eTyp = ScanVersion( aStream );
     220             : 
     221           1 :     aLotusPatternPool.clear();
     222             : 
     223           1 :     return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );
     224          18 : }
     225             : 
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10