LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/lotus - filter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 79 64.6 %
Date: 2012-12-27 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             : //------------------------------------------------------------------------
      24             : 
      25             : #include <tools/solar.h>
      26             : #include <string.h>
      27             : #include <map>
      28             : 
      29             : #include "filter.hxx"
      30             : #include "document.hxx"
      31             : #include "compiler.hxx"
      32             : #include "scerrors.hxx"
      33             : 
      34             : #include "root.hxx"
      35             : #include "lotrange.hxx"
      36             : #include "optab.h"
      37             : #include "scmem.h"
      38             : #include "decl.h"
      39             : #include "tool.h"
      40             : 
      41             : #include "fprogressbar.hxx"
      42             : 
      43             : #include "op.h"
      44             : 
      45             : // Konstanten ------------------------------------------------------------
      46             : const sal_uInt16        nBOF = 0x0000;
      47             : 
      48             : 
      49             : 
      50             : // externe Variablen -----------------------------------------------------
      51             : extern WKTYP        eTyp;   // Typ der gerade in bearbeitung befindlichen Datei
      52             : WKTYP               eTyp;
      53             : 
      54             : extern sal_Bool         bEOF;           // zeigt Ende der Datei
      55             : sal_Bool                bEOF;
      56             : 
      57             : extern CharSet      eCharVon;
      58             : CharSet             eCharVon;
      59             : 
      60             : extern ScDocument*  pDoc;           // Aufhaenger zum Dokumentzugriff
      61             : ScDocument*         pDoc;
      62             : 
      63             : 
      64             : extern OPCODE_FKT   pOpFkt[ FKT_LIMIT ];
      65             :                                     // -> optab.cxx, Tabelle moeglicher Opcodes
      66             : extern OPCODE_FKT   pOpFkt123[ FKT_LIMIT123 ];
      67             :                                     // -> optab.cxx, Table of possible Opcodes
      68             : 
      69             : LOTUS_ROOT*         pLotusRoot = NULL;
      70             : 
      71             : 
      72           3 : std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
      73             : 
      74             : static FltError
      75           1 : generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
      76             :                   ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
      77             : {
      78             :     OPCODE_FKT *pOps;
      79             :     int         nOps;
      80             : 
      81           1 :     switch(eType)
      82             :     {
      83             :         case eWK_1:
      84             :         case eWK_2:
      85           0 :         pOps = pOpFkt;
      86           0 :         nOps = FKT_LIMIT;
      87           0 :         break;
      88             :         case eWK123:
      89           1 :         pOps = pOpFkt123;
      90           1 :         nOps = FKT_LIMIT123;
      91           1 :         break;
      92           0 :         case eWK3:      return eERR_NI;
      93           0 :         case eWK_Error: return eERR_FORMAT;
      94           0 :         default:        return eERR_UNKN_WK;
      95             :      }
      96             : 
      97             :     // #i76299# seems that SvStream::IsEof() does not work correctly
      98           1 :     aStream.Seek( STREAM_SEEK_TO_END );
      99           1 :     sal_Size nStrmSize = aStream.Tell();
     100           1 :     aStream.Seek( STREAM_SEEK_TO_BEGIN );
     101         269 :     while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
     102             :     {
     103             :         sal_uInt16 nOpcode, nLength;
     104             : 
     105         267 :         aStream >> nOpcode >> nLength;
     106         267 :         aPrgrsBar.Progress();
     107         267 :         if( nOpcode == LOTUS_EOF )
     108           1 :         bEOF = sal_True;
     109             : 
     110         266 :         else if( nOpcode == LOTUS_FILEPASSWD )
     111           0 :         return eERR_FILEPASSWD;
     112             : 
     113         266 :         else if( nOpcode < nOps )
     114          52 :         pOps[ nOpcode ] ( aStream, nLength );
     115             : 
     116         214 :         else if( eType == eWK123 &&
     117             :              nOpcode == LOTUS_PATTERN )
     118             :             {
     119             :         // This is really ugly - needs re-factoring ...
     120           2 :         aStream.SeekRel(nLength);
     121           2 :         aStream >> nOpcode >> nLength;
     122           4 :         if ( nOpcode == 0x29a)
     123             :         {
     124           1 :             aStream.SeekRel(nLength);
     125           1 :             aStream >> nOpcode >> nLength;
     126           1 :             if ( nOpcode == 0x804 )
     127             :             {
     128           1 :             aStream.SeekRel(nLength);
     129           1 :             OP_ApplyPatternArea123(aStream);
     130             :             }
     131             :             else
     132           0 :             aStream.SeekRel(nLength);
     133             :         }
     134             :         else
     135           1 :             aStream.SeekRel(nLength);
     136             :         }
     137             :         else
     138         212 :         aStream.SeekRel( nLength );
     139             :     }
     140             : 
     141           1 :     MemDelete();
     142             : 
     143           1 :     rDoc.CalcAfterLoad();
     144             : 
     145           1 :     return eERR_OK;
     146             : }
     147             : 
     148           1 : WKTYP ScanVersion( SvStream& aStream )
     149             : {
     150             :     // PREC:    pWKDatei:   Zeiger auf offene Datei
     151             :     // POST:    return:     Typ der Datei
     152             :     sal_uInt16          nOpcode, nVersNr, nRecLen;
     153             : 
     154             :     // erstes Byte muss wegen BOF zwingend 0 sein!
     155           1 :     aStream >> nOpcode;
     156           1 :     if( nOpcode != nBOF )
     157           0 :         return eWK_UNKNOWN;
     158             : 
     159           1 :     aStream >> nRecLen >> nVersNr;
     160             : 
     161           1 :     if( aStream.IsEof() )
     162           0 :         return eWK_Error;
     163             : 
     164           1 :     switch( nVersNr )
     165             :     {
     166             :         case 0x0404:
     167           0 :             if( nRecLen == 2 )
     168           0 :                 return eWK_1;
     169             :             else
     170           0 :                 return eWK_UNKNOWN;
     171             : 
     172             :         case 0x0406:
     173           0 :             if( nRecLen == 2 )
     174           0 :                 return eWK_2;
     175             :             else
     176           0 :                 return eWK_UNKNOWN;
     177             : 
     178             :         case 0x1000:
     179           0 :             aStream >> nVersNr;
     180           0 :             if( aStream.IsEof() ) return eWK_Error;
     181           0 :             if( nVersNr == 0x0004 && nRecLen == 26 )
     182             :                         {       // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
     183             :                 sal_Char aDummy[22];
     184           0 :                 aStream.Read( aDummy, 22 );
     185           0 :                 return aStream.IsEof() ? eWK_Error : eWK3;
     186             :             }
     187           0 :             break;
     188             :         case 0x1003:
     189           1 :             if( nRecLen == 0x1a )
     190           1 :                 return eWK123;
     191             :             else
     192           0 :                 return eWK_UNKNOWN;
     193             :         case 0x1005:
     194           0 :             if( nRecLen == 0x1a )
     195           0 :                 return eWK123;
     196             :             else
     197           0 :                 return eWK_UNKNOWN;
     198             :     }
     199             : 
     200           0 :     return eWK_UNKNOWN;
     201             : }
     202             : 
     203           1 : FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, CharSet eSrc )
     204             : {
     205           1 :     aStream.Seek( 0UL );
     206             : 
     207             :     // Zeiger auf Dokument global machen
     208           1 :     pDoc = pDocument;
     209             : 
     210           1 :     bEOF = false;
     211             : 
     212           1 :     eCharVon = eSrc;
     213             : 
     214             :     // Speicher besorgen
     215           1 :     if( !MemNew() )
     216           0 :         return eERR_NOMEM;
     217             : 
     218           1 :     InitPage(); // Seitenformat initialisieren (nur Tab 0!)
     219             : 
     220             :         // Progressbar starten
     221           1 :     ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
     222             : 
     223             :     // Datei-Typ ermitteln
     224           1 :     eTyp = ScanVersion( aStream );
     225             : 
     226           1 :     aLotusPatternPool.clear();
     227             : 
     228           1 :     return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );
     229           9 : }
     230             : 
     231             : 
     232             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10