comparison tools/ppl.c @ 958:985225a93aeb

Add error code parameter to dmError() and dmErrorVA().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 03:58:25 +0200
parents daebbf28953d
children 96e0798f602b
comparison
equal deleted inserted replaced
957:b66653c9acb3 958:985225a93aeb
103 int w, h; 103 int w, h;
104 if (sscanf(optArg, "%dx%d", &w, &h) == 2) 104 if (sscanf(optArg, "%dx%d", &w, &h) == 2)
105 { 105 {
106 if (w < 320 || h < 200 || w > 3200 || h > 3200) 106 if (w < 320 || h < 200 || w > 3200 || h > 3200)
107 { 107 {
108 dmError("Invalid width or height: %d x %d\n", w, h); 108 dmErrorMsg("Invalid width or height: %d x %d\n", w, h);
109 return FALSE; 109 return FALSE;
110 } 110 }
111 engine.optScrWidth = w; 111 engine.optScrWidth = w;
112 engine.optScrHeight = h; 112 engine.optScrHeight = h;
113 } 113 }
114 else 114 else
115 { 115 {
116 dmError("Invalid size argument '%s'.\n", optArg); 116 dmErrorMsg("Invalid size argument '%s'.\n", optArg);
117 return FALSE; 117 return FALSE;
118 } 118 }
119 } 119 }
120 break; 120 break;
121 121
151 optPlayTime = atoi(optArg); 151 optPlayTime = atoi(optArg);
152 optUsePlayTime = TRUE; 152 optUsePlayTime = TRUE;
153 break; 153 break;
154 154
155 default: 155 default:
156 dmError("Unknown option '%s'.\n", currArg); 156 dmErrorMsg("Unknown option '%s'.\n", currArg);
157 return FALSE; 157 return FALSE;
158 } 158 }
159 159
160 return TRUE; 160 return TRUE;
161 } 161 }
165 { 165 {
166 if (!optFilename) 166 if (!optFilename)
167 optFilename = currArg; 167 optFilename = currArg;
168 else 168 else
169 { 169 {
170 dmError("Too many filename arguments '%s'\n", currArg); 170 dmErrorMsg("Too many filename arguments '%s'\n", currArg);
171 return FALSE; 171 return FALSE;
172 } 172 }
173 173
174 return TRUE; 174 return TRUE;
175 } 175 }
237 engine.optScrWidth, engine.optScrHeight, engine.optScrDepth, 237 engine.optScrWidth, engine.optScrHeight, engine.optScrDepth,
238 engine.optVFlags | SDL_RESIZABLE | SDL_SWSURFACE | SDL_HWPALETTE); 238 engine.optVFlags | SDL_RESIZABLE | SDL_SWSURFACE | SDL_HWPALETTE);
239 239
240 if (engine.screen == NULL) 240 if (engine.screen == NULL)
241 { 241 {
242 dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); 242 dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
243 return FALSE; 243 return FALSE;
244 } 244 }
245 245
246 col.inboxBg = dmCol(0.6, 0.5, 0.2); 246 col.inboxBg = dmCol(0.6, 0.5, 0.2);
247 col.boxBg = dmCol(0.7, 0.6, 0.3); 247 col.boxBg = dmCol(0.7, 0.6, 0.3);
575 exit(1); 575 exit(1);
576 576
577 // Open the files 577 // Open the files
578 if (optFilename == NULL) 578 if (optFilename == NULL)
579 { 579 {
580 dmError("No filename specified.\n"); 580 dmErrorMsg("No filename specified.\n");
581 return 1; 581 return 1;
582 } 582 }
583 583
584 if ((result = dmf_create_stdio(optFilename, "rb", &file)) != DMERR_OK) 584 if ((result = dmf_create_stdio(optFilename, "rb", &file)) != DMERR_OK)
585 { 585 {
586 dmError("Error opening file '%s', %d: (%s)\n", 586 dmErrorMsg("Error opening file '%s', %d: (%s)\n",
587 optFilename, result, dmErrorStr(result)); 587 optFilename, result, dmErrorStr(result));
588 return 1; 588 return 1;
589 } 589 }
590 590
591 // Initialize miniJSS 591 // Initialize miniJSS
607 #endif 607 #endif
608 dmf_close(file); 608 dmf_close(file);
609 609
610 if (result != DMERR_OK) 610 if (result != DMERR_OK)
611 { 611 {
612 dmError("Error loading module file, %d: %s\n", 612 dmErrorMsg("Error loading module file, %d: %s\n",
613 result, dmErrorStr(result)); 613 result, dmErrorStr(result));
614 goto error_exit; 614 goto error_exit;
615 } 615 }
616 616
617 // Try to convert it 617 // Try to convert it
618 if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK) 618 if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK)
619 { 619 {
620 dmError("Could not convert module for playing, %d: %s\n", 620 dmErrorMsg("Could not convert module for playing, %d: %s\n",
621 result, dmErrorStr(result)); 621 result, dmErrorStr(result));
622 goto error_exit; 622 goto error_exit;
623 } 623 }
624 624
625 // Get font 625 // Get font
626 result = dmf_create_memio(NULL, "pplfont.fnt", engineSetupFont, sizeof(engineSetupFont), &file); 626 result = dmf_create_memio(NULL, "pplfont.fnt", engineSetupFont, sizeof(engineSetupFont), &file);
627 if (result != DMERR_OK) 627 if (result != DMERR_OK)
628 { 628 {
629 dmError("Error opening font file 'pplfont.fnt', #%d: %s\n", 629 dmErrorMsg("Error opening font file 'pplfont.fnt', #%d: %s\n",
630 result, dmErrorStr(result)); 630 result, dmErrorStr(result));
631 goto error_exit; 631 goto error_exit;
632 } 632 }
633 result = dmLoadBitmapFont(file, &font); 633 result = dmLoadBitmapFont(file, &font);
634 dmf_close(file); 634 dmf_close(file);
635 if (result != DMERR_OK) 635 if (result != DMERR_OK)
636 { 636 {
637 dmError("Could not load font from file, %d: %s\n", 637 dmErrorMsg("Could not load font from file, %d: %s\n",
638 result, dmErrorStr(result)); 638 result, dmErrorStr(result));
639 goto error_exit; 639 goto error_exit;
640 } 640 }
641 641
642 // Initialize SDL components 642 // Initialize SDL components
643 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) 643 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
644 { 644 {
645 dmError("Could not initialize SDL: %s\n", SDL_GetError()); 645 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
646 goto error_exit; 646 goto error_exit;
647 } 647 }
648 initSDL = TRUE; 648 initSDL = TRUE;
649 649
650 650
653 optOutFormat, optOutChannels, optOutFreq); 653 optOutFormat, optOutChannels, optOutFreq);
654 654
655 engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); 655 engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
656 if (engine.dev == NULL) 656 if (engine.dev == NULL)
657 { 657 {
658 dmError("jvmInit() returned NULL\n"); 658 dmErrorMsg("jvmInit() returned NULL\n");
659 goto error_exit; 659 goto error_exit;
660 } 660 }
661 661
662 switch (optOutFormat) 662 switch (optOutFormat)
663 { 663 {
664 case JSS_AUDIO_S16: engine.afmt.format = AUDIO_S16SYS; break; 664 case JSS_AUDIO_S16: engine.afmt.format = AUDIO_S16SYS; break;
665 case JSS_AUDIO_U16: engine.afmt.format = AUDIO_U16SYS; break; 665 case JSS_AUDIO_U16: engine.afmt.format = AUDIO_U16SYS; break;
666 case JSS_AUDIO_S8: engine.afmt.format = AUDIO_S8; break; 666 case JSS_AUDIO_S8: engine.afmt.format = AUDIO_S8; break;
667 case JSS_AUDIO_U8: engine.afmt.format = AUDIO_U8; break; 667 case JSS_AUDIO_U8: engine.afmt.format = AUDIO_U8; break;
668 default: 668 default:
669 dmError("Unsupported audio format %d (could not set matching SDL format)\n", 669 dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n",
670 optOutFormat); 670 optOutFormat);
671 goto error_exit; 671 goto error_exit;
672 } 672 }
673 673
674 engine.afmt.freq = optOutFreq; 674 engine.afmt.freq = optOutFreq;
678 engine.afmt.userdata = (void *) engine.dev; 678 engine.afmt.userdata = (void *) engine.dev;
679 679
680 // Open the audio device 680 // Open the audio device
681 if (SDL_OpenAudio(&engine.afmt, NULL) < 0) 681 if (SDL_OpenAudio(&engine.afmt, NULL) < 0)
682 { 682 {
683 dmError("Couldn't open SDL audio: %s\n", 683 dmErrorMsg("Couldn't open SDL audio: %s\n",
684 SDL_GetError()); 684 SDL_GetError());
685 goto error_exit; 685 goto error_exit;
686 } 686 }
687 audioInit = TRUE; 687 audioInit = TRUE;
688 688
689 // Initialize player 689 // Initialize player
690 if ((engine.plr = jmpInit(engine.dev)) == NULL) 690 if ((engine.plr = jmpInit(engine.dev)) == NULL)
691 { 691 {
692 dmError("jmpInit() returned NULL\n"); 692 dmErrorMsg("jmpInit() returned NULL\n");
693 goto error_exit; 693 goto error_exit;
694 } 694 }
695 695
696 jvmSetCallback(engine.dev, jmpExec, engine.plr); 696 jvmSetCallback(engine.dev, jmpExec, engine.plr);
697 jmpSetModule(engine.plr, engine.mod); 697 jmpSetModule(engine.plr, engine.mod);
839 } 839 }
840 840
841 // Draw frame 841 // Draw frame
842 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) 842 if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0)
843 { 843 {
844 dmError("Can't lock surface.\n"); 844 dmErrorMsg("Can't lock surface.\n");
845 goto error_exit; 845 goto error_exit;
846 } 846 }
847 847
848 if (force) 848 if (force)
849 { 849 {