comparison tools/dumpmod.c @ 2530:aacf3bd1cceb

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 16 May 2020 06:38:52 +0300
parents bc05bcfc4598
children d56a0e86067a
comparison
equal deleted inserted replaced
2529:fddee4b6a427 2530:aacf3bd1cceb
422 422
423 423
424 424
425 int main(int argc, char *argv[]) 425 int main(int argc, char *argv[])
426 { 426 {
427 int result = -1, i;
428 DMResource *file = NULL; 427 DMResource *file = NULL;
429 JSSModule *mod = NULL; 428 JSSModule *mod = NULL;
429 int res = 0;
430 430
431 dmInitProg("dumpmod", "miniJSS Module Viewer", "0.4", NULL, NULL); 431 dmInitProg("dumpmod", "miniJSS Module Viewer", "0.4", NULL, NULL);
432 dmVerbosity = 0; 432 dmVerbosity = 0;
433 433
434 // Parse arguments 434 // Parse arguments
435 if (!dmArgsProcess(argc, argv, optList, optListN, 435 if (!dmArgsProcess(argc, argv, optList, optListN,
436 argHandleOpt, argHandleFile, OPTH_BAILOUT)) 436 argHandleOpt, argHandleFile, OPTH_BAILOUT))
437 exit(1); 437 {
438 res = 1;
439 goto exit;
440 }
438 441
439 // Initialize miniJSS 442 // Initialize miniJSS
440 jssInit(); 443 jssInit();
441 444
442 // Open the file 445 // Open the file
443 dmMsg(1, "Reading module file '%s'\n", optFilename); 446 dmMsg(1, "Reading module file '%s'\n", optFilename);
444 if (optFilename == NULL) 447 if (optFilename == NULL)
445 result = dmf_open_stdio_stream(stdin, &file); 448 res = dmf_open_stdio_stream(stdin, &file);
446 else 449 else
447 result = dmf_open_stdio(optFilename, "rb", &file); 450 res = dmf_open_stdio(optFilename, "rb", &file);
448 451
449 if (result != DMERR_OK) 452 if (res != DMERR_OK)
450 { 453 {
451 dmErrorMsg("Error opening input file '%s', #%d: %s\n", 454 res = dmError(DMERR_FOPEN,
452 optFilename, result, dmErrorStr(result)); 455 "Error opening input file '%s': %s\n",
453 return 1; 456 optFilename, dmErrorStr(res));
457 goto exit;
454 } 458 }
455 459
456 // Read module file 460 // Read module file
457 dmMsg(1, "Reading file: %s\n", optFilename); 461 dmMsg(1, "Reading file: %s\n", optFilename);
458 #ifdef JSS_SUP_XM 462 #ifdef JSS_SUP_XM
459 result = jssLoadXM(file, &mod, TRUE); 463 if (mod == NULL)
464 {
465 dmMsg(2, "* Trying XM...\n");
466 dmfreset(file);
467 if ((res = jssLoadXM(file, &mod, TRUE)) == DMERR_OK)
468 {
469 dmfreset(file);
470 res = jssLoadXM(file, &mod, FALSE);
471 }
472 }
460 #endif 473 #endif
461 #ifdef JSS_SUP_JSSMOD 474 #ifdef JSS_SUP_JSSMOD
462 dmfreset(file); 475 if (mod == NULL)
463 if (result != DMERR_OK)
464 { 476 {
465 dmMsg(1, "* Trying JSSMOD ...\n"); 477 dmMsg(1, "* Trying JSSMOD ...\n");
466 result = jssLoadJSSMOD(file, &mod, TRUE);
467 dmfreset(file); 478 dmfreset(file);
468 if (result == DMERR_OK) 479 if ((res = jssLoadJSSMOD(file, &mod, TRUE)) == DMERR_OK)
469 result = jssLoadJSSMOD(file, &mod, FALSE); 480 {
470 } 481 dmfreset(file);
471 else 482 res = jssLoadJSSMOD(file, &mod, FALSE);
472 { 483 }
473 dmMsg(2, "* Trying XM...\n");
474 result = jssLoadXM(file, &mod, FALSE);
475 } 484 }
476 #endif 485 #endif
477 dmf_close(file); 486 dmf_close(file);
478 487
479 // Check for errors, we still might have some data tho 488 // Check for errors, we still might have some data tho
480 if (result != DMERR_OK) 489 if (res != DMERR_OK)
481 { 490 {
482 dmErrorMsg("Error loading module file, %d: %s\n", 491 dmErrorMsg("Error loading module file: %s\n",
483 result, dmErrorStr(result)); 492 dmErrorStr(res));
484 } 493 }
485 494
486 // Check if we have anything 495 // Check if we have anything
487 if (mod == NULL) 496 if (mod == NULL)
488 return 3; 497 {
498 res = dmError(DMERR_INIT_FAIL,
499 "Could not load module file.\n");
500 goto exit;
501 }
489 502
490 // Print out information 503 // Print out information
491 if (optViewGeneralInfo) 504 if (optViewGeneralInfo)
492 printGeneralInfo(stdout, mod); 505 printGeneralInfo(stdout, mod);
493 506
494 if (optViewPatterns) 507 if (optViewPatterns)
495 { 508 {
496 for (i = 0; i < mod->npatterns; i++) 509 for (int i = 0; i < mod->npatterns; i++)
497 if (mod->patterns[i] != NULL) 510 if (mod->patterns[i] != NULL)
498 { 511 {
499 printf("\nPattern #%02x:\n", i); 512 printf("\nPattern #%02x:\n", i);
500 printPattern(stdout, mod->patterns[i]); 513 printPattern(stdout, mod->patterns[i]);
501 } 514 }
505 { 518 {
506 printf("\n" 519 printf("\n"
507 "ExtInstruments:\n" 520 "ExtInstruments:\n"
508 "---------------\n" 521 "---------------\n"
509 ); 522 );
510 for (i = 0; i < mod->nextInstruments; i++) 523 for (int i = 0; i < mod->nextInstruments; i++)
511 if (mod->extInstruments[i] != NULL) 524 if (mod->extInstruments[i] != NULL)
512 { 525 {
513 printf("#%02x: ", i + 1); 526 printf("#%02x: ", i + 1);
514 printExtInstrument(stdout, mod->extInstruments[i]); 527 printExtInstrument(stdout, mod->extInstruments[i]);
515 } 528 }
519 { 532 {
520 printf("\n" 533 printf("\n"
521 "Instruments:\n" 534 "Instruments:\n"
522 "------------\n" 535 "------------\n"
523 ); 536 );
524 for (i = 0; i < mod->ninstruments; i++) 537 for (int i = 0; i < mod->ninstruments; i++)
525 if (mod->instruments[i] != NULL) 538 if (mod->instruments[i] != NULL)
526 { 539 {
527 printf("#%02x: ", i + 1); 540 printf("#%02x: ", i + 1);
528 printInstrument(stdout, mod->instruments[i]); 541 printInstrument(stdout, mod->instruments[i]);
529 } 542 }
530 } 543 }
531 544
545 exit:
532 // Free module data 546 // Free module data
533 jssFreeModule(mod); 547 jssFreeModule(mod);
534 jssClose(); 548 jssClose();
535 549
536 return 0; 550 return res;
537 } 551 }