LibreOffice Module sc (master) 1
lotread.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <document.hxx>
21#include <docoptio.hxx>
22
23#include <scdll.hxx>
24#include <scerrors.hxx>
25#include "lotfilter.hxx"
26#include <lotimpop.hxx>
27#include <lotattr.hxx>
28#include <fprogressbar.hxx>
29
30#include <sal/log.hxx>
31
33{
34 enum STATE
35 {
36 S_START, // analyse first BOF
37 S_WK3, // in WK3-Section
38 S_WK4,
39 S_FM3,
40 S_END // Import finished
41 };
42
43 sal_uInt16 nOp;
44 sal_uInt16 nRecLen;
45 sal_uInt32 nNextRec = 0;
46 ErrCode eRet = ERRCODE_NONE;
47// ScFormulaCell *pLastFormCell;
48
49 STATE eCurrent = S_START;
50
51 nTab = 0;
52 nExtTab = -2;
53
54 pIn->Seek( nNextRec );
55
56 // start progressbar
58 LotusContext &rContext = aConv.getContext();
59 while( eCurrent != S_END )
60 {
61 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
62
63 if (!pIn->good() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4)
64 {
66 eCurrent = S_END;
67 if (!pIn->good())
68 break; // while
69 }
70
71 nNextRec += nRecLen + 4;
72
73 switch( eCurrent )
74 {
75
76 case S_START: // S_START
77 if( nOp )
78 {
80 eCurrent = S_END;
81 }
82 else
83 {
84 if( nRecLen > 2 )
85 {
86 Bof();
87 switch (rContext.eFirstType)
88 {
89 case Lotus123Typ::WK3: eCurrent = S_WK3; break;
90 case Lotus123Typ::WK4: eCurrent = S_WK4; break;
91 default:
93 eCurrent = S_END;
94 }
95 }
96 else
97 {
98 eCurrent = S_END; // TODO: add here something for <= WK1!
99 eRet = ErrCode(0xFFFFFFFF);
100 }
101 }
102 break;
103
104 case S_WK3: // S_WK3
105 case S_WK4: // S_WK4
106 switch( nOp )
107 {
108 case 0x0001: // EOF
109 eCurrent = S_FM3;
110 nTab++;
111 break;
112
113 case 0x0002: // PASSWORD
115 eCurrent = S_END;
116 break;
117
118 case 0x0007: // COLUMNWIDTH
119 Columnwidth( nRecLen );
120 break;
121
122 case 0x0008: // HIDDENCOLUMN
123 Hiddencolumn( nRecLen );
124 break;
125
126 case 0x0009: // USERRANGE
127 Userrange();
128 break;
129
130 case 0x0013: // FORMAT
131
132 break;
133 case 0x0014: // ERRCELL
134 Errcell();
135 break;
136
137 case 0x0015: // NACELL
138 Nacell();
139 break;
140
141 case 0x0016: // LABELCELL
142 Labelcell();
143 break;
144
145 case 0x0017: // NUMBERCELL
146 Numbercell();
147 break;
148
149 case 0x0018: // SMALLNUMCELL
150 Smallnumcell();
151 break;
152
153 case 0x0019: // FORMULACELL
154 Formulacell( nRecLen );
155 break;
156
157 case 0x001b: // extended attributes
158 if (nRecLen > 2)
159 {
160 sal_uInt16 nSubType(0);
161 Read( nSubType );
162 nRecLen -= 2;
163 switch( nSubType )
164 {
165 case 2007: // ROW PRESENTATION
166 RowPresentation( nRecLen );
167 break;
168
169 case 14000: // NAMED SHEET
170 NamedSheet();
171 break;
172 }
173 }
174 else
175 {
176 eRet = SCERR_IMPORT_FORMAT;
177 eCurrent = S_END;
178 }
179 }
180
181 break;
182
183 case S_FM3: // S_FM3
184 break;
185
186 case S_END: // S_END
187 break;
188 }
189
190 SAL_WARN_IF( nNextRec < pIn->Tell(), "sc.filter",
191 "*ImportLotus::Read(): Read too much..." );
192
193 pIn->Seek( nNextRec );
194 aPrgrsBar.Progress();
195 }
196
197 // TODO: eliminate stupid names
198 SCTAB nTabs = rD.GetTableCount();
199 SCTAB nCnt;
200 OUString aTabName;
201 OUString aBaseName;
202 if( nTabs != 0 )
203 {
204 if( nTabs > 1 )
205 {
206 rD.GetName( 0, aBaseName );
207 aBaseName = aBaseName.copy(0, aBaseName.getLength()-1);
208 }
209 for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
210 {
211 SAL_WARN_IF( !rD.HasTable( nCnt ), "sc.filter",
212 "-ImportLotus::Read(): Where is my table?!" );
213 rD.GetName( nCnt, aTabName );
214 if( aTabName == "temp" )
215 {
216 aTabName = aBaseName;
217 rD.CreateValidTabName( aTabName );
218 rD.RenameTab( nCnt, aTabName );
219 }
220 }
221 }
222
223 return eRet;
224}
225
227{
228 ErrCode eRet = parse();
230 return eRet;
231}
232
234{
235 pIn = &rIn;
236
237 bool bRead = true;
238 sal_uInt16 nOp;
239 sal_uInt16 nRecLen;
240 sal_uInt32 nNextRec = 0;
241 ErrCode eRet = ERRCODE_NONE;
242
243 nTab = 0;
244 nExtTab = -1;
245
246 pIn->Seek( nNextRec );
247
248 // start progressbar
250 LotusContext &rContext = aConv.getContext();
251 while( bRead )
252 {
253 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
254
255 if (!pIn->good() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4)
256 bRead = false;
257 else
258 {
259 nNextRec += nRecLen + 4;
260
261 switch( nOp )
262 {
263 case 0x0000: // BOF
264 if( nRecLen != 26 || !BofFm3() )
265 {
266 bRead = false;
267 eRet = SCERR_IMPORT_FORMAT;
268 }
269 break;
270
271 case 0x0001: // EOF
272 bRead = false;
273 SAL_WARN_IF( nTab != 0, "sc.filter",
274 "-ImportLotus::Read( SvStream& ): EOF twice!" );
275 nTab++;
276 break;
277
278 case 174: // FONT_FACE
279 Font_Face();
280 break;
281
282 case 176: // FONT_TYPE
283 Font_Type();
284 break;
285
286 case 177: // FONT_YSIZE
287 Font_Ysize();
288 break;
289
290 case 195:
291 if( nExtTab >= 0 )
292 rContext.maAttrTable.Apply(rContext, static_cast<SCTAB>(nExtTab));
293 nExtTab++;
294 break;
295 case 197:
296 Row_( nRecLen );
297 break;
298 }
299
300 SAL_WARN_IF( nNextRec < pIn->Tell(), "sc.filter",
301 "*ImportLotus::Read(): Read too much..." );
302 pIn->Seek( nNextRec );
303 aPrgrsBar.Progress();
304 }
305 }
306
307 rContext.maAttrTable.Apply(rContext, static_cast<SCTAB>(nExtTab));
308
309 return eRet;
310}
311
312extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportWKS(SvStream& rStream)
313{
314 ScDLL::Init();
316 ScDocOptions aDocOpt = aDocument.GetDocOptions();
317 aDocOpt.SetLookUpColRowNames(false);
318 aDocument.SetDocOptions(aDocOpt);
319 aDocument.MakeTable(0);
320 aDocument.EnableExecuteLink(false);
321 aDocument.SetInsertingFromOtherDoc(true);
322
323 LotusContext aContext(aDocument, RTL_TEXTENCODING_ASCII_US);
324 ImportLotus aLotusImport(aContext, rStream, RTL_TEXTENCODING_ASCII_US);
325
326 ErrCode eRet = aLotusImport.parse();
327 if (eRet == ErrCode(0xFFFFFFFF))
328 {
329 rStream.Seek(0);
330 eRet = ScImportLotus123old(aContext, rStream, RTL_TEXTENCODING_ASCII_US);
331 }
332
333 return eRet == ERRCODE_NONE;
334}
335
336/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScriptDocument aDocument
void Font_Type()
Definition: lotimpop.cxx:389
sal_Int32 nExtTab
Definition: lotimpop.hxx:37
LotusToSc aConv
Definition: lotimpop.hxx:35
void Formulacell(sal_uInt16 nRecLen)
Definition: lotimpop.cxx:279
void Hiddencolumn(sal_uInt16 nRecLen)
Definition: lotimpop.cxx:130
void NamedSheet()
Definition: lotimpop.cxx:353
void Numbercell()
Definition: lotimpop.cxx:241
void Bof()
Definition: lotimpop.cxx:57
void Labelcell()
Definition: lotimpop.cxx:218
void Smallnumcell()
Definition: lotimpop.cxx:260
void Columnwidth(sal_uInt16 nRecLen)
Definition: lotimpop.cxx:98
void Row_(const sal_uInt16 nRecLen)
Definition: lotimpop.cxx:411
void Userrange()
Definition: lotimpop.cxx:157
void Font_Face()
Definition: lotimpop.cxx:373
sal_uInt16 nTab
Definition: lotimpop.hxx:36
void Font_Ysize()
Definition: lotimpop.cxx:400
ErrCode parse()
Definition: lotread.cxx:32
void Nacell()
Definition: lotimpop.cxx:199
SvStream * pIn
Definition: lotimpop.hxx:34
void Errcell()
Definition: lotimpop.cxx:180
ErrCode Read()
Definition: lotread.cxx:226
void RowPresentation(sal_uInt16 nRecLen)
Definition: lotimpop.cxx:317
bool BofFm3()
Definition: lotimpop.cxx:88
ScDocument & rD
Definition: imp_op.hxx:46
void Apply(LotusContext &rContext, const SCTAB nTabNum)
Definition: lotattr.cxx:243
LotusContext & getContext()
Definition: lotform.hxx:94
static SC_DLLPUBLIC void Init()
DLL-init/exit-code must be linked to the DLL only.
Definition: scdll.cxx:100
void SetLookUpColRowNames(bool bVal)
Definition: docoptio.hxx:52
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:837
SC_DLLPUBLIC void CalcAfterLoad(bool bStartListening=true)
Definition: document.cxx:4029
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:375
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1083
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:2502
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:204
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
A simplified progress bar based on the stream position of an existing stream.
void Progress()
Sets the progress bar to the current stream position.
bool good() const
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
#define ERRCODE_NONE
ErrCode ScImportLotus123old(LotusContext &rContext, SvStream &aStream, rtl_TextEncoding eSrc)
Definition: filter.cxx:185
#define SAL_WARN_IF(condition, area, stream)
SAL_DLLPUBLIC_EXPORT bool TestImportWKS(SvStream &rStream)
Definition: lotread.cxx:312
STATE
#define SCERR_IMPORT_FORMAT
Definition: scerrors.hxx:33
#define SCERR_IMPORT_UNKNOWN_WK
Definition: scerrors.hxx:31
#define SCERR_IMPORT_FILEPASSWD
Definition: scerrors.hxx:40
Lotus123Typ eFirstType
Definition: lotfilter.hxx:52
LotAttrTable maAttrTable
Definition: lotfilter.hxx:57
#define SAL_MAX_UINT32
sal_Int16 SCTAB
Definition: types.hxx:22