comparison minijss/jloadxm.c @ 1188:d18c50f88d44

Clean up the pattern header parsing.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 12:48:58 +0200
parents f195dd7bfa48
children 51eb5788c1fc
comparison
equal deleted inserted replaced
1187:f195dd7bfa48 1188:d18c50f88d44
241 241
242 for (index = 0; index < module->npatterns; index++) 242 for (index = 0; index < module->npatterns; index++)
243 { 243 {
244 // Get the pattern header 244 // Get the pattern header
245 off_t remainder, pos = dmftell(inFile); 245 off_t remainder, pos = dmftell(inFile);
246 246 Uint32 headSize;
247 if (!dmf_read_le32(inFile, &xmP.headSize)) 247
248 // Get the pattern header size
249 if (!dmf_read_le32(inFile, &xmP.headSize) ||
250 !dmf_read_byte(inFile, &xmP.packing))
248 JSSERROR(DMERR_FREAD, DMERR_FREAD, 251 JSSERROR(DMERR_FREAD, DMERR_FREAD,
249 "Could not read pattern header size #%d.\n", 252 "Could not read pattern header size #%d.\n",
250 index); 253 index);
251 254
255 // Different format versions have slightly different headers
252 if (module->intVersion == 0x0102) 256 if (module->intVersion == 0x0102)
253 { 257 {
254 Uint8 tmp; 258 Uint8 tmp;
255 if (xmP.headSize != 4 + 1 + 1 + 2) 259 ret = dmf_read_byte(inFile, &tmp);
256 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
257 "Invalid pattern #%d header size %d, expected %d bytes.\n",
258 index, xmP.headSize, 4 + 1 + 1 + 2);
259
260 if (!dmf_read_byte(inFile, &xmP.packing) ||
261 !dmf_read_byte(inFile, &tmp) ||
262 !dmf_read_le16(inFile, &xmP.size))
263 JSSERROR(DMERR_FREAD, DMERR_FREAD,
264 "Could not read pattern header data #%d.\n",
265 index);
266
267 xmP.nrows = ((Uint16) tmp) + 1; 260 xmP.nrows = ((Uint16) tmp) + 1;
261 headSize = 4 + 1 + 1 + 2;
268 } 262 }
269 else 263 else
270 { 264 {
271 if (xmP.headSize != 4 + 1 + 2 + 2) 265 ret = dmf_read_le16(inFile, &xmP.nrows);
272 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, 266 headSize = 4 + 1 + 2 + 2;
273 "Invalid pattern #%d header size %d, expected %d bytes.\n", 267 }
274 index, xmP.headSize, 4 + 1 + 2 + 2); 268
275 269 if (headSize != xmP.headSize)
276 if (!dmf_read_byte(inFile, &xmP.packing) || 270 {
277 !dmf_read_le16(inFile, &xmP.nrows) || 271 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
278 !dmf_read_le16(inFile, &xmP.size)) 272 "Invalid pattern #%d header size %d, expected %d bytes.\n",
279 JSSERROR(DMERR_FREAD, DMERR_FREAD, 273 index, xmP.headSize, headSize);
280 "Could not read pattern header data #%d.\n", 274 }
281 index); 275
282 } 276 if (!ret || !dmf_read_le16(inFile, &xmP.size))
283 277 {
284 // Check the header 278 JSSERROR(DMERR_FREAD, DMERR_FREAD,
279 "Could not read pattern header data #%d.\n",
280 index);
281 }
282
283 // Check rest of the header data
285 if (xmP.packing != 0) 284 if (xmP.packing != 0)
286 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, 285 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
287 "Pattern #%d packing type unsupported (%d)\n", 286 "Pattern #%d packing type unsupported (%d)\n",
288 index, xmP.packing); 287 index, xmP.packing);
289 288