LCOV - code coverage report
Current view: top level - sc/source/filter/lotus - filter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 59 78 75.6 %
Date: 2015-06-13 12:38:46 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             : //  Discover WKS, WK1 und WK3; s.a op.cpp
      21             : 
      22             : #include <string.h>
      23             : #include <map>
      24             : 
      25             : #include "filter.hxx"
      26             : #include "document.hxx"
      27             : #include "compiler.hxx"
      28             : #include "scerrors.hxx"
      29             : 
      30             : #include "root.hxx"
      31             : #include "lotrange.hxx"
      32             : #include "optab.h"
      33             : #include "scmem.h"
      34             : #include "decl.h"
      35             : #include "tool.h"
      36             : #include "fprogressbar.hxx"
      37             : #include "lotfilter.hxx"
      38             : 
      39             : static FltError
      40           4 : generate_Opcodes(LotusContext &rContext, SvStream& aStream,
      41             :                   ScfStreamProgressBar& aPrgrsBar)
      42             : {
      43             :     OPCODE_FKT *pOps;
      44             :     int         nOps;
      45             : 
      46           4 :     switch (rContext.eTyp)
      47             :     {
      48             :         case eWK_1:
      49             :         case eWK_2:
      50           1 :         pOps = rContext.pOpFkt;
      51           1 :         nOps = FKT_LIMIT;
      52           1 :         break;
      53             :         case eWK123:
      54           2 :         pOps = rContext.pOpFkt123;
      55           2 :         nOps = FKT_LIMIT123;
      56           2 :         break;
      57           0 :         case eWK3:      return eERR_NI;
      58           0 :         case eWK_Error: return eERR_FORMAT;
      59           1 :         default:        return eERR_UNKN_WK;
      60             :      }
      61             : 
      62             :     // #i76299# seems that SvStream::IsEof() does not work correctly
      63           3 :     aStream.Seek( STREAM_SEEK_TO_END );
      64           3 :     sal_Size nStrmSize = aStream.Tell();
      65           3 :     aStream.Seek( STREAM_SEEK_TO_BEGIN );
      66        2652 :     while( !rContext.bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
      67             :     {
      68             :         sal_uInt16 nOpcode, nLength;
      69             : 
      70        2646 :         aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
      71        2646 :         aPrgrsBar.Progress();
      72        2646 :         if( nOpcode == LOTUS_EOF )
      73           3 :             rContext.bEOF = true;
      74        2643 :         else if( nOpcode == LOTUS_FILEPASSWD )
      75           0 :             return eERR_FILEPASSWD;
      76        2643 :         else if( nOpcode < nOps )
      77         364 :             pOps[ nOpcode ] (rContext, aStream, nLength);
      78        2279 :         else if (rContext.eTyp == eWK123 && nOpcode == LOTUS_PATTERN)
      79             :         {
      80             :             // This is really ugly - needs re-factoring ...
      81           2 :             aStream.SeekRel(nLength);
      82           2 :             aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
      83           4 :             if ( nOpcode == 0x29a)
      84             :             {
      85           1 :                 aStream.SeekRel(nLength);
      86           1 :                 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
      87           1 :                 if ( nOpcode == 0x804 )
      88             :                 {
      89           1 :                     aStream.SeekRel(nLength);
      90           1 :                     OP_ApplyPatternArea123(rContext, aStream);
      91             :                 }
      92             :                 else
      93           0 :                     aStream.SeekRel(nLength);
      94             :             }
      95             :             else
      96           1 :                 aStream.SeekRel(nLength);
      97             :         }
      98             :         else
      99        2277 :             aStream.SeekRel( nLength );
     100             :     }
     101             : 
     102           3 :     MemDelete(rContext);
     103             : 
     104           3 :     rContext.pDoc->CalcAfterLoad();
     105             : 
     106           3 :     return eERR_OK;
     107             : }
     108             : 
     109           4 : WKTYP ScanVersion(LotusContext &rContext, SvStream& aStream)
     110             : {
     111             :     // PREC:    pWKDatei:   pointer to open file
     112             :     // POST:    return:     type of file
     113           4 :     sal_uInt16 nOpcode(0), nVersNr(0), nRecLen(0);
     114             : 
     115             :     // first byte has to be 0 because of BOF!
     116           4 :     aStream.ReadUInt16( nOpcode );
     117           4 :     if (nOpcode != rContext.nBOF)
     118           1 :         return eWK_UNKNOWN;
     119             : 
     120           3 :     aStream.ReadUInt16( nRecLen ).ReadUInt16( nVersNr );
     121             : 
     122           3 :     if( aStream.IsEof() )
     123           0 :         return eWK_Error;
     124             : 
     125           3 :     switch( nVersNr )
     126             :     {
     127             :         case 0x0404:
     128           1 :             if( nRecLen == 2 )
     129           1 :                 return eWK_1;
     130             :             else
     131           0 :                 return eWK_UNKNOWN;
     132             : 
     133             :         case 0x0406:
     134           0 :             if( nRecLen == 2 )
     135           0 :                 return eWK_2;
     136             :             else
     137           0 :                 return eWK_UNKNOWN;
     138             : 
     139             :         case 0x1000:
     140           0 :             aStream.ReadUInt16( nVersNr );
     141           0 :             if( aStream.IsEof() ) return eWK_Error;
     142           0 :             if( nVersNr == 0x0004 && nRecLen == 26 )
     143             :                         {       // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
     144             :                 sal_Char aDummy[22];
     145           0 :                 aStream.Read( aDummy, 22 );
     146           0 :                 return aStream.IsEof() ? eWK_Error : eWK3;
     147             :             }
     148           0 :             break;
     149             :         case 0x1003:
     150           1 :             if( nRecLen == 0x1a )
     151           1 :                 return eWK123;
     152             :             else
     153           0 :                 return eWK_UNKNOWN;
     154             :         case 0x1005:
     155           1 :             if( nRecLen == 0x1a )
     156           1 :                 return eWK123;
     157             :             else
     158           0 :                 return eWK_UNKNOWN;
     159             :     }
     160             : 
     161           0 :     return eWK_UNKNOWN;
     162             : }
     163             : 
     164           4 : FltError ScImportLotus123old(LotusContext& rContext, SvStream& aStream, ScDocument* pDocument, rtl_TextEncoding eSrc )
     165             : {
     166           4 :     aStream.Seek( 0UL );
     167             : 
     168             :     // make document pointer global
     169           4 :     rContext.pDoc = pDocument;
     170           4 :     rContext.bEOF = false;
     171           4 :     rContext.eCharVon = eSrc;
     172             : 
     173             :     // allocate memory
     174           4 :     if( !MemNew(rContext) )
     175           0 :         return eERR_NOMEM;
     176             : 
     177             :     // initialize page format (only Tab 0!)
     178             :     // initialize page format; meaning: get defaults from SC TODO:
     179             :     //scGetPageFormat( 0, &aPage );
     180             : 
     181             :     // start progressbar
     182           4 :     ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
     183             : 
     184             :     // detect file type
     185           4 :     rContext.eTyp = ScanVersion(rContext, aStream);
     186           4 :     rContext.aLotusPatternPool.clear();
     187             : 
     188           4 :     return generate_Opcodes(rContext, aStream, aPrgrsBar);
     189          30 : }
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11