# HG changeset patch # User Matti Hamalainen # Date 1646041798 -7200 # Node ID d56a0e86067a9f7a6a6e4415fa1b3b9c7c45a607 # Parent 2cf4e995b50c83359435bf3ec2f60098b4345d3d Improve error handling. diff -r 2cf4e995b50c -r d56a0e86067a tools/64vw.c --- a/tools/64vw.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/64vw.c Mon Feb 28 11:49:58 2022 +0200 @@ -215,7 +215,7 @@ int ret; if ((ret = dmReadDataFile(NULL, filename, &dataBuf, &dataSize)) != DMERR_OK) - goto exit; + goto out; dmGrowBufConstCreateFrom(&tmp, dataBuf, dataSize); @@ -224,7 +224,7 @@ else ret = dmC64DecodeBMP(cimage, &tmp, -1, -1, fmt, forced); -exit: +out: dmFree(dataBuf); return ret; } @@ -275,14 +275,14 @@ DMImage *bimage = NULL; BOOL initSDL = FALSE, exitFlag, needRedraw; size_t currIndex, prevIndex; - int res; + int res = DMERR_OK; // Initialize pre-requisites if ((res = dmLib64GFXInit()) != DMERR_OK) { dmErrorMsg("Could not initialize lib64gfx: %s\n", dmErrorStr(res)); - goto exit; + goto out; } dmSetScaleFactor(2.0); @@ -294,25 +294,27 @@ // Parse arguments, round #1 if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile1, OPTH_BAILOUT)) - exit(1); + goto out; if (noptFilenames1 == 0) { - dmErrorMsg("No input file(s) specified, perhaps you need some --help\n"); - goto exit; + argShowHelp(); + res = dmError(DMERR_INVALID_ARGS, + "No input file(s) specified.\n"); + goto out; } // Allocate space for filename pointers if ((optFilenames = dmCalloc(noptFilenames1, sizeof(char *))) == NULL) { dmErrorMsg("Could not allocate memory for input file list.\n"); - goto exit; + goto out; } // Assign the filename pointers if (!dmArgsProcess(argc, argv, optList, optListN, NULL, argHandleFile2, OPTH_BAILOUT | OPTH_ONLY_OTHER)) - goto exit; + goto out; // Check for forced input format if (optForcedFormat >= 0) @@ -354,19 +356,19 @@ dmC64ImageFree(cimage); } - goto exit; + goto out; } if (optC64PaletteFile != NULL) { if ((res = dmHandleExternalPalette(optC64PaletteFile, &optSpec.pal)) != DMERR_OK) - goto exit; + goto out; if (optSpec.pal->ncolors < D64_NCOLORS) { dmErrorMsg("Palette does not have enough colors (%d < %d)\n", optSpec.pal->ncolors, D64_NCOLORS); - goto exit; + goto out; } } else @@ -384,7 +386,7 @@ { dmErrorMsg("Could not setup palette: %s\n", dmErrorStr(res)); - goto exit; + goto out; } } @@ -407,7 +409,7 @@ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); - goto exit; + goto out; } initSDL = TRUE; @@ -420,13 +422,13 @@ )) == NULL) { dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError()); - goto exit; + goto out; } if ((renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) { dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError()); - goto exit; + goto out; } // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); @@ -492,7 +494,7 @@ case SDLK_f: optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP; if (SDL_SetWindowFullscreen(window, optVFlags) != 0) - goto exit; + goto out; break; default: @@ -519,7 +521,7 @@ break; case SDL_QUIT: - goto exit; + goto out; } if (currIndex != prevIndex) @@ -582,7 +584,7 @@ D64_SCR_WIDTH, D64_SCR_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8)) == NULL) { dmErrorMsg("Could not allocate surface.\n"); - goto exit; + goto out; } if (texture != NULL) @@ -591,7 +593,7 @@ if ((texture = SDL_CreateTextureFromSurface(renderer, surf)) == NULL) { dmErrorMsg("Could not create texture from surface: %s\n", SDL_GetError()); - goto exit; + goto out; } if (title == NULL) @@ -621,7 +623,7 @@ SDL_Delay(50); } -exit: +out: // Cleanup dmFree(optFilenames); dmC64MemBlockFree(&setCharROM); @@ -645,5 +647,5 @@ dmPaletteFree(optSpec.pal); dmLib64GFXClose(); - return 0; + return res; } diff -r 2cf4e995b50c -r d56a0e86067a tools/data2inc.c --- a/tools/data2inc.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/data2inc.c Mon Feb 28 11:49:58 2022 +0200 @@ -481,7 +481,7 @@ void *ctx = NULL; size_t dataSize; off_t totalSize; - int res; + int res = DMERR_OK; // Initialize dmInitProg("data2inc", "Data to include file converter", "0.7", NULL, NULL); @@ -490,22 +490,24 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - exit(1); + goto out; // Determine output type, if not specified if (setFormat == NULL) { if (optOutFilename == NULL) { - dmErrorMsg("Output format not specified and no output filename given (try --help)\n"); - goto exit; + argShowHelp(); + res = dmError(DMERR_INVALID_ARGS, + "Output format not specified and no output filename given.\n"); + goto out; } if ((setFormat = dmGuessFormatFromName(optOutFilename)) == NULL) { dmErrorMsg("Could not guess output format from filename '%s'.\n", optOutFilename); - goto exit; + goto out; } dmMsg(0, "Guessed output format: %s (%s)\n", @@ -525,7 +527,7 @@ res = dmGetErrno(); dmErrorMsg("Error opening input file '%s'. (%s)\n", optInFilename, dmErrorStr(res)); - goto exit; + goto out; } if (optOutFilename == NULL) @@ -536,7 +538,7 @@ res = dmGetErrno(); dmErrorMsg("Error creating output file '%s'. (%s)\n", optOutFilename, dmErrorStr(res)); - goto exit; + goto out; } // Allocate linebuffer @@ -545,7 +547,7 @@ { dmErrorMsg("Could not allocate %" DM_PRIu_SIZE_T " byte buffer.\n", dataSize); - goto exit; + goto out; } // Get sourcefile size @@ -558,7 +560,7 @@ dmErrorMsg("Error initializing format %s (%s) context: %s\n", setFormat->name, setFormat->desc, dmErrorStr(res)); - goto exit; + goto out; } // Output header @@ -567,7 +569,7 @@ { dmErrorMsg("Error writing output header: %s\n", dmErrorStr(res)); - goto exit; + goto out; } if (optAddLine) @@ -579,7 +581,7 @@ { dmErrorMsg("Error writing output declaration: %s\n", dmErrorStr(res)); - goto exit; + goto out; } // Output data @@ -591,7 +593,7 @@ { dmErrorMsg("Error writing output data: %s\n", dmErrorStr(res)); - goto exit; + goto out; } } @@ -601,10 +603,10 @@ { dmErrorMsg("Error writing output footer: %s\n", dmErrorStr(res)); - goto exit; + goto out; } -exit: +out: // Cleanup if (inFile != NULL) fclose(inFile); @@ -623,5 +625,5 @@ dmErrorStr(res)); } - return 0; + return res; } diff -r 2cf4e995b50c -r d56a0e86067a tools/dumpmod.c --- a/tools/dumpmod.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/dumpmod.c Mon Feb 28 11:49:58 2022 +0200 @@ -434,10 +434,7 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - { - res = 1; - goto exit; - } + goto out; // Initialize miniJSS jssInit(); @@ -454,7 +451,7 @@ res = dmError(DMERR_FOPEN, "Error opening input file '%s': %s\n", optFilename, dmErrorStr(res)); - goto exit; + goto out; } // Read module file @@ -497,7 +494,7 @@ { res = dmError(DMERR_INIT_FAIL, "Could not load module file.\n"); - goto exit; + goto out; } // Print out information @@ -542,7 +539,7 @@ } } -exit: +out: // Free module data jssFreeModule(mod); jssClose(); diff -r 2cf4e995b50c -r d56a0e86067a tools/fontconv.c --- a/tools/fontconv.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/fontconv.c Mon Feb 28 11:49:58 2022 +0200 @@ -284,7 +284,7 @@ DMResource *inFile = NULL, *outFile = NULL; DMBitmapFont *font = NULL; SDL_Surface *fontbmap = NULL; - int res; + int res = DMERR_OK; #ifdef DM_GFX_TTF_TEXT BOOL initTTF = FALSE; TTF_Font *ttf = NULL; @@ -295,20 +295,22 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - exit(1); + goto out; // Check arguments if (optInFilename == NULL || optOutFilename == NULL) { - dmErrorMsg("Input or output file not specified!\n"); - return 1; + argShowHelp(); + res = dmError(DMERR_INVALID_ARGS, + "No input or output file specified!\n"); + goto out; } #ifdef DM_GFX_TTF_TEXT if (TTF_Init() < 0) { dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); - goto exit; + goto out; } initTTF = TRUE; #endif @@ -316,9 +318,9 @@ // Open the source file if ((res = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) { - dmErrorMsg("Error opening input file '%s', %d: %s\n", - optInFilename, res, dmErrorStr(res)); - goto exit; + dmErrorMsg("Error opening input file '%s': %s\n", + optInFilename, dmErrorStr(res)); + goto out; } @@ -332,7 +334,7 @@ { dmErrorMsg("Input is a TSFONT/DMFONT font file, but there is an error: %s\n", dmErrorStr(res)); - goto exit; + goto out; } #ifdef DM_GFX_TTF_TEXT else @@ -353,7 +355,7 @@ optSplitWidth - 6, optSplitHeight + 2, optBPP)) == NULL) { dmErrorMsg("Could not allocate bitmap font!\n"); - goto exit; + goto out; } // Render glyphs from the normal ASCII range only @@ -380,7 +382,7 @@ { dmErrorMsg("Could not get TTF glyph metrics for character '%c' (%d).\n", nglyph, nglyph); - goto exit; + goto out; } dst.x = 0; @@ -407,7 +409,7 @@ if ((fontbmap = dmLoadImage(inFile)) == NULL) { dmErrorMsg("Could not load image file '%s'.\n", optInFilename); - goto exit; + goto out; } dmMsg(1, "Input is a bitmap image (%d x %d, %d bpp), splitting to %d x %d.\n", @@ -418,14 +420,14 @@ { dmErrorMsg("Could not create a font from image, %d: %s\n", res, dmErrorStr(res)); - goto exit; + goto out; } } if (font == NULL) { dmErrorMsg("No font loaded.\n"); - goto exit; + goto out; } // Count number of actually existing glyphs despite that we should have @@ -449,7 +451,7 @@ n, glyph->width, glyph->height, font->width, font->height); - goto exit; + goto out; } } } @@ -463,7 +465,7 @@ { dmErrorMsg("Error creating file '%s', %d: %s\n", optInFilename, res, dmErrorStr(res)); - goto exit; + goto out; } res = dmSaveBitmapFont(outFile, font); @@ -473,9 +475,10 @@ { dmErrorMsg("Error saving font, %d: %s\n", res, dmErrorStr(res)); + goto out; } -exit: +out: // Cleanup #ifdef DM_GFX_TTF_TEXT if (initTTF) @@ -487,5 +490,5 @@ if (fontbmap != NULL) SDL_FreeSurface(fontbmap); - return 0; + return res; } diff -r 2cf4e995b50c -r d56a0e86067a tools/gfxconv.c --- a/tools/gfxconv.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/gfxconv.c Mon Feb 28 11:49:58 2022 +0200 @@ -2574,7 +2574,7 @@ DMImage *inImage = NULL, *outImage = NULL; Uint8 *dataBuf = NULL, *dataBufOrig = NULL; size_t dataSize, dataSizeOrig, dataRealOffs; - int i, n, res; + int i, n, res = DMERR_OK; // Default color mapping for (i = 0; i < D64_NCOLORS; i++) @@ -2588,7 +2588,7 @@ { dmErrorMsg("Could not initialize lib64gfx: %s\n", dmErrorStr(res)); - goto exit; + goto out; } nconvFormatList = ndmImageFormatList + ndmPaletteFormatList + nbaseFormatList; @@ -2625,14 +2625,13 @@ if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - exit(1); + goto out; switch (optShowHelp) { case 1: argShowHelp(); - exit(0); - break; + goto out; case 2: argShowHelp(); @@ -2646,14 +2645,12 @@ if (str != NULL) fprintf(stdout, "\n%s\n", str); } - exit(0); - break; + goto out; case 3: argShowFormats(); argShowC64Formats(stdout, TRUE, dmVerbosity > 0); - exit(0); - break; + goto out; } // Determine input format, if not specified @@ -2677,7 +2674,7 @@ { dmErrorMsg("Standard input cannot be used without specifying input format.\n"); dmErrorMsg("Perhaps you should try --help or --longhelp\n"); - goto exit; + goto out; } inFile = stdin; optInFilename = "stdin"; @@ -2688,7 +2685,7 @@ res = dmGetErrno(); dmErrorMsg("Error opening input file '%s': %s\n", optInFilename, dmErrorStr(res)); - goto exit; + goto out; } // Determine output format, if not specified @@ -2715,7 +2712,7 @@ if ((res = dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig)) != DMERR_OK) { dmErrorMsg("Could not read input: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } fclose(inFile); @@ -2725,7 +2722,7 @@ { dmErrorMsg("Input skip value %d (0x%x) is larger than input size %" DM_PRIu_SIZE_T ".\n", optInSkip, optInSkip, dataSizeOrig); - goto exit; + goto out; } if (optInSkipNeg) @@ -2787,7 +2784,7 @@ if (res != DMERR_OK && (forced != NULL || optInType == FFMT_BITMAP)) { dmErrorMsg("Could not decode input image: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } } @@ -2822,7 +2819,7 @@ if (optInType == FFMT_AUTO) { dmErrorMsg("No input format specified, and could not be determined automatically.\n"); - goto exit; + goto out; } if (dmGetConvFormat(optInType, optInFormat, &inFormat) && @@ -2864,7 +2861,7 @@ // Handle palette stuff that is generic for different operation modes if (optPaletteFile != NULL && (res = dmHandleExternalPalette(optPaletteFile, &optPaletteData)) != DMERR_OK) - goto exit; + goto out; switch (optInType) { @@ -2884,7 +2881,7 @@ { dmErrorMsg("Could not set up palette: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } } @@ -2892,7 +2889,7 @@ { dmErrorMsg("Palette does not have enough colors (%d < %d)\n", optPaletteData->ncolors, D64_NCOLORS); - goto exit; + goto out; } if (optPaletteData->ncolors > D64_NCOLORS) @@ -2914,7 +2911,7 @@ { dmErrorMsg("Could not set up palette: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } } } @@ -2934,14 +2931,14 @@ if (optOutFilename == NULL) { dmErrorMsg("Output filename not set, required for palette formats.\n"); - goto exit; + goto out; } // Read palette file if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) { dmErrorMsg("Could not create MemIO handle for input.\n"); - goto exit; + goto out; } // Read input @@ -2955,12 +2952,12 @@ if (res != DMERR_OK) { dmErrorMsg("Palette could not be read.\n"); - goto exit; + goto out; } } if (optPaletteData == NULL) - goto exit; + goto out; switch (optOutType) { @@ -2975,14 +2972,14 @@ { res = dmError(DMERR_MALLOC, "Could not allocate memory for image.\n"); - goto exit; + goto out; } if ((res = dmPaletteCopy(&inImage->pal, optPaletteData)) != DMERR_OK) { dmErrorMsg("Could not allocate image palette: %s\n", dmErrorStr(res)); - goto exit; + goto out; } res = dmWriteImage(optOutFilename, inImage, &optSpec, @@ -2999,7 +2996,7 @@ if (optOutFilename == NULL) { dmErrorMsg("Output filename not set, required for bitmap formats.\n"); - goto exit; + goto out; } switch (optOutType) @@ -3025,7 +3022,7 @@ { dmErrorMsg("Could not read character ROM from '%s'.\n", optCharROMFilename); - goto exit; + goto out; } } @@ -3036,7 +3033,7 @@ { dmErrorMsg("Error in bitmap to image conversion: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } switch (optOutType) @@ -3067,7 +3064,7 @@ &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) { dmErrorMsg("Error in bitmap format conversion.\n"); - goto exit; + goto out; } if (dmVerbosity >= 2) { @@ -3091,13 +3088,13 @@ if (optOutFilename == NULL) { dmErrorMsg("Output filename not set, required for image formats.\n"); - goto exit; + goto out; } if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) { dmErrorMsg("Could not create MemIO handle for input.\n"); - goto exit; + goto out; } // Read input @@ -3109,7 +3106,7 @@ dmf_close(fp); if (res != DMERR_OK || inImage == NULL) - goto exit; + goto out; switch (optOutType) { @@ -3122,7 +3119,7 @@ if (inImage->pal == NULL || inImage->pixfmt != DM_PIXFMT_PALETTE) { dmErrorMsg("Source image is not a paletted format or has no palette.\n"); - goto exit; + goto out; } res = dmWritePalette(optOutFilename, inImage->pal, &dmPaletteFormatList[optOutFormat]); break; @@ -3144,7 +3141,7 @@ dmC64ImageFree(tmpC64Image); dmErrorMsg("Error in image to bitmap conversion: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } if ((res = dmConvertC64Bitmap(&outC64Image, tmpC64Image, @@ -3153,7 +3150,7 @@ dmC64ImageFree(tmpC64Image); dmErrorMsg("Error in bitmap format conversion: %s.\n", dmErrorStr(res)); - goto exit; + goto out; } res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); @@ -3175,7 +3172,7 @@ dmErrorStr(res)); } -exit: +out: // Cleanup dmFree(convFormatList); dmFree(dataBufOrig); @@ -3186,5 +3183,5 @@ dmImageFree(outImage); dmLib64GFXClose(); - return 0; + return res; } diff -r 2cf4e995b50c -r d56a0e86067a tools/mod2wav.c --- a/tools/mod2wav.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/mod2wav.c Mon Feb 28 11:49:58 2022 +0200 @@ -230,7 +230,7 @@ JSSPlayer *plr = NULL; size_t bufLen = 1024*4, dataTotal, dataWritten, sampSize; Uint8 *dataBuf = NULL; - int res; + int res = DMERR_OK; dmInitProg("mod2wav", "XM/JSSMOD to WAV renderer", "0.2", NULL, NULL); dmVerbosity = 1; @@ -238,18 +238,14 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - { - res = 1; - goto exit; - } - + goto out; // Check arguments if (optInFilename == NULL || optOutFilename == NULL) { res = dmError(DMERR_INVALID_ARGS, - "Input or output file not specified. Try --help.\n"); - goto exit; + "Input or output file not specified.\n"); + goto out; } // Initialize miniJSS @@ -260,7 +256,7 @@ { dmErrorMsg("Error opening input file '%s': %s\n", optInFilename, dmErrorStr(res)); - goto exit; + goto out; } // Read module file @@ -296,7 +292,7 @@ { dmErrorMsg("Error loading module file: %s\n", dmErrorStr(res)); - goto exit; + goto out; } // Check if we have anything @@ -304,7 +300,7 @@ { res = dmError(DMERR_INIT_FAIL, "Could not load module file.\n"); - goto exit; + goto out; } // Try to convert it @@ -312,7 +308,7 @@ { dmErrorMsg("Could not convert module for playing: %s\n", dmErrorStr(res)); - goto exit; + goto out; } // Open mixer @@ -321,7 +317,7 @@ { res = dmError(DMERR_INIT_FAIL, "jvmInit() returned NULL\n"); - goto exit; + goto out; } sampSize = jvmGetSampleSize(dev); @@ -329,7 +325,7 @@ { res = dmError(DMERR_MALLOC, "Could not allocate mixing buffer.\n"); - goto exit; + goto out; } dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%" DM_PRIu_SIZE_T " / sample]\n", @@ -340,7 +336,7 @@ if ((plr = jmpInit(dev)) == NULL) { dmErrorMsg("jmpInit() returned NULL.\n"); - goto exit; + goto out; } // Set callback @@ -375,7 +371,7 @@ res = dmGetErrno(); dmErrorMsg("Error opening output file '%s': %s.\n", optInFilename, dmErrorStr(res)); - goto exit; + goto out; } // Write initial header @@ -407,7 +403,7 @@ { res = dmError(DMERR_FWRITE, "Error writing audio data!\n"); - goto exit; + goto out; } dataTotal += dataWritten; } @@ -421,7 +417,7 @@ { res = dmError(DMERR_FSEEK, "Error rewinding to header position!\n"); - goto exit; + goto out; } dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal); @@ -429,7 +425,7 @@ // Done! dmMsg(1, "OK.\n"); -exit: +out: if (outFile != NULL) fclose(outFile); diff -r 2cf4e995b50c -r d56a0e86067a tools/objlink.c --- a/tools/objlink.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/objlink.c Mon Feb 28 11:49:58 2022 +0200 @@ -576,8 +576,8 @@ if ((fh = fopen(filename, "rb")) == NULL) { res = dmGetErrno(); - dmErrorMsg("Error opening input file '%s' #%d: %s.\n", - filename, res, dmErrorStr(res)); + dmErrorMsg("Error opening input file '%s': %s.\n", + filename, dmErrorStr(res)); goto out; } @@ -585,8 +585,8 @@ if ((dataSize = dmGetFileSize(fh) - 2) < 0) { res = dmGetErrno(); - dmErrorMsg("Error getting file size for '%s' #%d: %s.\n", - filename, res, dmErrorStr(res)); + dmErrorMsg("Error getting file size for '%s': %s.\n", + filename, dmErrorStr(res)); goto out; } @@ -594,8 +594,8 @@ if (!dm_fread_le16(fh, &tmpAddr)) { res = dmGetErrno(); - dmErrorMsg("Error reading input file '%s' #%d: %s.\n", - filename, res, dmErrorStr(res)); + dmErrorMsg("Error reading input file '%s': %s.\n", + filename, dmErrorStr(res)); goto out; } @@ -617,8 +617,8 @@ if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) { res = dmGetErrno(); - dmPrint(1, " .. Error #%d: %s.\n", - res, dmErrorStr(res)); + dmPrint(1, " .. Error: %s.\n", + dmErrorStr(res)); goto out; } @@ -645,8 +645,8 @@ if ((fh = fopen(filename, "rb")) == NULL) { res = dmGetErrno(); - dmErrorMsg("Error opening input file '%s' #%d: %s.\n", - filename, res, dmErrorStr(res)); + dmErrorMsg("Error opening input file '%s': %s.\n", + filename, dmErrorStr(res)); goto out; } @@ -674,8 +674,8 @@ if (fread(&memory[destAddr], dataSize, 1, fh) < 1) { res = dmGetErrno(); - dmPrint(1, " .. Error reading data #%d: %s.\n", - res, dmErrorStr(res)); + dmPrint(1, " .. Error reading data: %s.\n", + dmErrorStr(res)); goto out; } @@ -855,7 +855,9 @@ if (nsrcFiles < 1) { - dmErrorMsg("Nothing to do. (try --help)\n"); + argShowHelp(); + res = dmError(DMERR_INVALID_ARGS, + "No input file(s) specified.\n"); goto out; } diff -r 2cf4e995b50c -r d56a0e86067a tools/ppl.c --- 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) { diff -r 2cf4e995b50c -r d56a0e86067a tools/xm2jss.c --- a/tools/xm2jss.c Mon Feb 28 10:18:38 2022 +0200 +++ b/tools/xm2jss.c Mon Feb 28 11:49:58 2022 +0200 @@ -1307,13 +1307,14 @@ // Parse arguments if (!dmArgsProcess(argc, argv, optList, optListN, argHandleOpt, argHandleFile, OPTH_BAILOUT)) - exit(1); + goto out; // Check arguments if (optInFilename == NULL || optOutFilename == NULL) { + argShowHelp(); res = dmError(DMERR_INVALID_ARGS, - "Input or output file not specified. Try --help.\n"); + "Input or output file not specified.\n"); goto out; }