xref: /aoo4110/main/sc/source/filter/qpro/biff.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include <sal/config.h>
28 #include <stdio.h>
29 #include <sfx2/docfile.hxx>
30 
31 #include "global.hxx"
32 #include "scerrors.hxx"
33 #include "docpool.hxx"
34 #include "patattr.hxx"
35 #include "filter.hxx"
36 #include "document.hxx"
37 #include "cell.hxx"
38 #include "biff.hxx"
39 
ScBiffReader(SfxMedium & rMedium)40 ScBiffReader::ScBiffReader( SfxMedium & rMedium ) :
41 	mnId(0),
42 	mnLength(0),
43 	mnOffset(0)
44 {
45 	mpStream = rMedium.GetInStream();
46 	if( mpStream )
47 	{
48         mpStream->SetBufferSize( 65535 );
49 		mpStream->SetStreamCharSet( RTL_TEXTENCODING_MS_1252 );
50 	}
51 }
52 
~ScBiffReader()53 ScBiffReader::~ScBiffReader()
54 {
55 	if( mpStream )
56 		mpStream->SetBufferSize( 0 );
57 }
58 
nextRecord()59 bool ScBiffReader::nextRecord()
60 {
61 	if( !recordsLeft() )
62 		return false;
63 
64 	if( IsEndOfFile() )
65 		return false;
66 
67 	sal_uInt32 nPos = mpStream->Tell();
68 	if( nPos != mnOffset + mnLength )
69 		mpStream->Seek( mnOffset + mnLength );
70 
71 	mnLength = mnId = 0;
72 	*mpStream >> mnId >> mnLength;
73 
74 	mnOffset = mpStream->Tell();
75 #ifdef DEBUG
76 	fprintf( stderr, "Read record 0x%x length 0x%x at offset 0x%x\n",
77         (unsigned)mnId, (unsigned)mnLength, (unsigned)mnOffset );
78 
79 #if 1  // rather verbose
80 	int len = mnLength;
81 	while (len > 0) {
82 		int i, chunk = len < 16 ? len : 16;
83 		unsigned char data[16];
84 		mpStream->Read( data, chunk );
85 
86 		for (i = 0; i < chunk; i++)
87 			fprintf( stderr, "%.2x ", data[i] );
88 		fprintf( stderr, "| " );
89 		for (i = 0; i < chunk; i++)
90 			fprintf( stderr, "%c", data[i] < 127 && data[i] > 30 ? data[i] : '.' );
91 		fprintf( stderr, "\n" );
92 
93 		len -= chunk;
94 	}
95 	mpStream->Seek( mnOffset );
96 #endif
97 #endif
98 	return true;
99 }
100 
101