Bump version to 4.3-4
[LibreOffice.git] / sc / source / filter / lotus / filter.cxx
blob79a74c815590938a0b31df847d98c14a250585ce
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 #include <string.h>
24 #include <map>
26 #include "filter.hxx"
27 #include "document.hxx"
28 #include "compiler.hxx"
29 #include "scerrors.hxx"
31 #include "root.hxx"
32 #include "lotrange.hxx"
33 #include "optab.h"
34 #include "scmem.h"
35 #include "decl.h"
36 #include "tool.h"
38 #include "fprogressbar.hxx"
40 #include "op.h"
42 // Konstanten
43 const sal_uInt16 nBOF = 0x0000;
45 // externe Variablen
46 extern WKTYP eTyp; // Typ der gerade in bearbeitung befindlichen Datei
47 WKTYP eTyp;
49 extern bool bEOF; // zeigt Ende der Datei
50 bool bEOF;
52 extern rtl_TextEncoding eCharVon;
53 rtl_TextEncoding eCharVon;
55 extern ScDocument* pDoc; // Aufhaenger zum Dokumentzugriff
56 ScDocument* pDoc;
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
64 LOTUS_ROOT* pLotusRoot = NULL;
67 std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
69 static FltError
70 generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
71 ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
73 OPCODE_FKT *pOps;
74 int nOps;
76 switch(eType)
78 case eWK_1:
79 case eWK_2:
80 pOps = pOpFkt;
81 nOps = FKT_LIMIT;
82 break;
83 case eWK123:
84 pOps = pOpFkt123;
85 nOps = FKT_LIMIT123;
86 break;
87 case eWK3: return eERR_NI;
88 case eWK_Error: return eERR_FORMAT;
89 default: return eERR_UNKN_WK;
92 // #i76299# seems that SvStream::IsEof() does not work correctly
93 aStream.Seek( STREAM_SEEK_TO_END );
94 sal_Size nStrmSize = aStream.Tell();
95 aStream.Seek( STREAM_SEEK_TO_BEGIN );
96 while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
98 sal_uInt16 nOpcode, nLength;
100 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
101 aPrgrsBar.Progress();
102 if( nOpcode == LOTUS_EOF )
103 bEOF = true;
105 else if( nOpcode == LOTUS_FILEPASSWD )
106 return eERR_FILEPASSWD;
108 else if( nOpcode < nOps )
109 pOps[ nOpcode ] ( aStream, nLength );
111 else if( eType == eWK123 &&
112 nOpcode == LOTUS_PATTERN )
114 // This is really ugly - needs re-factoring ...
115 aStream.SeekRel(nLength);
116 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
117 if ( nOpcode == 0x29a)
119 aStream.SeekRel(nLength);
120 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
121 if ( nOpcode == 0x804 )
123 aStream.SeekRel(nLength);
124 OP_ApplyPatternArea123(aStream);
126 else
127 aStream.SeekRel(nLength);
129 else
130 aStream.SeekRel(nLength);
132 else
133 aStream.SeekRel( nLength );
136 MemDelete();
138 rDoc.CalcAfterLoad();
140 return eERR_OK;
143 WKTYP ScanVersion( SvStream& aStream )
145 // PREC: pWKDatei: Zeiger auf offene Datei
146 // POST: return: Typ der Datei
147 sal_uInt16 nOpcode, nVersNr, nRecLen;
149 // erstes Byte muss wegen BOF zwingend 0 sein!
150 aStream.ReadUInt16( nOpcode );
151 if( nOpcode != nBOF )
152 return eWK_UNKNOWN;
154 aStream.ReadUInt16( nRecLen ).ReadUInt16( nVersNr );
156 if( aStream.IsEof() )
157 return eWK_Error;
159 switch( nVersNr )
161 case 0x0404:
162 if( nRecLen == 2 )
163 return eWK_1;
164 else
165 return eWK_UNKNOWN;
167 case 0x0406:
168 if( nRecLen == 2 )
169 return eWK_2;
170 else
171 return eWK_UNKNOWN;
173 case 0x1000:
174 aStream.ReadUInt16( nVersNr );
175 if( aStream.IsEof() ) return eWK_Error;
176 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 aStream.Read( aDummy, 22 );
180 return aStream.IsEof() ? eWK_Error : eWK3;
182 break;
183 case 0x1003:
184 if( nRecLen == 0x1a )
185 return eWK123;
186 else
187 return eWK_UNKNOWN;
188 case 0x1005:
189 if( nRecLen == 0x1a )
190 return eWK123;
191 else
192 return eWK_UNKNOWN;
195 return eWK_UNKNOWN;
198 FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, rtl_TextEncoding eSrc )
200 aStream.Seek( 0UL );
202 // Zeiger auf Dokument global machen
203 pDoc = pDocument;
205 bEOF = false;
207 eCharVon = eSrc;
209 // Speicher besorgen
210 if( !MemNew() )
211 return eERR_NOMEM;
213 InitPage(); // Seitenformat initialisieren (nur Tab 0!)
215 // Progressbar starten
216 ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
218 // Datei-Typ ermitteln
219 eTyp = ScanVersion( aStream );
221 aLotusPatternPool.clear();
223 return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */