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 // Discover WKS, WK1 and WK3; s.a op.cpp
25 #include <document.hxx>
26 #include <scerrors.hxx>
32 #include <fprogressbar.hxx>
33 #include "lotfilter.hxx"
34 #include <tools/stream.hxx>
37 generate_Opcodes(LotusContext
&rContext
, SvStream
& aStream
,
38 ScfStreamProgressBar
& aPrgrsBar
)
40 OPCODE_FKT
*pOps
= nullptr;
43 ErrCode nErr
= ERRCODE_NONE
;
45 switch (rContext
.eTyp
)
49 pOps
= LotusContext::pOpFkt
;
53 pOps
= LotusContext::pOpFkt123
;
57 nErr
= SCERR_IMPORT_NI
;
60 nErr
= SCERR_IMPORT_FORMAT
;
63 nErr
= SCERR_IMPORT_UNKNOWN_WK
;
67 if (nErr
!= ERRCODE_NONE
)
73 // #i76299# seems that SvStream::IsEof() does not work correctly
74 sal_uInt64
const nStrmSize
= aStream
.TellEnd();
75 aStream
.Seek( STREAM_SEEK_TO_BEGIN
);
76 while (!rContext
.bEOF
&& aStream
.good() && (aStream
.Tell() < nStrmSize
))
78 sal_uInt16
nOpcode(LOTUS_EOF
), nLength(0);
80 aStream
.ReadUInt16(nOpcode
).ReadUInt16(nLength
);
85 if( nOpcode
== LOTUS_EOF
)
87 else if( nOpcode
== LOTUS_FILEPASSWD
)
89 nErr
= SCERR_IMPORT_FILEPASSWD
;
92 else if( nOpcode
< nOps
)
93 pOps
[ nOpcode
] (rContext
, aStream
, nLength
);
94 else if (rContext
.eTyp
== eWK123
&& nOpcode
== LOTUS_PATTERN
)
96 // This is really ugly - needs re-factoring ...
97 aStream
.SeekRel(nLength
);
98 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
99 if ( nOpcode
== 0x29a)
101 aStream
.SeekRel(nLength
);
102 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
103 if ( nOpcode
== 0x804 )
105 aStream
.SeekRel(nLength
);
106 OP_ApplyPatternArea123(rContext
, aStream
);
109 aStream
.SeekRel(nLength
);
112 aStream
.SeekRel(nLength
);
115 aStream
.SeekRel( nLength
);
121 nErr
= SCERR_IMPORT_FORMAT
;
122 else if (nErr
== ERRCODE_NONE
)
123 rContext
.pDoc
->CalcAfterLoad();
128 static WKTYP
ScanVersion(SvStream
& aStream
)
130 // PREC: pWKFile: pointer to open file
131 // POST: return: type of file
132 sal_uInt16
nOpcode(0), nVersNr(0), nRecLen(0);
134 // first byte has to be 0 because of BOF!
135 aStream
.ReadUInt16( nOpcode
);
136 if (nOpcode
!= LotusContext::nBOF
)
139 aStream
.ReadUInt16( nRecLen
).ReadUInt16( nVersNr
);
159 aStream
.ReadUInt16( nVersNr
);
162 if( nVersNr
== 0x0004 && nRecLen
== 26 )
164 // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
166 aStream
.ReadBytes(aDummy
, 22);
167 return !aStream
.good() ? eWK_Error
: eWK3
;
171 if( nRecLen
== 0x1a )
176 if( nRecLen
== 0x1a )
185 ErrCode
ScImportLotus123old(LotusContext
& rContext
, SvStream
& aStream
, ScDocument
* pDocument
, rtl_TextEncoding eSrc
)
189 // make document pointer global
190 rContext
.pDoc
= pDocument
;
191 rContext
.bEOF
= false;
192 rContext
.eCharVon
= eSrc
;
195 if( !MemNew(rContext
) )
196 return SCERR_IMPORT_OUTOFMEM
;
198 // initialize page format (only Tab 0!)
199 // initialize page format; meaning: get defaults from SC TODO:
200 //scGetPageFormat( 0, &aPage );
203 ScfStreamProgressBar
aPrgrsBar( aStream
, pDocument
->GetDocumentShell() );
206 rContext
.eTyp
= ScanVersion(aStream
);
207 rContext
.aLotusPatternPool
.clear();
209 return generate_Opcodes(rContext
, aStream
, aPrgrsBar
);
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */