comparison sidinfo.c @ 3:dbe35d78e621

Cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 25 Sep 2014 01:46:22 +0300
parents ffb795582a91
children 2892e994243c
comparison
equal deleted inserted replaced
2:ffb795582a91 3:dbe35d78e621
95 th_print_banner(stdout, th_prog_name, "[options] <sid filename>"); 95 th_print_banner(stdout, th_prog_name, "[options] <sid filename>");
96 th_args_help(stdout, optList, optListN); 96 th_args_help(stdout, optList, optListN);
97 printf( 97 printf(
98 "\n" 98 "\n"
99 "Available fields:\n"); 99 "Available fields:\n");
100 100
101 for (index = n = 0; index < noptPSFlags; index++) 101 for (index = n = 0; index < noptPSFlags; index++)
102 { 102 {
103 const PSFOption *opt = &optPSFlags[index]; 103 const PSFOption *opt = &optPSFlags[index];
104 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n"); 104 printf("%s%s", opt->name, (index < noptPSFlags - 1) ? ", " : "\n\n");
105 if (++n > 5) 105 if (++n > 5)
150 return FALSE; 150 return FALSE;
151 151
152 case -2: 152 case -2:
153 THERR("Flag '%s' is ambiguous.\n", opt); 153 THERR("Flag '%s' is ambiguous.\n", opt);
154 return FALSE; 154 return FALSE;
155 155
156 default: 156 default:
157 *fields |= optPSFlags[found].flag; 157 *fields |= optPSFlags[found].flag;
158 return TRUE; 158 return TRUE;
159 } 159 }
160 } 160 }
192 if (!end) 192 if (!end)
193 break; 193 break;
194 194
195 start = end + 1; 195 start = end + 1;
196 } 196 }
197 197
198 //fprintf(stderr, "%08x\n", optFields); 198 //fprintf(stderr, "%08x\n", optFields);
199 } 199 }
200 break; 200 break;
201 201
202 case 4: 202 case 4:
277 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL) 277 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL)
278 { 278 {
279 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE); 279 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE);
280 goto error; 280 goto error;
281 } 281 }
282 282
283 // Read PSID header in 283 // Read PSID header in
284 if (!th_fread_str(inFile, (uint8_t *) psid->magic, PSID_MAGIC_LEN) || 284 if (!th_fread_str(inFile, (uint8_t *) psid->magic, PSID_MAGIC_LEN) ||
285 !th_fread_be16(inFile, &psid->version) || 285 !th_fread_be16(inFile, &psid->version) ||
286 !th_fread_be16(inFile, &psid->dataOffset) || 286 !th_fread_be16(inFile, &psid->dataOffset) ||
287 !th_fread_be16(inFile, &psid->loadAddress) || 287 !th_fread_be16(inFile, &psid->loadAddress) ||
429 vfprintf(outFile, fmt, ap); 429 vfprintf(outFile, fmt, ap);
430 else 430 else
431 vfprintf(outFile, fmt, ap); 431 vfprintf(outFile, fmt, ap);
432 432
433 va_end(ap); 433 va_end(ap);
434 434
435 fprintf(outFile, "\n"); 435 fprintf(outFile, "\n");
436 } 436 }
437 } 437 }
438 438
439 #define PR(xindex, xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, parsable, hex, flags, xindex, xfmt, xaltfmt, __VA_ARGS__ ) 439 #define PR(xindex, xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, parsable, hex, flags, xindex, xfmt, xaltfmt, __VA_ARGS__ )
451 PR( 7, "%d", "$%04x", psid->nSongs); 451 PR( 7, "%d", "$%04x", psid->nSongs);
452 PR( 8, "%d", "$%04x", psid->startSong); 452 PR( 8, "%d", "$%04x", psid->startSong);
453 453
454 PR( 9, "%s", NULL, psid->sidName); 454 PR( 9, "%s", NULL, psid->sidName);
455 PR(10, "%s", NULL, psid->sidAuthor); 455 PR(10, "%s", NULL, psid->sidAuthor);
456 PR(11, "%s", NULL, psid->sidCopyright); 456 PR(11, "%s", NULL, psid->sidCopyright);
457 457
458 if (flags & PSF_HASH) 458 if (flags & PSF_HASH)
459 { 459 {
460 siPrintLinePrefix(outFile, parsable, "Hash"); 460 siPrintLinePrefix(outFile, parsable, "Hash");
461 th_md5_print(outFile, psid->hash); 461 th_md5_print(outFile, psid->hash);