LibreOffice Module sc (master) 1
filter.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// Discover WKS, WK1 and WK3; s.a op.cpp
21
22#include <map>
23
24#include <filter.hxx>
25#include <document.hxx>
26#include <scerrors.hxx>
27
28#include <optab.h>
29#include <op.h>
30#include <scmem.h>
31#include <decl.h>
32#include <fprogressbar.hxx>
33#include "lotfilter.hxx"
34#include <tools/stream.hxx>
35
36static ErrCode
38 ScfStreamProgressBar& aPrgrsBar)
39{
40 OPCODE_FKT *pOps = nullptr;
41 int nOps = 0;
42
43 ErrCode nErr = ERRCODE_NONE;
44
45 switch (rContext.eTyp)
46 {
47 case eWK_1:
48 case eWK_2:
50 nOps = FKT_LIMIT;
51 break;
52 case eWK123:
54 nOps = FKT_LIMIT123;
55 break;
56 case eWK3:
57 nErr = SCERR_IMPORT_NI;
58 break;
59 case eWK_Error:
61 break;
62 default:
64 break;
65 }
66
67 if (nErr != ERRCODE_NONE)
68 {
69 MemDelete(rContext);
70 return nErr;
71 }
72
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))
77 {
78 sal_uInt16 nOpcode(LOTUS_EOF), nLength(0);
79
80 aStream.ReadUInt16(nOpcode).ReadUInt16(nLength);
81 if (!aStream.good())
82 break;
83
84 aPrgrsBar.Progress();
85 if( nOpcode == LOTUS_EOF )
86 rContext.bEOF = true;
87 else if( nOpcode == LOTUS_FILEPASSWD )
88 {
90 break;
91 }
92 else if( nOpcode < nOps )
93 pOps[ nOpcode ] (rContext, aStream, nLength);
94 else if (rContext.eTyp == eWK123 && nOpcode == LOTUS_PATTERN)
95 {
96 // This is really ugly - needs re-factoring ...
97 aStream.SeekRel(nLength);
98 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
99 if ( nOpcode == 0x29a)
100 {
101 aStream.SeekRel(nLength);
102 aStream.ReadUInt16( nOpcode ).ReadUInt16( nLength );
103 if ( nOpcode == 0x804 )
104 {
105 aStream.SeekRel(nLength);
106 OP_ApplyPatternArea123(rContext, aStream);
107 }
108 else
109 aStream.SeekRel(nLength);
110 }
111 else
112 aStream.SeekRel(nLength);
113 }
114 else
115 aStream.SeekRel( nLength );
116 }
117
118 MemDelete(rContext);
119
120 if (!aStream.good())
121 nErr = SCERR_IMPORT_FORMAT;
122 else if (nErr == ERRCODE_NONE)
123 rContext.rDoc.CalcAfterLoad();
124
125 return nErr;
126}
127
128static WKTYP ScanVersion(SvStream& aStream)
129{
130 // PREC: pWKFile: pointer to open file
131 // POST: return: type of file
132 sal_uInt16 nOpcode(0), nVersNr(0), nRecLen(0);
133
134 // first byte has to be 0 because of BOF!
135 aStream.ReadUInt16( nOpcode );
136 if (nOpcode != LotusContext::nBOF)
137 return eWK_UNKNOWN;
138
139 aStream.ReadUInt16( nRecLen ).ReadUInt16( nVersNr );
140
141 if (!aStream.good())
142 return eWK_Error;
143
144 switch( nVersNr )
145 {
146 case 0x0404:
147 if( nRecLen == 2 )
148 return eWK_1;
149 else
150 return eWK_UNKNOWN;
151
152 case 0x0406:
153 if( nRecLen == 2 )
154 return eWK_2;
155 else
156 return eWK_UNKNOWN;
157
158 case 0x1000:
159 aStream.ReadUInt16( nVersNr );
160 if (!aStream.good())
161 return eWK_Error;
162 if( nVersNr == 0x0004 && nRecLen == 26 )
163 {
164 // 4 bytes of 26 read => skip 22 (read instead of seek to make IsEof() work just in case)
165 char aDummy[22];
166 aStream.ReadBytes(aDummy, 22);
167 return !aStream.good() ? eWK_Error : eWK3;
168 }
169 break;
170 case 0x1003:
171 if( nRecLen == 0x1a )
172 return eWK123;
173 else
174 return eWK_UNKNOWN;
175 case 0x1005:
176 if( nRecLen == 0x1a )
177 return eWK123;
178 else
179 return eWK_UNKNOWN;
180 }
181
182 return eWK_UNKNOWN;
183}
184
185ErrCode ScImportLotus123old(LotusContext& rContext, SvStream& aStream, rtl_TextEncoding eSrc )
186{
187 aStream.Seek( 0 );
188
189 // make document pointer global
190 rContext.bEOF = false;
191 rContext.eCharset = eSrc;
192
193 // allocate memory
194 if( !MemNew(rContext) )
196
197 // initialize page format (only Tab 0!)
198 // initialize page format; meaning: get defaults from SC TODO:
199 //scGetPageFormat( 0, &aPage );
200
201 // start progressbar
202 ScfStreamProgressBar aPrgrsBar( aStream, rContext.rDoc.GetDocumentShell() );
203
204 // detect file type
205 rContext.eTyp = ScanVersion(aStream);
206 rContext.aLotusPatternPool.clear();
207
208 return generate_Opcodes(rContext, aStream, aPrgrsBar);
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void CalcAfterLoad(bool bStartListening=true)
Definition: document.cxx:4090
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1081
A simplified progress bar based on the stream position of an existing stream.
void Progress()
Sets the progress bar to the current stream position.
sal_uInt64 Tell() const
bool good() const
virtual sal_uInt64 TellEnd()
sal_uInt64 Seek(sal_uInt64 nPos)
std::size_t ReadBytes(void *pData, std::size_t nSize)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
WKTYP
Definition: decl.h:23
@ eWK123
Definition: decl.h:23
@ eWK3
Definition: decl.h:23
@ eWK_Error
Definition: decl.h:23
@ eWK_1
Definition: decl.h:23
@ eWK_2
Definition: decl.h:23
@ eWK_UNKNOWN
Definition: decl.h:23
#define ERRCODE_NONE
static WKTYP ScanVersion(SvStream &aStream)
Definition: filter.cxx:128
static ErrCode generate_Opcodes(LotusContext &rContext, SvStream &aStream, ScfStreamProgressBar &aPrgrsBar)
Definition: filter.cxx:37
ErrCode ScImportLotus123old(LotusContext &rContext, SvStream &aStream, rtl_TextEncoding eSrc)
Definition: filter.cxx:185
void OP_ApplyPatternArea123(LotusContext &rContext, SvStream &r)
Definition: op.cxx:611
#define LOTUS_PATTERN
Definition: optab.h:38
#define LOTUS_EOF
Definition: optab.h:34
#define LOTUS_FILEPASSWD
Definition: optab.h:36
#define FKT_LIMIT
Definition: optab.h:30
#define FKT_LIMIT123
Definition: optab.h:32
void(* OPCODE_FKT)(LotusContext &rContext, SvStream &rStream, sal_uInt16 nLength)
Definition: optab.h:28
#define SCERR_IMPORT_OUTOFMEM
Definition: scerrors.hxx:29
#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
#define SCERR_IMPORT_NI
Definition: scerrors.hxx:35
bool MemNew(LotusContext &rContext)
Definition: memory.cxx:30
void MemDelete(LotusContext &rContext)
Definition: memory.cxx:45
#define STREAM_SEEK_TO_BEGIN
static OPCODE_FKT pOpFkt[FKT_LIMIT]
Definition: lotfilter.hxx:38
std::map< sal_uInt16, ScPatternAttr > aLotusPatternPool
Definition: lotfilter.hxx:45
static const sal_uInt16 nBOF
Definition: lotfilter.hxx:37
static OPCODE_FKT pOpFkt123[FKT_LIMIT123]
Definition: lotfilter.hxx:39
ScDocument & rDoc
Definition: lotfilter.hxx:44
rtl_TextEncoding eCharset
Definition: lotfilter.hxx:43
sal_Int32 nLength