bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / lotus / filter.cxx
blobb54233a9d9d839c274c2526b02d44b21c652dac0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 // Das geht: Versionserkennung WKS, WK1 und WK3
21 // ...Rest steht in op.cpp
23 //------------------------------------------------------------------------
25 #include <tools/solar.h>
26 #include <string.h>
27 #include <map>
29 #include "filter.hxx"
30 #include "document.hxx"
31 #include "compiler.hxx"
32 #include "scerrors.hxx"
34 #include "root.hxx"
35 #include "lotrange.hxx"
36 #include "optab.h"
37 #include "scmem.h"
38 #include "decl.h"
39 #include "tool.h"
41 #include "fprogressbar.hxx"
43 #include "op.h"
45 // Konstanten ------------------------------------------------------------
46 const sal_uInt16 nBOF = 0x0000;
50 // externe Variablen -----------------------------------------------------
51 extern WKTYP eTyp; // Typ der gerade in bearbeitung befindlichen Datei
52 WKTYP eTyp;
54 extern sal_Bool bEOF; // zeigt Ende der Datei
55 sal_Bool bEOF;
57 extern CharSet eCharVon;
58 CharSet eCharVon;
60 extern ScDocument* pDoc; // Aufhaenger zum Dokumentzugriff
61 ScDocument* pDoc;
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
69 LOTUS_ROOT* pLotusRoot = NULL;
72 std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
74 static FltError
75 generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
76 ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
78 OPCODE_FKT *pOps;
79 int nOps;
81 switch(eType)
83 case eWK_1:
84 case eWK_2:
85 pOps = pOpFkt;
86 nOps = FKT_LIMIT;
87 break;
88 case eWK123:
89 pOps = pOpFkt123;
90 nOps = FKT_LIMIT123;
91 break;
92 case eWK3: return eERR_NI;
93 case eWK_Error: return eERR_FORMAT;
94 default: return eERR_UNKN_WK;
97 // #i76299# seems that SvStream::IsEof() does not work correctly
98 aStream.Seek( STREAM_SEEK_TO_END );
99 sal_Size nStrmSize = aStream.Tell();
100 aStream.Seek( STREAM_SEEK_TO_BEGIN );
101 while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
103 sal_uInt16 nOpcode, nLength;
105 aStream >> nOpcode >> nLength;
106 aPrgrsBar.Progress();
107 if( nOpcode == LOTUS_EOF )
108 bEOF = sal_True;
110 else if( nOpcode == LOTUS_FILEPASSWD )
111 return eERR_FILEPASSWD;
113 else if( nOpcode < nOps )
114 pOps[ nOpcode ] ( aStream, nLength );
116 else if( eType == eWK123 &&
117 nOpcode == LOTUS_PATTERN )
119 // This is really ugly - needs re-factoring ...
120 aStream.SeekRel(nLength);
121 aStream >> nOpcode >> nLength;
122 if ( nOpcode == 0x29a)
124 aStream.SeekRel(nLength);
125 aStream >> nOpcode >> nLength;
126 if ( nOpcode == 0x804 )
128 aStream.SeekRel(nLength);
129 OP_ApplyPatternArea123(aStream);
131 else
132 aStream.SeekRel(nLength);
134 else
135 aStream.SeekRel(nLength);
137 else
138 aStream.SeekRel( nLength );
141 MemDelete();
143 rDoc.CalcAfterLoad();
145 return eERR_OK;
148 WKTYP ScanVersion( SvStream& aStream )
150 // PREC: pWKDatei: Zeiger auf offene Datei
151 // POST: return: Typ der Datei
152 sal_uInt16 nOpcode, nVersNr, nRecLen;
154 // erstes Byte muss wegen BOF zwingend 0 sein!
155 aStream >> nOpcode;
156 if( nOpcode != nBOF )
157 return eWK_UNKNOWN;
159 aStream >> nRecLen >> nVersNr;
161 if( aStream.IsEof() )
162 return eWK_Error;
164 switch( nVersNr )
166 case 0x0404:
167 if( nRecLen == 2 )
168 return eWK_1;
169 else
170 return eWK_UNKNOWN;
172 case 0x0406:
173 if( nRecLen == 2 )
174 return eWK_2;
175 else
176 return eWK_UNKNOWN;
178 case 0x1000:
179 aStream >> nVersNr;
180 if( aStream.IsEof() ) return eWK_Error;
181 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 aStream.Read( aDummy, 22 );
185 return aStream.IsEof() ? eWK_Error : eWK3;
187 break;
188 case 0x1003:
189 if( nRecLen == 0x1a )
190 return eWK123;
191 else
192 return eWK_UNKNOWN;
193 case 0x1005:
194 if( nRecLen == 0x1a )
195 return eWK123;
196 else
197 return eWK_UNKNOWN;
200 return eWK_UNKNOWN;
203 FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, CharSet eSrc )
205 aStream.Seek( 0UL );
207 // Zeiger auf Dokument global machen
208 pDoc = pDocument;
210 bEOF = false;
212 eCharVon = eSrc;
214 // Speicher besorgen
215 if( !MemNew() )
216 return eERR_NOMEM;
218 InitPage(); // Seitenformat initialisieren (nur Tab 0!)
220 // Progressbar starten
221 ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
223 // Datei-Typ ermitteln
224 eTyp = ScanVersion( aStream );
226 aLotusPatternPool.clear();
228 return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */