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
27 #include "document.hxx"
28 #include "compiler.hxx"
29 #include "scerrors.hxx"
32 #include "lotrange.hxx"
38 #include "fprogressbar.hxx"
43 const sal_uInt16 nBOF
= 0x0000;
46 extern WKTYP eTyp
; // Typ der gerade in bearbeitung befindlichen Datei
49 extern bool bEOF
; // zeigt Ende der Datei
52 extern rtl_TextEncoding eCharVon
;
53 rtl_TextEncoding eCharVon
;
55 extern ScDocument
* pDoc
; // Aufhaenger zum Dokumentzugriff
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
;
70 generate_Opcodes( SvStream
& aStream
, ScDocument
& rDoc
,
71 ScfStreamProgressBar
& aPrgrsBar
, WKTYP eType
)
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
)
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
);
127 aStream
.SeekRel(nLength
);
130 aStream
.SeekRel(nLength
);
133 aStream
.SeekRel( nLength
);
138 rDoc
.CalcAfterLoad();
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
)
154 aStream
.ReadUInt16( nRecLen
).ReadUInt16( nVersNr
);
156 if( aStream
.IsEof() )
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)
179 aStream
.Read( aDummy
, 22 );
180 return aStream
.IsEof() ? eWK_Error
: eWK3
;
184 if( nRecLen
== 0x1a )
189 if( nRecLen
== 0x1a )
198 FltError
ScImportLotus123old( SvStream
& aStream
, ScDocument
* pDocument
, rtl_TextEncoding eSrc
)
202 // Zeiger auf Dokument global machen
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: */