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 und WK3; s.a op.cpp
26 #include "document.hxx"
27 #include "compiler.hxx"
28 #include "scerrors.hxx"
31 #include "lotrange.hxx"
36 #include "fprogressbar.hxx"
37 #include "lotfilter.hxx"
40 generate_Opcodes(LotusContext
&rContext
, SvStream
& aStream
,
41 ScfStreamProgressBar
& aPrgrsBar
)
46 switch (rContext
.eTyp
)
50 pOps
= rContext
.pOpFkt
;
54 pOps
= rContext
.pOpFkt123
;
57 case eWK3
: return eERR_NI
;
58 case eWK_Error
: return eERR_FORMAT
;
59 default: return eERR_UNKN_WK
;
62 // #i76299# seems that SvStream::IsEof() does not work correctly
63 aStream
.Seek( STREAM_SEEK_TO_END
);
64 sal_Size nStrmSize
= aStream
.Tell();
65 aStream
.Seek( STREAM_SEEK_TO_BEGIN
);
66 while( !rContext
.bEOF
&& !aStream
.IsEof() && (aStream
.Tell() < nStrmSize
) )
68 sal_uInt16 nOpcode
, nLength
;
70 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
72 if( nOpcode
== LOTUS_EOF
)
74 else if( nOpcode
== LOTUS_FILEPASSWD
)
75 return eERR_FILEPASSWD
;
76 else if( nOpcode
< nOps
)
77 pOps
[ nOpcode
] (rContext
, aStream
, nLength
);
78 else if (rContext
.eTyp
== eWK123
&& nOpcode
== LOTUS_PATTERN
)
80 // This is really ugly - needs re-factoring ...
81 aStream
.SeekRel(nLength
);
82 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
83 if ( nOpcode
== 0x29a)
85 aStream
.SeekRel(nLength
);
86 aStream
.ReadUInt16( nOpcode
).ReadUInt16( nLength
);
87 if ( nOpcode
== 0x804 )
89 aStream
.SeekRel(nLength
);
90 OP_ApplyPatternArea123(rContext
, aStream
);
93 aStream
.SeekRel(nLength
);
96 aStream
.SeekRel(nLength
);
99 aStream
.SeekRel( nLength
);
104 rContext
.pDoc
->CalcAfterLoad();
109 WKTYP
ScanVersion(LotusContext
&rContext
, SvStream
& aStream
)
111 // PREC: pWKDatei: pointer to open file
112 // POST: return: type of file
113 sal_uInt16
nOpcode(0), nVersNr(0), nRecLen(0);
115 // first byte has to be 0 because of BOF!
116 aStream
.ReadUInt16( nOpcode
);
117 if (nOpcode
!= rContext
.nBOF
)
120 aStream
.ReadUInt16( nRecLen
).ReadUInt16( nVersNr
);
122 if( aStream
.IsEof() )
140 aStream
.ReadUInt16( nVersNr
);
141 if( aStream
.IsEof() ) return eWK_Error
;
142 if( nVersNr
== 0x0004 && nRecLen
== 26 )
143 { // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
145 aStream
.Read( aDummy
, 22 );
146 return aStream
.IsEof() ? eWK_Error
: eWK3
;
150 if( nRecLen
== 0x1a )
155 if( nRecLen
== 0x1a )
164 FltError
ScImportLotus123old(LotusContext
& rContext
, SvStream
& aStream
, ScDocument
* pDocument
, rtl_TextEncoding eSrc
)
168 // make document pointer global
169 rContext
.pDoc
= pDocument
;
170 rContext
.bEOF
= false;
171 rContext
.eCharVon
= eSrc
;
174 if( !MemNew(rContext
) )
177 // initialize page format (only Tab 0!)
178 // initialize page format; meaning: get defaults from SC TODO:
179 //scGetPageFormat( 0, &aPage );
182 ScfStreamProgressBar
aPrgrsBar( aStream
, pDocument
->GetDocumentShell() );
185 rContext
.eTyp
= ScanVersion(rContext
, aStream
);
186 rContext
.aLotusPatternPool
.clear();
188 return generate_Opcodes(rContext
, aStream
, aPrgrsBar
);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */