Line data Source code
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 <sal/config.h>
21 : #include <stdio.h>
22 : #include <sfx2/docfile.hxx>
23 :
24 : #include "global.hxx"
25 : #include "scerrors.hxx"
26 : #include "docpool.hxx"
27 : #include "patattr.hxx"
28 : #include "filter.hxx"
29 : #include "document.hxx"
30 : #include "formulacell.hxx"
31 : #include "biff.hxx"
32 :
33 6 : ScBiffReader::ScBiffReader(SfxMedium& rMedium)
34 : : mnId(0)
35 : , mnLength(0)
36 : , mnOffset(0)
37 6 : , mbEndOfFile(false)
38 : {
39 6 : mpStream = rMedium.GetInStream();
40 6 : if( mpStream )
41 : {
42 6 : mpStream->SetBufferSize( 65535 );
43 6 : mpStream->SetStreamCharSet( RTL_TEXTENCODING_MS_1252 );
44 : }
45 6 : }
46 :
47 6 : ScBiffReader::~ScBiffReader()
48 : {
49 6 : if( mpStream )
50 6 : mpStream->SetBufferSize( 0 );
51 6 : }
52 :
53 20020 : bool ScBiffReader::nextRecord()
54 : {
55 20020 : if( !recordsLeft() )
56 4 : return false;
57 :
58 20016 : if( IsEndOfFile() )
59 0 : return false;
60 :
61 20016 : sal_uInt32 nPos = mpStream->Tell();
62 20016 : if( nPos != mnOffset + mnLength )
63 4 : mpStream->Seek( mnOffset + mnLength );
64 :
65 20016 : mnLength = mnId = 0;
66 20016 : mpStream->ReadUInt16( mnId ).ReadUInt16( mnLength );
67 :
68 20016 : mnOffset = mpStream->Tell();
69 : #if OSL_DEBUG_LEVEL > 1
70 : fprintf( stderr, "Read record 0x%x length 0x%x at offset 0x%x\n",
71 : (unsigned)mnId, (unsigned)mnLength, (unsigned)mnOffset );
72 :
73 : #if 1 // rather verbose
74 : int len = mnLength;
75 : while (len > 0) {
76 : int i, chunk = len < 16 ? len : 16;
77 : unsigned char data[16];
78 : mpStream->Read( data, chunk );
79 :
80 : for (i = 0; i < chunk; i++)
81 : fprintf( stderr, "%.2x ", data[i] );
82 : fprintf( stderr, "| " );
83 : for (i = 0; i < chunk; i++)
84 : fprintf( stderr, "%c", data[i] < 127 && data[i] > 30 ? data[i] : '.' );
85 : fprintf( stderr, "\n" );
86 :
87 : len -= chunk;
88 : }
89 : mpStream->Seek( mnOffset );
90 : #endif
91 : #endif
92 20016 : return true;
93 48 : }
94 :
95 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|