Mercurial > hg > dmlib
diff tools/64vw.c @ 2565:d56a0e86067a
Improve error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Feb 2022 11:49:58 +0200 |
parents | c6ee41fd98dd |
children | bb44c48cffac |
line wrap: on
line diff
--- 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; }