merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / lotus / filter.cxx
blob3a6e39b7d818f37c68865cd69ae15abbc145119d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 // Das geht: Versionserkennung WKS, WK1 und WK3
31 // ...Rest steht in op.cpp
33 //------------------------------------------------------------------------
35 #include <tools/solar.h>
36 #include <string.h>
37 #include <map>
39 #include "filter.hxx"
40 #include "document.hxx"
41 #include "compiler.hxx"
42 #include "scerrors.hxx"
44 #include "root.hxx"
45 #include "lotrange.hxx"
46 #include "optab.h"
47 #include "scmem.h"
48 #include "decl.h"
49 #include "tool.h"
51 #include "fprogressbar.hxx"
53 #include "op.h"
55 // Konstanten ------------------------------------------------------------
56 const UINT16 nBOF = 0x0000;
60 // externe Variablen -----------------------------------------------------
61 extern WKTYP eTyp; // Typ der gerade in bearbeitung befindlichen Datei
62 WKTYP eTyp;
64 extern BOOL bEOF; // zeigt Ende der Datei
65 BOOL bEOF;
67 extern CharSet eCharNach; // Zeichenkonvertierung von->nach
68 CharSet eCharNach;
70 extern CharSet eCharVon;
71 CharSet eCharVon;
73 extern ScDocument* pDoc; // Aufhaenger zum Dokumentzugriff
74 ScDocument* pDoc;
77 extern sal_Char* pPuffer; // -> memory.cxx
78 extern sal_Char* pDummy1; // -> memory.cxx
80 extern OPCODE_FKT pOpFkt[ FKT_LIMIT ];
81 // -> optab.cxx, Tabelle moeglicher Opcodes
82 extern OPCODE_FKT pOpFkt123[ FKT_LIMIT123 ];
83 // -> optab.cxx, Table of possible Opcodes
85 extern long nDateiLaenge; // -> datei.cpp, ...der gerade offenen Datei
87 LOTUS_ROOT* pLotusRoot = NULL;
90 std::map<UINT16, ScPatternAttr> aLotusPatternPool;
92 static FltError
93 generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
94 ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
96 OPCODE_FKT *pOps;
97 int nOps;
99 switch(eType)
101 case eWK_1:
102 case eWK_2:
103 pOps = pOpFkt;
104 nOps = FKT_LIMIT;
105 break;
106 case eWK123:
107 pOps = pOpFkt123;
108 nOps = FKT_LIMIT123;
109 break;
110 case eWK3: return eERR_NI;
111 case eWK_Error: return eERR_FORMAT;
112 default: return eERR_UNKN_WK;
115 // #i76299# seems that SvStream::IsEof() does not work correctly
116 aStream.Seek( STREAM_SEEK_TO_END );
117 sal_Size nStrmSize = aStream.Tell();
118 aStream.Seek( STREAM_SEEK_TO_BEGIN );
119 while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
121 UINT16 nOpcode, nLength;
123 aStream >> nOpcode >> nLength;
124 aPrgrsBar.Progress();
125 if( nOpcode == LOTUS_EOF )
126 bEOF = TRUE;
128 else if( nOpcode == LOTUS_FILEPASSWD )
129 return eERR_FILEPASSWD;
131 else if( nOpcode < nOps )
132 pOps[ nOpcode ] ( aStream, nLength );
134 else if( eType == eWK123 &&
135 nOpcode == LOTUS_PATTERN )
137 // This is really ugly - needs re-factoring ...
138 aStream.SeekRel(nLength);
139 aStream >> nOpcode >> nLength;
140 if ( nOpcode == 0x29a)
142 aStream.SeekRel(nLength);
143 aStream >> nOpcode >> nLength;
144 if ( nOpcode == 0x804 )
146 aStream.SeekRel(nLength);
147 OP_ApplyPatternArea123(aStream);
149 else
150 aStream.SeekRel(nLength);
152 else
153 aStream.SeekRel(nLength);
155 else
156 aStream.SeekRel( nLength );
159 MemDelete();
161 rDoc.CalcAfterLoad();
163 return eERR_OK;
166 WKTYP ScanVersion( SvStream& aStream )
168 // PREC: pWKDatei: Zeiger auf offene Datei
169 // POST: return: Typ der Datei
170 UINT16 nOpcode, nVersNr, nRecLen;
172 // erstes Byte muss wegen BOF zwingend 0 sein!
173 aStream >> nOpcode;
174 if( nOpcode != nBOF )
175 return eWK_UNKNOWN;
177 aStream >> nRecLen >> nVersNr;
179 if( aStream.IsEof() )
180 return eWK_Error;
182 switch( nVersNr )
184 case 0x0404:
185 if( nRecLen == 2 )
186 return eWK_1;
187 else
188 return eWK_UNKNOWN;
190 case 0x0406:
191 if( nRecLen == 2 )
192 return eWK_2;
193 else
194 return eWK_UNKNOWN;
196 case 0x1000:
197 aStream >> nVersNr;
198 if( aStream.IsEof() ) return eWK_Error;
199 if( nVersNr == 0x0004 && nRecLen == 26 )
200 { // 4 Bytes von 26 gelesen->22 ueberlesen
201 aStream.Read( pDummy1, 22 );
202 return eWK3;
204 break;
205 case 0x1003:
206 if( nRecLen == 0x1a )
207 return eWK123;
208 else
209 return eWK_UNKNOWN;
210 case 0x1005:
211 if( nRecLen == 0x1a )
212 return eWK123;
213 else
214 return eWK_UNKNOWN;
217 return eWK_UNKNOWN;
220 FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, CharSet eSrc )
222 aStream.Seek( 0UL );
224 // Zeiger auf Dokument global machen
225 pDoc = pDocument;
227 bEOF = FALSE;
229 eCharVon = eSrc;
231 // Speicher besorgen
232 if( !MemNew() )
233 return eERR_NOMEM;
235 InitPage(); // Seitenformat initialisieren (nur Tab 0!)
237 // Progressbar starten
238 ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
240 // Datei-Typ ermitteln
241 eTyp = ScanVersion( aStream );
243 aLotusPatternPool.clear();
245 return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );