1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 #include "document.hxx"
31 #include "compiler.hxx"
32 #include "scerrors.hxx"
35 #include "lotrange.hxx"
41 #include "fprogressbar.hxx"
45 // Konstanten ------------------------------------------------------------
46 const sal_uInt16 nBOF
= 0x0000;
50 // externe Variablen -----------------------------------------------------
51 extern WKTYP eTyp
; // Typ der gerade in bearbeitung befindlichen Datei
54 extern sal_Bool bEOF
; // zeigt Ende der Datei
57 extern CharSet eCharVon
;
60 extern ScDocument
* pDoc
; // Aufhaenger zum Dokumentzugriff
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
;
75 generate_Opcodes( SvStream
& aStream
, ScDocument
& rDoc
,
76 ScfStreamProgressBar
& aPrgrsBar
, WKTYP eType
)
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
)
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
);
132 aStream
.SeekRel(nLength
);
135 aStream
.SeekRel(nLength
);
138 aStream
.SeekRel( nLength
);
143 rDoc
.CalcAfterLoad();
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!
156 if( nOpcode
!= nBOF
)
159 aStream
>> nRecLen
>> nVersNr
;
161 if( aStream
.IsEof() )
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)
184 aStream
.Read( aDummy
, 22 );
185 return aStream
.IsEof() ? eWK_Error
: eWK3
;
189 if( nRecLen
== 0x1a )
194 if( nRecLen
== 0x1a )
203 FltError
ScImportLotus123old( SvStream
& aStream
, ScDocument
* pDocument
, CharSet eSrc
)
207 // Zeiger auf Dokument global machen
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: */