| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <iomanip> |
| 35 |
#include <iostream> |
| 36 |
|
| 37 |
#include "RagTimeStruct.hxx" |
| 38 |
|
| 39 |
namespace RagTimeStruct |
| 40 |
{ |
| 41 |
|
| 42 |
bool ResourceList::read(MWAWInputStreamPtr input, MWAWEntry &entry) |
| 43 |
{ |
| 44 |
long pos=entry.begin(); |
| 45 |
if (pos<=0 || !input->checkPosition(pos+2)) |
| 46 |
return false; |
| 47 |
entry.setParsed(true); |
| 48 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 49 |
auto dSz=static_cast<int>(input->readULong(2)); |
| 50 |
m_headerPos=pos+2; |
| 51 |
if (dSz==0) |
| 52 |
return true; |
| 53 |
m_endPos=pos+2+dSz; |
| 54 |
m_headerSize=static_cast<int>(input->readULong(2)); |
| 55 |
m_dataSize=static_cast<int>(input->readULong(2)); |
| 56 |
m_dataNumber=static_cast<int>(input->readULong(2)); |
| 57 |
if (m_headerSize<0x20 || dSz<m_headerSize+long(m_dataNumber+1)*m_dataSize || !input->checkPosition(m_endPos)) |
| 58 |
return false; |
| 59 |
libmwaw::DebugStream f; |
| 60 |
int unkn[3]; |
| 61 |
for (auto &u : unkn) u=static_cast<int>(input->readLong(2)); |
| 62 |
bool printUnknown=true; |
| 63 |
/* try to use the first value to retrieve the type of the zone */ |
| 64 |
switch (unkn[0]) { |
| 65 |
case 0: |
| 66 |
if (m_dataSize==6 && unkn[1]==2 && unkn[2]==4) { |
| 67 |
m_type=gray; |
| 68 |
printUnknown=false; |
| 69 |
} |
| 70 |
else if (entry.type()=="rsrcgray") |
| 71 |
m_type=gray; |
| 72 |
break; |
| 73 |
case 6: |
| 74 |
if (m_dataSize==10 && unkn[1]==4 && unkn[2]==0) { |
| 75 |
m_type=SpTe; |
| 76 |
printUnknown=false; |
| 77 |
} |
| 78 |
else if (entry.type()=="rsrcSpTe") |
| 79 |
m_type=SpTe; |
| 80 |
break; |
| 81 |
case 8: |
| 82 |
if (m_dataSize==12 && unkn[1]==4 && unkn[2]==0) { |
| 83 |
m_type=SpVa; |
| 84 |
printUnknown=false; |
| 85 |
} |
| 86 |
else if (entry.type()=="rsrcSpVa") |
| 87 |
m_type=SpVa; |
| 88 |
break; |
| 89 |
case 16: |
| 90 |
if (m_dataSize==20 && unkn[1]==4 && unkn[2]==0) { |
| 91 |
m_type=SpBo; |
| 92 |
printUnknown=false; |
| 93 |
} |
| 94 |
else if (entry.type()=="rsrcSpBo") |
| 95 |
m_type=SpBo; |
| 96 |
break; |
| 97 |
case 22: |
| 98 |
if (m_dataSize==26 && unkn[1]==4 && unkn[2]==0) { |
| 99 |
m_type=BuGr; |
| 100 |
printUnknown=false; |
| 101 |
} |
| 102 |
else if (entry.type()=="rsrcBuGr") |
| 103 |
m_type=BuGr; |
| 104 |
break; |
| 105 |
case 4: |
| 106 |
if (m_dataSize==8 && unkn[1]==4 && unkn[2]==0) { |
| 107 |
m_type=SpCe; |
| 108 |
printUnknown=false; |
| 109 |
break; |
| 110 |
} |
| 111 |
if (m_dataSize==10 && unkn[1]==4 && unkn[2]==0) { // find also with unkn[1]==0 |
| 112 |
m_type=SpDE; |
| 113 |
printUnknown=false; |
| 114 |
break; |
| 115 |
} |
| 116 |
// (m_dataSize==6 && unkn[1]==4 && unkn[2]==2) can be BuSl, colr, res_ |
| 117 |
if (entry.type()=="rsrcSpCe") |
| 118 |
m_type=SpCe; |
| 119 |
else if (entry.type()=="rsrcSpDE") |
| 120 |
m_type=SpDE; |
| 121 |
else if (entry.type()=="rsrcBuSl") |
| 122 |
m_type=BuSl; |
| 123 |
else if (entry.type()=="rsrccolr") |
| 124 |
m_type=colr; |
| 125 |
else if (entry.type()=="rsrcres_") |
| 126 |
m_type=res_; |
| 127 |
break; |
| 128 |
default: |
| 129 |
break; |
| 130 |
} |
| 131 |
if (printUnknown) { |
| 132 |
f << "unkn=["; |
| 133 |
for (auto u : unkn) f << u << ","; |
| 134 |
f << "],"; |
| 135 |
} |
| 136 |
for (int i=0; i<9; ++i) { // g3=3|5|7,g4=-1|-2|9 |
| 137 |
auto val=static_cast<int>(input->readLong(2)); |
| 138 |
if (val) f << "g" << i << "=" << val << ","; |
| 139 |
} |
| 140 |
auto subN=static_cast<int>(input->readLong(2)); |
| 141 |
if (m_headerSize!=0x20+subN*6) { |
| 142 |
MWAW_DEBUG_MSG(("RagTimeStruct::ResourceList::read: the number of sub data seems bad\n")); |
| 143 |
f << "##subN=" << subN << ","; |
| 144 |
subN=0; |
| 145 |
} |
| 146 |
for (int i=0; i<subN; ++i) { |
| 147 |
f << "unkn" << i << "=["; |
| 148 |
// first always 0, second d|17|21|35|49|67|71|85|a3, last increasing index |
| 149 |
for (int j=0; j<3; ++j) { |
| 150 |
auto val=static_cast<int>(input->readLong(2)); |
| 151 |
if (val) f << val << ","; |
| 152 |
else f << "_,"; |
| 153 |
} |
| 154 |
f << "],"; |
| 155 |
} |
| 156 |
m_extra=f.str(); |
| 157 |
m_dataPos=pos+2+m_headerSize; |
| 158 |
return true; |
| 159 |
} |
| 160 |
|
| 161 |
std::ostream &operator<<(std::ostream &o, ResourceList const &zone) |
| 162 |
{ |
| 163 |
o << "type=" << ResourceList::getName(zone.m_type) << ","; |
| 164 |
if (zone.m_headerSize) |
| 165 |
o << "sz[header]=" << zone.m_headerSize << ","; |
| 166 |
if (zone.m_dataNumber) |
| 167 |
o << "N[data]=" << zone.m_dataNumber << ",sz[data]=" << zone.m_dataSize << ","; |
| 168 |
o << zone.m_extra; |
| 169 |
return o; |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |