Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/RagTimeStruct.cxx
Line
Count
Source
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 (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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
22.2k
{
44
22.2k
  long pos=entry.begin();
45
22.2k
  if (pos<=0 || !input->checkPosition(pos+2))
46
2
    return false;
47
22.2k
  entry.setParsed(true);
48
22.2k
  input->seek(pos, librevenge::RVNG_SEEK_SET);
49
22.2k
  auto dSz=static_cast<int>(input->readULong(2));
50
22.2k
  m_headerPos=pos+2;
51
22.2k
  if (dSz==0)
52
3.94k
    return true;
53
18.3k
  m_endPos=pos+2+dSz;
54
18.3k
  m_headerSize=static_cast<int>(input->readULong(2));
55
18.3k
  m_dataSize=static_cast<int>(input->readULong(2));
56
18.3k
  m_dataNumber=static_cast<int>(input->readULong(2));
57
18.3k
  if (m_headerSize<0x20 || dSz<m_headerSize+long(m_dataNumber+1)*m_dataSize || !input->checkPosition(m_endPos))
58
10.9k
    return false;
59
7.39k
  libmwaw::DebugStream f;
60
7.39k
  int unkn[3];
61
22.1k
  for (auto &u : unkn) u=static_cast<int>(input->readLong(2));
62
7.39k
  bool printUnknown=true;
63
  /* try to use the first value to retrieve the type of the zone */
64
7.39k
  switch (unkn[0]) {
65
1.62k
  case 0:
66
1.62k
    if (m_dataSize==6 && unkn[1]==2 && unkn[2]==4) {
67
952
      m_type=gray;
68
952
      printUnknown=false;
69
952
    }
70
674
    else if (entry.type()=="rsrcgray")
71
25
      m_type=gray;
72
1.62k
    break;
73
609
  case 6:
74
609
    if (m_dataSize==10 && unkn[1]==4 && unkn[2]==0) {
75
607
      m_type=SpTe;
76
607
      printUnknown=false;
77
607
    }
78
2
    else if (entry.type()=="rsrcSpTe")
79
0
      m_type=SpTe;
80
609
    break;
81
636
  case 8:
82
636
    if (m_dataSize==12 && unkn[1]==4 && unkn[2]==0) {
83
564
      m_type=SpVa;
84
564
      printUnknown=false;
85
564
    }
86
72
    else if (entry.type()=="rsrcSpVa")
87
0
      m_type=SpVa;
88
636
    break;
89
621
  case 16:
90
621
    if (m_dataSize==20 && unkn[1]==4 && unkn[2]==0) {
91
604
      m_type=SpBo;
92
604
      printUnknown=false;
93
604
    }
94
17
    else if (entry.type()=="rsrcSpBo")
95
0
      m_type=SpBo;
96
621
    break;
97
42
  case 22:
98
42
    if (m_dataSize==26 && unkn[1]==4 && unkn[2]==0) {
99
0
      m_type=BuGr;
100
0
      printUnknown=false;
101
0
    }
102
42
    else if (entry.type()=="rsrcBuGr")
103
0
      m_type=BuGr;
104
42
    break;
105
2.32k
  case 4:
106
2.32k
    if (m_dataSize==8 && unkn[1]==4 && unkn[2]==0) {
107
496
      m_type=SpCe;
108
496
      printUnknown=false;
109
496
      break;
110
496
    }
111
1.82k
    if (m_dataSize==10 && unkn[1]==4 && unkn[2]==0) { // find also with unkn[1]==0
112
0
      m_type=SpDE;
113
0
      printUnknown=false;
114
0
      break;
115
0
    }
116
    // (m_dataSize==6 && unkn[1]==4 && unkn[2]==2) can be BuSl, colr, res_
117
1.82k
    if (entry.type()=="rsrcSpCe")
118
2
      m_type=SpCe;
119
1.82k
    else if (entry.type()=="rsrcSpDE")
120
0
      m_type=SpDE;
121
1.82k
    else if (entry.type()=="rsrcBuSl")
122
0
      m_type=BuSl;
123
1.82k
    else if (entry.type()=="rsrccolr")
124
794
      m_type=colr;
125
1.03k
    else if (entry.type()=="rsrcres_")
126
792
      m_type=res_;
127
1.82k
    break;
128
1.53k
  default:
129
1.53k
    break;
130
7.39k
  }
131
7.39k
  if (printUnknown) {
132
4.17k
    f << "unkn=[";
133
12.5k
    for (auto u : unkn) f << u << ",";
134
4.17k
    f << "],";
135
4.17k
  }
136
73.9k
  for (int i=0; i<9; ++i) { // g3=3|5|7,g4=-1|-2|9
137
66.5k
    auto val=static_cast<int>(input->readLong(2));
138
66.5k
    if (val) f << "g" << i << "=" << val << ",";
139
66.5k
  }
140
7.39k
  auto subN=static_cast<int>(input->readLong(2));
141
7.39k
  if (m_headerSize!=0x20+subN*6) {
142
1.12k
    MWAW_DEBUG_MSG(("RagTimeStruct::ResourceList::read: the number of sub data seems bad\n"));
143
1.12k
    f << "##subN=" << subN << ",";
144
1.12k
    subN=0;
145
1.12k
  }
146
11.3k
  for (int i=0; i<subN; ++i) {
147
3.98k
    f << "unkn" << i << "=[";
148
    // first always 0, second d|17|21|35|49|67|71|85|a3, last increasing index
149
15.9k
    for (int j=0; j<3; ++j) {
150
11.9k
      auto val=static_cast<int>(input->readLong(2));
151
11.9k
      if (val) f << val << ",";
152
3.98k
      else f << "_,";
153
11.9k
    }
154
3.98k
    f << "],";
155
3.98k
  }
156
7.39k
  m_extra=f.str();
157
7.39k
  m_dataPos=pos+2+m_headerSize;
158
7.39k
  return true;
159
7.39k
}
160
161
std::ostream &operator<<(std::ostream &o, ResourceList const &zone)
162
0
{
163
0
  o << "type=" << ResourceList::getName(zone.m_type) << ",";
164
0
  if (zone.m_headerSize)
165
0
    o << "sz[header]=" << zone.m_headerSize << ",";
166
0
  if (zone.m_dataNumber)
167
0
    o << "N[data]=" << zone.m_dataNumber << ",sz[data]=" << zone.m_dataSize << ",";
168
0
  o << zone.m_extra;
169
0
  return o;
170
0
}
171
172
}
173
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: