2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "PdbReader.h"
23 #include "../../bookmodel/BookModel.h"
24 #include "../../bookmodel/BookReader.h"
26 void PdbUtil::readUnsignedShort(ZLInputStream
&stream
, unsigned short &N
) {
27 unsigned char data
[2];
28 stream
.read((char*)data
, 2);
29 N
= (((unsigned short)data
[0]) << 8) + data
[1];
31 stream.read((char*)&N + 1, 1);
32 stream.read((char*)&N, 1);
36 void PdbUtil::readUnsignedLong(ZLInputStream
&stream
, unsigned long &N
) {
37 unsigned char data
[4];
38 stream
.read((char*)data
, 4);
39 N
= (((unsigned long)data
[0]) << 24) +
40 (((unsigned long)data
[1]) << 16) +
41 (((unsigned long)data
[2]) << 8) +
42 (unsigned long)data
[3];
44 stream.read((char*)&N + 3, 1);
45 stream.read((char*)&N + 2, 1);
46 stream.read((char*)&N + 1, 1);
47 stream.read((char*)&N, 1);
51 bool PdbHeader::read(shared_ptr
<ZLInputStream
> stream
) {
52 size_t startOffset
= stream
->offset();
55 DocName
.append(32, '\0');
56 stream
->read((char*)DocName
.data(), 32);
58 PdbUtil::readUnsignedShort(*stream
, Flags
);
60 stream
->seek(26, false);
64 stream
->read((char*)Id
.data(), 8);
66 stream
->seek(8, false);
69 unsigned short numRecords
;
70 PdbUtil::readUnsignedShort(*stream
, numRecords
);
71 Offsets
.reserve(numRecords
);
73 for (int i
= 0; i
< numRecords
; ++i
) {
74 unsigned long recordOffset
;
75 PdbUtil::readUnsignedLong(*stream
, recordOffset
);
76 Offsets
.push_back(recordOffset
);
77 stream
->seek(4, false);
80 return stream
->offset() == startOffset
+ 78 + 8 * numRecords
;