Mercurial > hg > dmlib
diff tools/ppl.c @ 2565:d56a0e86067a
Improve error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Feb 2022 11:49:58 +0200 |
parents | aacf3bd1cceb |
children | 9807ae37ad69 |
line wrap: on
line diff
--- a/tools/ppl.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/ppl.c Mon Feb 28 11:49:58 2022 +0200 @@ -550,7 +550,7 @@ { BOOL initSDL = FALSE, audioInit = FALSE; DMResource *file = NULL; - int res = -1; + int res = DMERR_OK; BOOL muteState = FALSE; memset(&eng, 0, sizeof(eng)); @@ -564,20 +564,22 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - exit(1); + goto out; // Open the files if (optFilename == NULL || argc < 2) { argShowHelp(); - return 1; + res = dmError(DMERR_INVALID_ARGS, + "No filename specified.\n"); + goto out; } if ((res = dmf_open_stdio(optFilename, "rb", &file)) != DMERR_OK) { dmErrorMsg("Error opening file '%s': %s\n", optFilename, dmErrorStr(res)); - return 1; + goto out; } // Initialize miniJSS @@ -616,7 +618,7 @@ { dmErrorMsg("Error loading module file: %s\n", dmErrorStr(res)); - goto exit; + goto out; } // Check if we have anything @@ -624,7 +626,7 @@ { res = dmError(DMERR_INIT_FAIL, "Could not load module file.\n"); - goto exit; + goto out; } // Try to convert it @@ -632,7 +634,7 @@ { dmErrorMsg("Could not convert module for playing: %s\n", dmErrorStr(res)); - goto exit; + goto out; } @@ -642,7 +644,7 @@ res = dmError(DMERR_INIT_FAIL, "Could not initialize SDL: %s\n", SDL_GetError()); - goto exit; + goto out; } initSDL = TRUE; @@ -656,7 +658,7 @@ { res = dmError(DMERR_INIT_FAIL, "jvmInit() returned NULL\n"); - goto exit; + goto out; } switch (optOutFormat) @@ -669,7 +671,7 @@ res = dmError(DMERR_NOT_SUPPORTED, "Unsupported audio format %d (could not set matching SDL format)\n", optOutFormat); - goto exit; + goto out; } eng.afmt.freq = optOutFreq; @@ -684,7 +686,7 @@ res = dmError(DMERR_INIT_FAIL, "Couldn't open SDL audio: %s\n", SDL_GetError()); - goto exit; + goto out; } audioInit = TRUE; @@ -693,7 +695,7 @@ { res = dmError(DMERR_INIT_FAIL, "jmpInit() returned NULL\n"); - goto exit; + goto out; } jvmSetCallback(eng.dev, jmpExec, eng.plr); @@ -718,7 +720,7 @@ { dmErrorMsg("Error opening font file '%s': %s\n", engineFontName, dmErrorStr(res)); - goto exit; + goto out; } res = dmLoadBitmapFont(file, &font); dmf_close(file); @@ -726,7 +728,7 @@ { dmErrorMsg("Could not load font data from '%s': %s\n", engineFontName, dmErrorStr(res)); - goto exit; + goto out; } SDL_Color pal[DMFONT_NPALETTE]; @@ -748,7 +750,7 @@ res = dmError(DMERR_INIT_FAIL, "Can't create an SDL window: %s\n", SDL_GetError()); - goto exit; + goto out; } SDL_SetWindowTitle(eng.window, dmProgDesc); @@ -758,13 +760,13 @@ res = dmError(DMERR_INIT_FAIL, "Can't create an SDL renderer: %s\n", SDL_GetError()); - goto exit; + goto out; } if (!dmInitializeVideo()) { res = DMERR_INIT_FAIL; - goto exit; + goto out; } //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); @@ -854,7 +856,7 @@ case SDLK_f: eng.optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP; if (SDL_SetWindowFullscreen(eng.window, eng.optVFlags) != 0) - goto exit; + goto out; needUpdate = TRUE; break; @@ -875,7 +877,7 @@ eng.optScrWidth = eng.event.window.data1; eng.optScrHeight = eng.event.window.data2; if (!dmInitializeVideo()) - goto exit; + goto out; needUpdate = TRUE; break; @@ -970,7 +972,7 @@ SDL_Delay(eng.pauseFlag ? 100 : 30); } -exit: +out: // Cleanup if (optUseGUI) {