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>
27 #include <scerrors.hxx>
33 #include <fprogressbar.hxx>
34 #include "lotfilter.hxx"
35 #include <tools/stream.hxx>
38 generate_Opcodes(LotusContext
&rContext
, SvStream
& aStream
,
39 ScfStreamProgressBar
& aPrgrsBar
)
41 OPCODE_FKT
*pOps
= nullptr;
44 ErrCode nErr
= ERRCODE_NONE
;
46 switch (rContext
.eTyp
)
50 pOps
= LotusContext::pOpFkt
;
54 pOps
= LotusContext::pOpFkt123
;
58 nErr
= SCERR_IMPORT_NI
;
61 nErr
= SCERR_IMPORT_FORMAT
;
64 nErr
= SCERR_IMPORT_UNKNOWN_WK
;
68 if (nErr
!= ERRCODE_NONE
)
74 // #i76299# seems that SvStream::IsEof() does not work correctly
75 sal_uInt64
const nStrmSize
= aStream
.TellEnd();
76 aStream
.Seek( STREAM_SEEK_TO_BEGIN
);
77 while (!rContext
.bEOF
&& aStream
.good() && (aStream
.Tell() < nStrmSize
))
79 sal_uInt16
nOpcode(LOTUS_EOF
), nLength(0);
81 aStream
.ReadUInt16(nOpcode
).ReadUInt16(nLength
);
86 if( nOpcode
== LOTUS_EOF
)
88 else if( nOpcode
== LOTUS_FILEPASSWD
)
90 nErr
= SCERR_IMPORT_FILEPASSWD
;
93 else if( nOpcode
< nOps
)
96 pOps
[ nOpcode
] (rContext
, aStream
, nLength
);
98 else if (rContext
.eTyp
== eWK123
&& nOpcode
== LOTUS_PATTERN
)
100 // This is really ugly - needs re-factoring ...
101 aStream
.SeekRel(nLength
);
102 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
103 if ( nOpcode
== 0x29a)
105 aStream
.SeekRel(nLength
);
106 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
107 if ( nOpcode
== 0x804 )
109 aStream
.SeekRel(nLength
);
110 OP_ApplyPatternArea123(rContext
, aStream
);
113 aStream
.SeekRel(nLength
);
116 aStream
.SeekRel(nLength
);
119 aStream
.SeekRel( nLength
);
125 nErr
= SCERR_IMPORT_FORMAT
;
126 else if (nErr
== ERRCODE_NONE
)
127 rContext
.rDoc
.CalcAfterLoad();
132 static WKTYP
ScanVersion(SvStream
& aStream
)
134 // PREC: pWKFile: pointer to open file
135 // POST: return: type of file
136 sal_uInt16
nOpcode(0), nVersNr(0), nRecLen(0);
138 // first byte has to be 0 because of BOF!
139 aStream
.ReadUInt16( nOpcode
);
140 if (nOpcode
!= LotusContext::nBOF
)
143 aStream
.ReadUInt16( nRecLen
).ReadUInt16( nVersNr
);
163 aStream
.ReadUInt16( nVersNr
);
166 if( nVersNr
== 0x0004 && nRecLen
== 26 )
168 // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
170 aStream
.ReadBytes(aDummy
, 22);
171 return !aStream
.good() ? eWK_Error
: eWK3
;
175 if( nRecLen
== 0x1a )
180 if( nRecLen
== 0x1a )
189 ErrCode
ScImportLotus123old(LotusContext
& rContext
, SvStream
& aStream
, rtl_TextEncoding eSrc
)
193 // make document pointer global
194 rContext
.bEOF
= false;
195 rContext
.eCharset
= eSrc
;
198 if( !MemNew(rContext
) )
199 return SCERR_IMPORT_OUTOFMEM
;
201 // initialize page format (only Tab 0!)
202 // initialize page format; meaning: get defaults from SC TODO:
203 //scGetPageFormat( 0, &aPage );
206 ScfStreamProgressBar
aPrgrsBar( aStream
, rContext
.rDoc
.GetDocumentShell() );
209 rContext
.eTyp
= ScanVersion(aStream
);
210 rContext
.aLotusPatternPool
.clear();
212 return generate_Opcodes(rContext
, aStream
, aPrgrsBar
);
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */