# HG changeset patch # User Matti Hamalainen # Date 1425002305 -7200 # Node ID 985225a93aeb043c3b2dd93c0a646ab7edc127aa # Parent b66653c9acb3bb35a7268c272a2b37c3e1579d7d Add error code parameter to dmError() and dmErrorVA(). diff -r b66653c9acb3 -r 985225a93aeb src/dmargs.c --- a/src/dmargs.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmargs.c Fri Feb 27 03:58:25 2015 +0200 @@ -4,7 +4,7 @@ #define th_args_process dmArgsProcess #define th_args_help dmArgsPrintHelp -#define THERR dmError +#define THERR dmErrorMsg #define th_calloc dmCalloc #define th_malloc dmMalloc #define th_free dmFree diff -r b66653c9acb3 -r 985225a93aeb src/dmengine.c --- a/src/dmengine.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmengine.c Fri Feb 27 03:58:25 2015 +0200 @@ -32,8 +32,8 @@ engineEffects = dmRealloc(engineEffects, sizeof(DMEffect) * nengineEffectsAlloc); if (engineEffects == NULL) { - dmError("Could not expand effects structure.\n"); - return DMERR_INIT_FAIL; + return dmError(DMERR_INIT_FAIL, + "Could not expand effects structure.\n"); } } @@ -53,8 +53,8 @@ engine->effectData = dmCalloc(nengineEffectsAlloc, sizeof(void *)); if (engine->effectData == NULL) { - dmError("Could not expand effects data structure.\n"); - return DMERR_INIT_FAIL; + return dmError(DMERR_INIT_FAIL, + "Could not expand effects data structure.\n"); } for (i = 0; i < nengineEffects; i++) @@ -335,7 +335,9 @@ return res->resData; else { - dmError("Could not find resource '%s'.\n", name); + dmError(DMERR_INTERNAL, + "Could not find resource '%s'.\n", + name); return NULL; } } @@ -522,7 +524,9 @@ if (SDL_OpenAudio(&engine->optAfmt, NULL) < 0) { // We'll let this pass, as we want to support no-sound. - dmError("Couldn't open SDL audio, falling back to no sound: %s\n", SDL_GetError()); + dmMsg(0, + "Couldn't open SDL audio, falling back to no sound: %s\n", + SDL_GetError()); // Set up simulated audio thread engine->audioSimDelay = 1000 / 45; diff -r b66653c9acb3 -r 985225a93aeb src/dmfile.c --- a/src/dmfile.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmfile.c Fri Feb 27 03:58:25 2015 +0200 @@ -76,22 +76,22 @@ { if ((f = fopen(filename, "rb")) == NULL) { - dmError("Could not open '%s' for reading.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "Could not open '%s' for reading.\n", filename); } } else { - dmError("NULL filename and stream pointers.\n"); - return DMERR_NULLPTR; + return dmError(DMERR_NULLPTR, + "NULL filename and stream pointers.\n"); } // Allocate initial data buffer readSize = dataSize = BUF_SIZE_INITIAL; if ((dataBuf = dmMalloc(dataSize)) == NULL) { - dmError("Error allocating memory for data, %d bytes.\n", dataSize); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "Error allocating memory for data, %d bytes.\n", dataSize); goto error; } @@ -110,8 +110,9 @@ dataSize += BUF_SIZE_GROW; if ((dataBuf = dmRealloc(dataBuf, dataSize)) == NULL) { - dmError("Error reallocating memory for data, %d bytes.\n", dataSize); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "Error reallocating memory for data, %d bytes.\n", + dataSize); goto error; } } diff -r b66653c9acb3 -r 985225a93aeb src/dmimage.c --- a/src/dmimage.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmimage.c Fri Feb 27 03:58:25 2015 +0200 @@ -121,7 +121,8 @@ if (data == NULL) { - dmError("Error decoding image resource %p '%s' [%d, %d, %d]: %s\n", + dmError(DMERR_DATA_ERROR, + "Error decoding image resource %p '%s' [%d, %d, %d]: %s\n", file, file->filename, width, height, comp, stbi_failure_reason()); return NULL; } @@ -170,7 +171,8 @@ if (result == NULL) { - dmError("Format conversion failed for image resource %p '%s' [%d, %d, %d].\n", + dmError(DMERR_DATA_ERROR, + "Format conversion failed for image resource %p '%s' [%d, %d, %d].\n", file, file->filename, width, height, comp); } diff -r b66653c9acb3 -r 985225a93aeb src/dmlib.c --- a/src/dmlib.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmlib.c Fri Feb 27 03:58:25 2015 +0200 @@ -51,23 +51,6 @@ } -void dmErrorVA(const char *fmt, va_list ap) -{ - fprintf(stderr, "%s: ", dmProgName); - vfprintf(stderr, fmt, ap); -} - - -void dmError(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - dmErrorVA(fmt, ap); - va_end(ap); -} - - void dmMsg(int level, const char *fmt, ...) { va_list ap; @@ -194,6 +177,41 @@ } +int dmErrorVA(const int error, const char *fmt, va_list ap) +{ + if (dmProgName != NULL) + fprintf(stderr, "%s: ", dmProgName); + + vfprintf(stderr, fmt, ap); + return error; +} + + +int dmError(const int error, const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = dmErrorVA(error, fmt, ap); + va_end(ap); + return ret; +} + + +void dmErrorMsg(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + dmErrorVA(DMERR_INTERNAL, fmt, ap); + va_end(ap); +} + + +/* + * Mutex debugging + */ #ifdef DM_MUTEX_DEBUG static DMMutexLock * dmGetMutexThreadIDLock(DMMutex *mutex) diff -r b66653c9acb3 -r 985225a93aeb src/dmlib.h --- a/src/dmlib.h Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmlib.h Fri Feb 27 03:58:25 2015 +0200 @@ -375,9 +375,10 @@ void dmMsg(int level, const char *fmt, ...); void dmPrintVA(int level, const char *fmt, va_list ap); void dmPrint(int level, const char *fmt, ...); -void dmErrorVA(const char *fmt, va_list); -void dmError(const char *fmt, ...); +int dmErrorVA(const int error, const char *fmt, va_list); +int dmError(const int error, const char *fmt, ...); +void dmErrorMsg(const char *fmt, ...); int dmGetErrno(); const char *dmErrorStr(const int error); diff -r b66653c9acb3 -r 985225a93aeb src/dmres.c --- a/src/dmres.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmres.c Fri Feb 27 03:58:25 2015 +0200 @@ -340,16 +340,17 @@ // Search PACK nodelist for file if ((node = dmPackFind(handle->lib->packFile->entries, handle->filename)) == NULL) { - dmError("Entry '%s' not found in PACK file.\n", handle->filename); - res = DMERR_NOT_FOUND; + res = dmError(DMERR_NOT_FOUND, + "Entry '%s' not found in PACK file.\n", + handle->filename); goto error; } // Seek to entry if (fseek(handle->lib->packFile->file, node->offset, SEEK_SET) == -1) { - dmError("Could not seek node position in PACK file.\n"); - res = DMERR_FSEEK; + res = dmError(DMERR_FSEEK, + "Could not seek node position in PACK file.\n"); goto error; } @@ -381,8 +382,8 @@ cres = inflateInit(&(cstream)); if (cres != Z_OK) { - dmError("Could not initialize zlib stream inflation.\n"); - res = DMERR_INIT_FAIL; + res = dmError(DMERR_INIT_FAIL, + "Could not initialize zlib stream inflation.\n"); goto error; } @@ -904,8 +905,8 @@ char *fname = dm_strdup_printf("%s/%s", path, dh->d_name); if (stat(fname, &sbuf) == -1) { - res = dmGetErrno(); - dmError("Could not stat() %s, #%d: %s\n", + res = dmError(dmGetErrno(), + "Could not stat() %s, #%d: %s\n", fname, res, dmErrorStr(res)); dmFree(fname); goto out; @@ -966,14 +967,17 @@ { if ((flags & DRF_USE_STDIO) == 0) { - dmError("Error opening PACK file '%s', #%d: %s\n", - lib->packFilename, ret, dmErrorStr(ret)); - - return DMERR_INIT_FAIL; + return dmError(DMERR_INIT_FAIL, + "Error opening PACK file '%s', #%d: %s\n", + lib->packFilename, ret, dmErrorStr(ret)); } else - dmError("Failed to open PACK, falling back to STDIO, '%s' %d: %s\n", - lib->packFilename, ret, dmErrorStr(ret)); + { + // Non-fatal + dmError(DMERR_INIT_FAIL, + "Failed to open PACK, falling back to STDIO, '%s' %d: %s\n", + lib->packFilename, ret, dmErrorStr(ret)); + } } else { @@ -983,9 +987,9 @@ DMResource *res = dmResourceNew(lib, node->filename, node->size); if (res == NULL) { - dmError("Could not allocate memory for resource node '%s' [0x%08x], %d.\n", + return dmError(DMERR_INIT_FAIL, + "Could not allocate memory for resource node '%s' [0x%08x], %d.\n", node->filename, node->flags, node->size); - return DMERR_INIT_FAIL; } res->fops = &dfPackFileOps; @@ -1044,7 +1048,7 @@ int res = dmPackClose(lib->packFile); if (res != DMERR_OK) { - dmError("Error closing PACK, #%i: %s\n", + dmError(res, "Error closing PACK, #%i: %s\n", res, dmErrorStr(res)); } @@ -1097,7 +1101,7 @@ // Attempt to preload the resource if ((ret = dmResourcePreload(lib->preload)) != DMERR_OK) { - dmError("Error preloading '%s', %d: %s\n", + dmError(ret, "Error preloading '%s', %d: %s\n", lib->preload->filename, ret, dmErrorStr(ret)); goto error; } diff -r b66653c9acb3 -r 985225a93aeb src/dmsimple.c --- a/src/dmsimple.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmsimple.c Fri Feb 27 03:58:25 2015 +0200 @@ -53,7 +53,8 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmError(DMERR_INTERNAL, + "Unknown option '%s'.\n", currArg); return FALSE; } @@ -124,7 +125,8 @@ engine.screen = SDL_SetVideoMode(width, height, depth, flags); if (engine.screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmError(DMERR_INIT_FAIL, + "Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } @@ -257,8 +259,8 @@ sscanf(str, "textEnterToStart %s", engine.setupTextEnterToStart) != 1 ) { - dmError("Syntax error in configuration:\n%s\n", buf); - res = DMERR_INVALID_DATA; + res = dmError(DMERR_INVALID_DATA, + "Syntax error in configuration:\n%s\n", buf); goto out; } } @@ -296,7 +298,8 @@ SDL_Rect **modes = SDL_ListModes(engine.screen->format, engine.screen->flags | SDL_FULLSCREEN); if (modes == (SDL_Rect**) 0) { - dmError("No compatible video resolutions/depths available at all. Bailing out.\n"); + dmError(DMERR_INIT_FAIL, + "No compatible video resolutions/depths available at all. Bailing out.\n"); goto out; } @@ -310,7 +313,8 @@ if (nengineModeList == 0) { - dmError("Umm, no modes found.\n"); + dmError(DMERR_INIT_FAIL, + "Umm, no modes found.\n"); goto out; } @@ -363,7 +367,8 @@ if (menuBgImage == NULL || menuBarImage == NULL) { - dmError("Could not instantiate setup screen images, %d: %s\n", + dmError(result, + "Could not instantiate setup screen images, %d: %s\n", result, dmErrorStr(result)); goto out; } @@ -371,7 +376,8 @@ if (menuBgImage->w != DM_VSETUP_WIDTH || menuBgImage->h != DM_VSETUP_HEIGHT) { - dmError("Setup screen background image does not match " + dmError(DMERR_INIT_FAIL, + "Setup screen background image does not match " "required dimensions (%dx%d vs %dx%d)\n", menuBgImage->w, menuBgImage->h, DM_VSETUP_WIDTH, DM_VSETUP_HEIGHT); @@ -388,7 +394,8 @@ } if (result != DMERR_OK) { - dmError("Could not instantiate setup screen font, %d: %s\n", + dmError(result, + "Could not instantiate setup screen font, %d: %s\n", result, dmErrorStr(result)); goto out; } @@ -398,7 +405,8 @@ engine.screen->w, engine.screen->h); if (tmp == NULL) { - dmError("Could not convert setup screen background image.\n"); + dmError(DMERR_MALLOC, + "Could not convert setup screen background image.\n"); goto out; } @@ -478,7 +486,7 @@ engine.frameTime = SDL_GetTicks(); if (SDL_MUSTLOCK(engine.screen) && SDL_LockSurface(engine.screen) != 0) { - dmError("Can't lock surface.\n"); + dmError(DMERR_INTERNAL, "Can't lock surface.\n"); goto out; } @@ -610,7 +618,9 @@ if ((err = dmResourcesInit(&engine.resources, engine.optPackFilename, engine.optDataPath, engine.optResFlags, engineClassifier)) != DMERR_OK) { - dmError("Could not initialize resource manager, #%d: %s.\n", err, dmErrorStr(err)); + dmError(err, + "Could not initialize resource manager, #%d: %s.\n", + err, dmErrorStr(err)); goto error_exit; } @@ -618,7 +628,9 @@ dmPrint(1, "Initializing libSDL.\n"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmError(DMERR_INIT_FAIL, + "Could not initialize SDL: %s\n", + SDL_GetError()); goto error_exit; } initSDL = TRUE; @@ -667,23 +679,25 @@ if ((engine.jssDev = jvmInit(engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq, JMIX_AUTO)) == NULL) { - dmError("jvmInit() returned NULL, voi perkele.\n"); + dmError(DMERR_INIT_FAIL, + "jvmInit() returned NULL, voi perkele.\n"); goto error_exit; } if ((engine.jssPlr = jmpInit(engine.jssDev)) == NULL) { - dmError("jmpInit() returned NULL\n"); + dmError(DMERR_INIT_FAIL, + "jmpInit() returned NULL\n"); goto error_exit; } #else - dmError("miniJSS support not included.\n"); + dmError(DMERR_INTERNAL, "miniJSS support not included.\n"); #endif break; case DM_ASETUP_TREMOR: #ifndef DM_USE_TREMOR - dmError("Tremor support not included.\n"); + dmError(DMERR_INTERNAL, "Tremor support not included.\n"); #endif break; } @@ -695,7 +709,9 @@ if ((err = engineInitAudioParts(&engine)) != DMERR_OK) { - dmError("engineInitAudioParts() failed: #%d: %s\n", err, dmErrorStr(err)); + dmError(err, + "engineInitAudioParts() failed: #%d: %s\n", + err, dmErrorStr(err)); goto error_exit; } @@ -703,7 +719,9 @@ if (engine.demoInitPreVideo != NULL && (err = engine.demoInitPreVideo(&engine)) != DMERR_OK) { - dmError("demoInitPreVideo() failed, #%d: %s\n", err, dmErrorStr(err)); + dmError(err, + "demoInitPreVideo() failed, #%d: %s\n", + err, dmErrorStr(err)); goto error_exit; } @@ -713,7 +731,9 @@ if (engine.demoInitPostVideo != NULL && (err = engine.demoInitPostVideo(&engine)) != DMERR_OK) { - dmError("demoInitPostVideo() failed, #%d: %s\n", err, dmErrorStr(err)); + dmError(err, + "demoInitPostVideo() failed, #%d: %s\n", + err, dmErrorStr(err)); goto error_exit; } @@ -740,7 +760,8 @@ // Initialize effects if ((err = engineInitializeEffects(&engine)) != DMERR_OK) { - dmError("Effects initialization failed, #%d: %s\n", + dmError(err, + "Effects initialization failed, #%d: %s\n", err, dmErrorStr(err)); goto error_exit; } @@ -751,14 +772,16 @@ { if ((err = dmLoadTimeline(engine.timeline, &engine.tl)) != DMERR_OK) { - dmError("Error loading timeline, #%d: %s\n", err, - dmErrorStr(err)); + dmError(err, + "Error loading timeline, #%d: %s\n", + err, dmErrorStr(err)); goto error_exit; } if ((err = dmPrepareTimeline(engine.tl, engine.ptl)) != DMERR_OK) { - dmError("Error creating prepared timeline, #%d: %s\n", + dmError(err, + "Error creating prepared timeline, #%d: %s\n", err, dmErrorStr(err)); goto error_exit; } @@ -833,7 +856,7 @@ if (SDL_MUSTLOCK(engine.screen) && SDL_LockSurface(engine.screen) != 0) { - dmError("Can't lock surface.\n"); + dmError(DMERR_INTERNAL, "Can't lock surface.\n"); goto error_exit; } diff -r b66653c9acb3 -r 985225a93aeb src/dmtimeline.c --- a/src/dmtimeline.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmtimeline.c Fri Feb 27 03:58:25 2015 +0200 @@ -149,9 +149,9 @@ if (hdr.nparams > DT_MAX_EFFECT_PARAMS) { - dmError("Invalid number of parameters, %d > %d ('%s' @ %d:%d)\n", + return dmError(DMERR_INVALID_DATA, + "Invalid number of parameters, %d > %d ('%s' @ %d:%d)\n", hdr.nparams, DT_MAX_EFFECT_PARAMS, hdr.effectName, hdr.start, hdr.duration); - return DMERR_INVALID_DATA; } event->start = hdr.start; @@ -160,15 +160,16 @@ event->effect = engineFindEffect(hdr.effectName, hdr.nparams); if (event->effect == NULL) { - dmError("No matching registered effect found for '%s'.\n", hdr.effectName); - return DMERR_INVALID_DATA; + return dmError(DMERR_INVALID_DATA, + "No matching registered effect found for '%s'.\n", + hdr.effectName); } event->params = dmCalloc(event->nparams, sizeof(DMTimelineEventParam)); if (event->params == NULL) { - dmError("Could not allocate memory for timeline event parameters.\n"); - return DMERR_MALLOC; + return dmError(DMERR_MALLOC, + "Could not allocate memory for timeline event parameters.\n"); } for (param = 0; param < event->nparams; param++) diff -r b66653c9acb3 -r 985225a93aeb src/dmzlib.c --- a/src/dmzlib.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmzlib.c Fri Feb 27 03:58:25 2015 +0200 @@ -8,15 +8,7 @@ #define DM_ZLIB_TMPBUF_SIZE (16 * 1024) -#define STBI_ASSERT(x) // dummy - - -static int stbi__err(const char *s, const char *p) -{ - (void) s; - (void) p; - return 0; -} +#define DMSTBI_ASSERT(x) // dummy // @TODO: should statically initialize these for optimal thread safety @@ -57,21 +49,21 @@ static inline int stbi__bit_reverse_n(int v, int bits) { - STBI_ASSERT(bits <= 16); + DMSTBI_ASSERT(bits <= 16); // to bit reverse n bits, reverse 16 and shift // e.g. 11 bits, bit reverse and shift away 5 return stbi__bit_reverse_16(v) >> (16 - bits); } -static int stbi__zbuild_huffman(DMZHuffmanContext * z, const Uint8 * sizelist, const int num) +static int stbi__zbuild_huffman(DMZHuffmanContext * ctx, const Uint8 * sizelist, const int num) { int i, k = 0; int code, next_code[16], sizes[17]; // DEFLATE spec for generating codes memset(sizes, 0, sizeof(sizes)); - memset(z->fast, 0, sizeof(z->fast)); + memset(ctx->fast, 0, sizeof(ctx->fast)); for (i = 0; i < num; i++) sizes[sizelist[i]]++; @@ -80,41 +72,47 @@ for (i = 1; i < 16; i++) { if (sizes[i] > (1 << i)) - return stbi__err("fail!", "omg!"); + { + return dmError(DMERR_INTERNAL, + "Sizes assert failed while building Huffman codes.\n"); + } } code = 0; for (i = 1; i < 16; i++) { next_code[i] = code; - z->firstCode[i] = (Uint16) code; - z->firstSymbol[i] = (Uint16) k; + ctx->firstCode[i] = (Uint16) code; + ctx->firstSymbol[i] = (Uint16) k; code = (code + sizes[i]); if (sizes[i] && code - 1 >= (1 << i)) - return stbi__err("bad codelengths", "Corrupt JPEG"); + { + return dmError(DMERR_INVALID_DATA, + "Bad Huffman code lengths.\n"); + } - z->maxCode[i] = code << (16 - i); // preshift for inner loop + ctx->maxCode[i] = code << (16 - i); // preshift for inner loop code <<= 1; k += sizes[i]; } - z->maxCode[16] = 0x10000; // sentinel + ctx->maxCode[16] = 0x10000; // sentinel for (i = 0; i < num; i++) { int s = sizelist[i]; if (s) { - int c = next_code[s] - z->firstCode[s] + z->firstSymbol[s]; + int c = next_code[s] - ctx->firstCode[s] + ctx->firstSymbol[s]; Uint16 fastv = (Uint16) ((s << 9) | i); - z->size[c] = (Uint8) s; - z->value[c] = (Uint16) i; + ctx->size[c] = (Uint8) s; + ctx->value[c] = (Uint16) i; if (s <= STBI__ZFAST_BITS) { int k = stbi__bit_reverse_n(next_code[s], s); while (k < STBI__ZFAST_SIZE) { - z->fast[k] = fastv; + ctx->fast[k] = fastv; k += (1 << s); } } @@ -125,103 +123,123 @@ } -static inline Uint8 stbi__zget8(DMZLibContext * z) +static inline Uint8 stbi__zget8(DMZLibContext * ctx) { - if (z->zbuffer >= z->zbuffer_end) + if (ctx->zbuffer >= ctx->zbufferEnd) return 0; - return *z->zbuffer++; + return *ctx->zbuffer++; } -static void stbi__fill_bits(DMZLibContext * z) +static void stbi__fill_bits(DMZLibContext * ctx) { do { - STBI_ASSERT(z->code_buffer < (1U << z->num_bits)); - z->code_buffer |= stbi__zget8(z) << z->num_bits; - z->num_bits += 8; + DMSTBI_ASSERT(ctx->codeBuffer < (1U << ctx->numBits)); + ctx->codeBuffer |= stbi__zget8(ctx) << ctx->numBits; + ctx->numBits += 8; } - while (z->num_bits <= 24); + while (ctx->numBits <= 24); } -static inline unsigned int stbi__zreceive(DMZLibContext * z, int n) +static inline unsigned int stbi__zreceive(DMZLibContext * ctx, int n) { - unsigned int k; - if (z->num_bits < n) - stbi__fill_bits(z); - k = z->code_buffer & ((1 << n) - 1); - z->code_buffer >>= n; - z->num_bits -= n; - return k; + unsigned int val; + + if (ctx->numBits < n) + stbi__fill_bits(ctx); + + val = ctx->codeBuffer & ((1 << n) - 1); + ctx->codeBuffer >>= n; + ctx->numBits -= n; + + return val; } -static int stbi__zhuffman_decode_slowpath(DMZLibContext * a, DMZHuffmanContext * z) +static int stbi__zhuffman_decode_slowpath(DMZLibContext * ctx, DMZHuffmanContext * huff, int *val) { int b, s, k; // not resolved by fast table, so compute it the slow way // use jpeg approach, which requires MSbits at top - k = stbi__bit_reverse_16(a->code_buffer); + k = stbi__bit_reverse_16(ctx->codeBuffer); for (s = STBI__ZFAST_BITS + 1; ; s++) { - if (k < z->maxCode[s]) break; + if (k < huff->maxCode[s]) + break; } if (s == 16) - return -1; // invalid code! + { + return dmError(DMERR_DATA_ERROR, + "Bad Huffman code.\n"); + } // code size is s, so: - b = (k >> (16 - s)) - z->firstCode[s] + z->firstSymbol[s]; - STBI_ASSERT(z->size[b] == s); - a->code_buffer >>= s; - a->num_bits -= s; - return z->value[b]; + b = (k >> (16 - s)) - huff->firstCode[s] + huff->firstSymbol[s]; + DMSTBI_ASSERT(huff->size[b] == s); + + ctx->codeBuffer >>= s; + ctx->numBits -= s; + *val = huff->value[b]; + + return DMERR_OK; } -static inline int stbi__zhuffman_decode(DMZLibContext * a, DMZHuffmanContext * z) +static inline int stbi__zhuffman_decode(DMZLibContext * ctx, DMZHuffmanContext * huff, int *val) { int b; - if (a->num_bits < 16) - stbi__fill_bits(a); + if (ctx->numBits < 16) + stbi__fill_bits(ctx); - b = z->fast[a->code_buffer & STBI__ZFAST_MASK]; + b = huff->fast[ctx->codeBuffer & STBI__ZFAST_MASK]; if (b) { int s = b >> 9; - a->code_buffer >>= s; - a->num_bits -= s; - return b & 511; + ctx->codeBuffer >>= s; + ctx->numBits -= s; + *val = b & 511; + return DMERR_OK; } - return stbi__zhuffman_decode_slowpath(a, z); + + return stbi__zhuffman_decode_slowpath(ctx, huff, val); } -static int stbi__zexpand(DMZLibContext * z, char *zout, int n) // need to make room for n bytes +static int stbi__zexpand(DMZLibContext * ctx, Uint8 *zout, size_t n) { - char *q; - int cur, limit; - z->zout = zout; + Uint8 *newBuf; + size_t cur, limit; + + ctx->zout = zout; - if (!z->z_expandable) - return stbi__err("output buffer limit", "Corrupt PNG"); + if (!ctx->expandable) + { + return dmError(DMERR_BOUNDS, + "Output buffer limit hit, and is not expandable.\n"); + } - cur = (int) (z->zout - z->zout_start); - limit = (int) (z->zout_end - z->zout_start); + cur = ctx->zout - ctx->zoutStart; + limit = ctx->zoutEnd - ctx->zoutStart; while (cur + n > limit) limit *= 2; - if ((q = (char *) dmRealloc(z->zout_start, limit)) == NULL) - return stbi__err("outofmem", "Out of memory"); + if ((newBuf = (Uint8 *) dmRealloc(ctx->zoutStart, limit)) == NULL) + { + return dmError(DMERR_MALLOC, + "Could not reallocate buffer.\n"); + } - z->zout_start = q; - z->zout = q + cur; - z->zout_end = q + limit; - return 1; + ctx->zoutStart = newBuf; + ctx->zout = newBuf + cur; + ctx->zoutEnd = newBuf + limit; + + return DMERR_OK; } @@ -254,22 +272,23 @@ static int stbi__parse_huffman_block(DMZLibContext * a) { - char *zout = a->zout; + Uint8 *zout = a->zout; for (;;) { - int z = stbi__zhuffman_decode(a, &a->z_length); + int z, ret; + if ((ret = stbi__zhuffman_decode(a, &a->zlength, &z)) != DMERR_OK) + return ret; + if (z < 256) { - if (z < 0) - return stbi__err("bad huffman code", "Corrupt PNG"); // error in huffman codes + if (zout >= a->zoutEnd) + { + if ((ret = stbi__zexpand(a, zout, 1)) != DMERR_OK) + return ret; - if (zout >= a->zout_end) - { - if (!stbi__zexpand(a, zout, 1)) - return 0; zout = a->zout; } - *zout++ = (char) z; + *zout++ = (Uint8) z; } else { @@ -278,7 +297,7 @@ if (z == 256) { a->zout = zout; - return 1; + return DMERR_OK; } z -= 257; @@ -286,18 +305,20 @@ if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); - z = stbi__zhuffman_decode(a, &a->z_distance); - if (z < 0) - return stbi__err("bad huffman code", "Corrupt PNG"); + if ((ret = stbi__zhuffman_decode(a, &a->zdistance, &z)) != DMERR_OK) + return ret; dist = stbi__zdist_base[z]; if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); - if (zout - a->zout_start < dist) - return stbi__err("bad dist", "Corrupt PNG"); + if (zout - a->zoutStart < dist) + { + return dmError(DMERR_DATA_ERROR, + "Bad Huffman block distance.\n"); + } - if (zout + len > a->zout_end) + if (zout + len > a->zoutEnd) { if (!stbi__zexpand(a, zout, len)) return 0; @@ -331,9 +352,9 @@ DMZHuffmanContext z_codelength; Uint8 lencodes[286 + 32 + 137]; //padding for maximum single op Uint8 codelength_sizes[19]; - int i, n; + int i, n, ret; - int hlit = stbi__zreceive(a, 5) + 257; + int hlit = stbi__zreceive(a, 5) + 257; int hdist = stbi__zreceive(a, 5) + 1; int hclen = stbi__zreceive(a, 4) + 4; @@ -344,15 +365,18 @@ int s = stbi__zreceive(a, 3); codelength_sizes[length_dezigzag[i]] = (Uint8) s; } - if (!stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) - return 0; + if ((ret = stbi__zbuild_huffman(&z_codelength, codelength_sizes, 19)) != DMERR_OK) + return ret; n = 0; while (n < hlit + hdist) { - int c = stbi__zhuffman_decode(a, &z_codelength); - STBI_ASSERT(c >= 0 && c < 19); + int c; + if ((ret = stbi__zhuffman_decode(a, &z_codelength, &c)) != DMERR_OK) + return ret; + + DMSTBI_ASSERT(c >= 0 && c < 19); if (c < 16) lencodes[n++] = (Uint8) c; @@ -379,14 +403,18 @@ } if (n != hlit + hdist) - return stbi__err("bad codelengths", "Corrupt PNG"); + { + return dmError(DMERR_DATA_ERROR, + "Bad huffman codelengths.\n"); + } - if (!stbi__zbuild_huffman(&a->z_length, lencodes, hlit)) - return 0; + if ((ret = stbi__zbuild_huffman(&a->zlength, lencodes, hlit)) != DMERR_OK) + return ret; - if (!stbi__zbuild_huffman(&a->z_distance, lencodes + hlit, hdist)) - return 0; - return 1; + if ((ret = stbi__zbuild_huffman(&a->zdistance, lencodes + hlit, hdist)) != DMERR_OK) + return ret; + + return DMERR_OK; } @@ -395,80 +423,97 @@ Uint8 header[4]; int len, nlen, k; - if (a->num_bits & 7) - stbi__zreceive(a, a->num_bits & 7); // discard + if (a->numBits & 7) + stbi__zreceive(a, a->numBits & 7); // discard // drain the bit-packed data into header k = 0; - while (a->num_bits > 0) + while (a->numBits > 0) { - header[k++] = (Uint8) (a->code_buffer & 255); // suppress MSVC run-time check - a->code_buffer >>= 8; - a->num_bits -= 8; + header[k++] = (Uint8) (a->codeBuffer & 255); // suppress MSVC run-time check + a->codeBuffer >>= 8; + a->numBits -= 8; } - STBI_ASSERT(a->num_bits == 0); + DMSTBI_ASSERT(a->numBits == 0); // now fill header the normal way while (k < 4) header[k++] = stbi__zget8(a); - len = header[1] * 256 + header[0]; - nlen = header[3] * 256 + header[2]; + len = (header[1] << 8) | header[0]; + nlen = (header[3] << 8) | header[2]; if (nlen != (len ^ 0xffff)) - return stbi__err("zlib corrupt", "Corrupt PNG"); + { + return dmError(DMERR_DATA_ERROR, + "Compressed data corrupt.\n"); + } - if (a->zbuffer + len > a->zbuffer_end) - return stbi__err("read past buffer", "Corrupt PNG"); + if (a->zbuffer + len > a->zbufferEnd) + { + return dmError(DMERR_BOUNDS, + "Read past buffer, probably corrupt compressed data.\n"); + } - if (a->zout + len > a->zout_end && !stbi__zexpand(a, a->zout, len)) - return 0; + if (a->zout + len > a->zoutEnd && !stbi__zexpand(a, a->zout, len)) + { + return dmError(DMERR_DATA_ERROR, + "XXXX TODO"); + } memcpy(a->zout, a->zbuffer, len); a->zbuffer += len; - a->zout += len; - return 1; + a->zout += len; + + return DMERR_OK; } -static int stbi__parse_zlib_header(DMZLibContext * a) +int dmZLibParseHeader(DMZLibContext * ctx, BOOL checkPNG) { - int cmf = stbi__zget8(a); + int cmf = stbi__zget8(ctx); + int flags = stbi__zget8(ctx); int cm = cmf & 15; - int flg = stbi__zget8(a); // int cinfo = cmf >> 4; - if ((cmf * 256 + flg) % 31 != 0) - return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec + if ((cmf * 256 + flags) % 31 != 0) + { + return dmError(DMERR_INVALID_DATA, + "Bad zlib header."); + } - if (flg & 32) - return stbi__err("no preset dict", "Corrupt PNG"); // preset dictionary not allowed in png + if (checkPNG && (flags & 32)) + { + // preset dictionary not allowed in png + return dmError(DMERR_NOT_SUPPORTED, + "Preset dictionary not allowed in PNG.\n"); + } - if (cm != 8) - return stbi__err("bad compression", "Corrupt PNG"); // DEFLATE required for png + if (checkPNG && cm != 8) + { + return dmError(DMERR_INVALID_DATA, + "Bad or unsupported compression type.\n"); + } // window = 1 << (8 + cinfo)... but who cares, we fully buffer output - return 1; + return DMERR_OK; } -static int stbi__parse_zlib(DMZLibContext * a, BOOL parse_header) +int dmZLibDecode(DMZLibContext * ctx) { - int final, type; + int final, type, ret; - if (parse_header && !stbi__parse_zlib_header(a)) - return 0; - - a->num_bits = 0; - a->code_buffer = 0; + ctx->numBits = 0; + ctx->codeBuffer = 0; do { - final = stbi__zreceive(a, 1); - type = stbi__zreceive(a, 2); + final = stbi__zreceive(ctx, 1); + type = stbi__zreceive(ctx, 2); if (type == 0) { - if (!stbi__parse_uncompressed_block(a)) - return 0; + if ((ret = stbi__parse_uncompressed_block(ctx)) != DMERR_OK) + return ret; } else if (type == 3) @@ -478,136 +523,127 @@ if (type == 1) { // use fixed code lengths - if (!stbi__zbuild_huffman(&a->z_length, stbi__zdefault_length, 288)) - return 0; + if ((ret = stbi__zbuild_huffman(&ctx->zlength, stbi__zdefault_length, 288)) != DMERR_OK) + return ret; - if (!stbi__zbuild_huffman - (&a->z_distance, stbi__zdefault_distance, 32)) - return 0; + if ((ret = stbi__zbuild_huffman(&ctx->zdistance, stbi__zdefault_distance, 32)) != DMERR_OK) + return ret; } else - { - if (!stbi__compute_huffman_codes(a)) - return 0; - } - if (!stbi__parse_huffman_block(a)) - return 0; + if ((ret = stbi__compute_huffman_codes(ctx)) != DMERR_OK) + return ret; + + if ((ret = stbi__parse_huffman_block(ctx)) != DMERR_OK) + return ret; } } while (!final); - return 1; + + return DMERR_OK; } -static int stbi__do_zlib(DMZLibContext * a, char *obuf, int olen, int exp, - BOOL parse_header) +Uint8 *stbi_zlib_decode_malloc_guesssize_headerflag( + const Uint8 *buffer, const size_t len, + const size_t initialSize, size_t *outLen, + BOOL parseHeader) { - a->zout_start = obuf; - a->zout = obuf; - a->zout_end = obuf + olen; - a->z_expandable = exp; + DMZLibContext ctx; + Uint8 *outBuf; + int ret; - return stbi__parse_zlib(a, parse_header); -} - + if ((outBuf = dmMalloc(initialSize)) == NULL) + return NULL; -char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen) -{ - DMZLibContext a; - char *p = (char *) dmMalloc(initial_size); - if (p == NULL) - return NULL; - a.zbuffer = (Uint8 *) buffer; - a.zbuffer_end = (Uint8 *) buffer + len; - if (stbi__do_zlib(&a, p, initial_size, 1, 1)) + ctx.zbuffer = (Uint8 *) buffer; + ctx.zbufferEnd = (Uint8 *) buffer + len; + ctx.zout = outBuf; + ctx.zoutStart = outBuf; + ctx.zoutEnd = outBuf + initialSize; + ctx.expandable = TRUE; + + if (parseHeader && (ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) { - if (outlen) - *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; + return dmError(ret, + "Failed to parse zlib header data.\n"); + } + + if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) + { + if (outLen) + *outLen = ctx.zout - ctx.zoutStart; + + return ctx.zoutStart; } else { - dmFree(a.zout_start); + dmFree(ctx.zoutStart); return NULL; } } -char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen) +#if 0 + +Uint8 *stbi_zlib_decode_malloc(Uint8 const *buffer, int len, int *outlen) { return stbi_zlib_decode_malloc_guesssize(buffer, len, DM_ZLIB_TMPBUF_SIZE, outlen); } -char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, - int len, int initial_size, int *outlen, BOOL parse_header) +int stbi_zlib_decode_buffer(Uint8 *obuffer, size_t olen, Uint8 const *ibuffer, size_t ilen, size_t *res) { - DMZLibContext a; - char *p = (char *) dmMalloc(initial_size); + DMZLibContext ctx; + int ret; + + ctx.zbuffer = (Uint8 *) ibuffer; + ctx.zbufferEnd = (Uint8 *) ibuffer + ilen; + + if ((ret = stbi__do_zlib(&a, obuffer, olen, 0, 1)) != DMERR_OK) + { + *res = a.zout - a.zoutStart; + return DMERR_OK; + } + else + return ret; +} + + +Uint8 *stbi_zlib_decode_noheader_malloc(Uint8 const *buffer, int len, size_t *outlen) +{ + DMZLibContext ctx; + Uint8 *p = (Uint8 *) dmMalloc(DM_ZLIB_TMPBUF_SIZE); if (p == NULL) return NULL; - a.zbuffer = (Uint8 *) buffer; - a.zbuffer_end = (Uint8 *) buffer + len; - if (stbi__do_zlib(&a, p, initial_size, 1, parse_header)) + ctx.zbuffer = (Uint8 *) buffer; + ctx.zbufferEnd = (Uint8 *) buffer + len; + + if (stbi__do_zlib(&ctx, p, DM_ZLIB_TMPBUF_SIZE, 1, 0)) { - if (outlen) - *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; + if (outlen != NULL) + *outlen = (int) (ctx.zout - a.zoutStart); + return a.zoutStart; } else { - dmFree(a.zout_start); + dmFree(a.zoutStart); return NULL; } } -int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen) +int stbi_zlib_decode_noheader_buffer(Uint8 *obuffer, int olen, const Uint8 *ibuffer, int ilen) { DMZLibContext a; + a.zbuffer = (Uint8 *) ibuffer; - a.zbuffer_end = (Uint8 *) ibuffer + ilen; - if (stbi__do_zlib(&a, obuffer, olen, 0, 1)) - return (int) (a.zout - a.zout_start); + a.zbufferEnd = (Uint8 *) ibuffer + ilen; + + if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) + return (int) (a.zout - a.zoutStart); else return -1; } - -char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen) -{ - DMZLibContext a; - char *p = (char *) dmMalloc(DM_ZLIB_TMPBUF_SIZE); - if (p == NULL) - return NULL; - - a.zbuffer = (Uint8 *) buffer; - a.zbuffer_end = (Uint8 *) buffer + len; - - if (stbi__do_zlib(&a, p, DM_ZLIB_TMPBUF_SIZE, 1, 0)) - { - if (outlen != NULL) - *outlen = (int) (a.zout - a.zout_start); - return a.zout_start; - } - else - { - dmFree(a.zout_start); - return NULL; - } -} - - -int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen) -{ - DMZLibContext a; - - a.zbuffer = (Uint8 *) ibuffer; - a.zbuffer_end = (Uint8 *) ibuffer + ilen; - - if (stbi__do_zlib(&a, obuffer, olen, 0, 0)) - return (int) (a.zout - a.zout_start); - else - return -1; -} +#endif diff -r b66653c9acb3 -r 985225a93aeb src/dmzlib.h --- a/src/dmzlib.h Fri Feb 27 02:21:57 2015 +0200 +++ b/src/dmzlib.h Fri Feb 27 03:58:25 2015 +0200 @@ -32,28 +32,23 @@ typedef struct { - Uint8 *zbuffer, *zbuffer_end; + Uint8 *zbuffer, *zbufferEnd; - int num_bits; - Uint32 code_buffer; + int numBits; + Uint32 codeBuffer; - char *zout, *zout_start, *zout_end; - int z_expandable; + Uint8 *zout, *zoutStart, *zoutEnd; + BOOL expandable; - DMZHuffmanContext z_length, z_distance; + DMZHuffmanContext zlength, zdistance; } DMZLibContext; void dmZLibInit(); +int dmZLibDecode(DMZLibContext * ctx); +int dmZLibParseHeader(DMZLibContext * ctx, BOOL checkPNG); -char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); -char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen); -char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, - int len, int initial_size, int *outlen, BOOL parse_header); -int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen); -char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen); -int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); - +Uint8 *stbi_zlib_decode_malloc_guesssize(const Uint8 *buffer, const size_t len, const size_t initialSize, size_t *outLen); #ifdef __cplusplus } diff -r b66653c9acb3 -r 985225a93aeb src/libgfx.c --- a/src/libgfx.c Fri Feb 27 02:21:57 2015 +0200 +++ b/src/libgfx.c Fri Feb 27 03:58:25 2015 +0200 @@ -299,8 +299,9 @@ if ((fp = fopen(filename, "wb")) == NULL) { - dmError("RAW: Could not open file '%s' for writing.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "RAW: Could not open file '%s' for writing.\n", + filename); } res = dmWriteRAWImageFILE(fp, img, spec); @@ -341,8 +342,9 @@ // Create output file if ((fp = fopen(filename, "wb")) == NULL) { - dmError("PPM: could not open file '%s' for writing.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "PPM: could not open file '%s' for writing.\n", + filename); } res = dmWritePPMImageFILE(fp, img, spec); @@ -380,23 +382,24 @@ if (png_ptr == NULL) { - dmError("PNG: png_create_write_struct() failed.\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PNG: png_create_write_struct() failed.\n"); goto error; } info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { - dmError("PNG: png_create_info_struct(%p) failed.\n", png_ptr); - res = DMERR_INIT_FAIL; + res = dmError(DMERR_INIT_FAIL, + "PNG: png_create_info_struct(%p) failed.\n", + png_ptr); goto error; } if (setjmp(png_jmpbuf(png_ptr))) { - dmError("PNG: Error during image writing..\n"); - res = DMERR_INIT_FAIL; + res = dmError(DMERR_INIT_FAIL, + "PNG: Error during image writing..\n"); goto error; } @@ -409,8 +412,9 @@ case DM_IFMT_RGB : fmt = PNG_COLOR_TYPE_RGB; break; case DM_IFMT_RGBA : fmt = PNG_COLOR_TYPE_RGB_ALPHA; break; default: - dmError("PNG: Unsupported image format %d.\n", spec->format); - res = DMERR_NOT_SUPPORTED; + res = dmError(DMERR_NOT_SUPPORTED, + "PNG: Unsupported image format %d.\n", + spec->format); goto error; } @@ -436,8 +440,8 @@ if (palette == NULL) { - dmError("PNG: Could not allocate palette structure."); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PNG: Could not allocate palette structure."); goto error; } @@ -482,8 +486,9 @@ if ((fp = fopen(filename, "wb")) == NULL) { - dmError("PNG: could not open file '%s' for writing.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "PNG: could not open file '%s' for writing.\n", + filename); } res = dmWritePNGImageFILE(fp, img, spec); @@ -512,23 +517,24 @@ if (png_ptr == NULL) { - dmError("PNG: png_create_write_struct() failed.\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PNG: png_create_write_struct() failed.\n"); goto error; } info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) { - dmError("PNG: png_create_info_struct(%p) failed.\n", png_ptr); - res = DMERR_INIT_FAIL; + res = dmError(DMERR_INIT_FAIL, + "PNG: png_create_info_struct(%p) failed.\n", + png_ptr); goto error; } if (setjmp(png_jmpbuf(png_ptr))) { - dmError("PNG: Error during image reading..\n"); - res = DMERR_INIT_FAIL; + res = dmError(DMERR_INIT_FAIL, + "PNG: Error during image reading..\n"); goto error; } @@ -542,9 +548,9 @@ if (width < 1 || height < 1) { - dmError("PNG: Invalid width or height (%d x %d)\n", + res = dmError(DMERR_INVALID_DATA, + "PNG: Invalid width or height (%d x %d)\n", width, height); - res = DMERR_INVALID_DATA; goto error; } @@ -556,9 +562,9 @@ if (bit_depth > 8) { - dmError("PNG: Unsupported bit depth for grayscale image: %d\n", + res = dmError(DMERR_NOT_SUPPORTED, + "PNG: Unsupported bit depth for grayscale image: %d\n", bit_depth); - res = DMERR_NOT_SUPPORTED; goto error; } break; @@ -568,8 +574,8 @@ break; default: - dmError("PNG: RGB/RGBA images not supported for loading.\n"); - res = DMERR_NOT_SUPPORTED; + res = dmError(DMERR_NOT_SUPPORTED, + "PNG: RGB/RGBA images not supported for loading.\n"); goto error; } @@ -579,8 +585,8 @@ if ((*pimg = img = dmImageAlloc(width, height)) == NULL) { - dmError("PNG: Could not allocate image data.\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PNG: Could not allocate image data.\n"); goto error; } @@ -665,8 +671,9 @@ if ((fp = fopen(filename, "rb")) == NULL) { - dmError("PNG: Could not open file '%s' for reading.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "PNG: Could not open file '%s' for reading.\n", + filename); } res = dmReadPNGImageFILE(fp, img); @@ -841,9 +848,9 @@ pcx.bufLen = hdr.bpl * 4; if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) { - dmError("PCX: Could not allocate %d bytes for RLE compression buffer.\n", + res = dmError(DMERR_MALLOC, + "PCX: Could not allocate %d bytes for RLE compression buffer.\n", pcx.bufLen); - res = DMERR_MALLOC; goto error; } @@ -853,8 +860,8 @@ !dm_fwrite_byte(pcx.fp, hdr.encoding) || !dm_fwrite_byte(pcx.fp, hdr.bpp)) { - dmError("PCX: Could not write basic header data.\n"); - res = DMERR_FWRITE; + res = dmError(DMERR_FWRITE, + "PCX: Could not write basic header data.\n"); goto error; } @@ -865,15 +872,15 @@ !dm_fwrite_le16(pcx.fp, hdr.hres) || !dm_fwrite_le16(pcx.fp, hdr.vres)) { - dmError("PCX: Could not write image dimensions.\n"); - res = DMERR_FWRITE; + res = dmError(DMERR_FWRITE, + "PCX: Could not write image dimensions.\n"); goto error; } if (!dm_fwrite_str(pcx.fp, (Uint8 *) &hdr.colormap, sizeof(hdr.colormap))) { - dmError("PCX: Could not write colormap.\n"); - res = DMERR_FWRITE; + res = dmError(DMERR_FWRITE, + "PCX: Could not write colormap.\n"); goto error; } @@ -883,8 +890,8 @@ !dm_fwrite_le16(pcx.fp, hdr.palinfo) || !dm_fwrite_str(pcx.fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) { - dmError("PCX: Could not write header remainder.\n"); - res = DMERR_FWRITE; + res = dmError(DMERR_FWRITE, + "PCX: Could not write header remainder.\n"); goto error; } @@ -927,8 +934,9 @@ if ((fp = fopen(filename, "wb")) == NULL) { - dmError("PCX: Could not open file '%s' for writing.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "PCX: Could not open file '%s' for writing.\n", + filename); } res = dmWritePCXImageFILE(fp, img, spec); @@ -984,8 +992,8 @@ !dm_fread_byte(fp, &hdr.encoding) || !dm_fread_byte(fp, &hdr.bpp)) { - dmError("PCX: Could not read basic header data.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Could not read basic header data.\n"); goto error; } @@ -994,8 +1002,8 @@ hdr.encoding != 1 || hdr.bpp != 8) { - dmError("PCX: Not a PCX file, or unsupported variant.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_NOT_SUPPORTED, + "PCX: Not a PCX file, or unsupported variant.\n"); goto error; } @@ -1006,15 +1014,15 @@ !dm_fread_le16(fp, &hdr.hres) || !dm_fread_le16(fp, &hdr.vres)) { - dmError("PCX: Could not read image dimensions.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Could not read image dimensions.\n"); goto error; } if (!dm_fread_str(fp, (Uint8 *) &hdr.colormap, sizeof(hdr.colormap))) { - dmError("PCX: Could not read colormap.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Could not read colormap.\n"); goto error; } @@ -1024,23 +1032,24 @@ !dm_fread_le16(fp, &hdr.palinfo) || !dm_fread_str(fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) { - dmError("PCX: Could not read header remainder.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Could not read header remainder.\n"); goto error; } if (hdr.nplanes != 3 && hdr.nplanes != 1) { - dmError("PCX: Unsupported number of bitplanes %d.\n", hdr.nplanes); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Unsupported number of bitplanes %d.\n", + hdr.nplanes); goto error; } // Allocate image if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1)) == NULL) { - dmError("PCX: Could not allocate image structure.\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PCX: Could not allocate image structure.\n"); goto error; } @@ -1048,8 +1057,8 @@ pcx.bufLen = hdr.nplanes * hdr.bpl; if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) { - dmError("PCX: Could not allocate RLE buffer.\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PCX: Could not allocate RLE buffer.\n"); goto error; } @@ -1060,8 +1069,8 @@ // Decode row of RLE'd data if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen)) { - dmError("PCX: Error decoding RLE data.\n"); - res = DMERR_INVALID_DATA; + res = dmError(DMERR_INVALID_DATA, + "PCX: Error decoding RLE data.\n"); goto error; } @@ -1112,8 +1121,8 @@ if (!dmImageAllocPalette(img, ncolors, -1)) { - dmError("PCX: Could not allocate palette data!\n"); - res = DMERR_MALLOC; + res = dmError(DMERR_MALLOC, + "PCX: Could not allocate palette data!\n"); goto error; } @@ -1121,8 +1130,9 @@ { if (!dmReadPaletteData(fp, img->pal, ncolors)) { - dmError("PCX: Error reading palette.\n"); - return DMERR_FREAD; + res = dmError(DMERR_FREAD, + "PCX: Error reading palette.\n"); + goto error; } } else @@ -1152,8 +1162,9 @@ if ((fp = fopen(filename, "rb")) == NULL) { - dmError("PCX: Could not open file '%s' for reading.\n", filename); - return -15; + return dmError(DMERR_FOPEN, + "PCX: Could not open file '%s' for reading.\n", + filename); } res = dmReadPCXImageFILE(fp, pimg); @@ -1222,11 +1233,12 @@ if (!dm_fread_be32(fp, &chunk->id) || !dm_fread_be32(fp, &chunk->size)) { - dmError("ILBM: Could not read IFF chunk header.\n"); - return FALSE; + dmError(DMERR_FREAD, + "ILBM: Could not read IFF chunk header.\n"); + return TRUE; } else - return TRUE; + return FALSE; } static char * dmGetIFFChunkID(DMIFFChunk *chunk) @@ -1239,34 +1251,44 @@ return chunk->str; } -static BOOL dmSkipIFFChunkRest(FILE *fp, const DMIFFChunk *chunk, const Uint32 used) +static int dmSkipIFFChunkRest(FILE *fp, const DMIFFChunk *chunk, const Uint32 used) { if (chunk->size > used) { dmMsg(4, "ILBM: Skipping %d bytes (%d of %d consumed)\n", chunk->size - used, used, chunk->size); - return fseeko(fp, chunk->size - used, SEEK_CUR) == 0; + + if (fseeko(fp, chunk->size - used, SEEK_CUR) != 0) + { + return dmError(DMERR_FSEEK, + "ILBM: Failed to skip chunk end.\n"); + } + else + return DMERR_OK; } else - return TRUE; + return DMERR_OK; } -static BOOL dmCheckIFFChunk(DMIFFChunk *dest, DMIFFChunk *chunk, +static int dmCheckIFFChunk(DMIFFChunk *dest, DMIFFChunk *chunk, const BOOL multi, const Uint32 minSize) { if (dest->count > 0 && !multi) { - dmError("ILBM: Multiple instances of chunk %s found.\n", + return dmError(DMERR_INVALID_DATA, + "ILBM: Multiple instances of chunk %s found.\n", dmGetIFFChunkID(chunk)); - return FALSE; } - + dest->count++; if (chunk->size < minSize) - return FALSE; - - return TRUE; + { + return dmError(DMERR_OUT_OF_DATA, + "ILBM: Chunk is too small.\n"); + } + + return DMERR_OK; } @@ -1367,8 +1389,9 @@ // Decompress or read data if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) { - dmError("ILBM: Error in reading image plane #%d @ %d.\n", plane, yc); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "ILBM: Error in reading image plane #%d @ %d.\n", + plane, yc); goto error; } @@ -1386,8 +1409,8 @@ // Decompress or read data if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) { - dmError("ILBM: Error in reading mask plane.\n"); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "ILBM: Error in reading mask plane.\n"); goto error; } @@ -1429,8 +1452,8 @@ if (!dmIFFReadOneRow(fp, iff, dp, img->width)) { - dmError("ILBM: Error in reading image row #%d.\n", yc); - res = DMERR_FREAD; + res = dmError(DMERR_FREAD, + "ILBM: Error in reading image row #%d.\n", yc); goto error; } @@ -1458,16 +1481,16 @@ chunk.id != IFF_ID_FORM || chunk.size < 32) { - dmError("ILBM: Not a IFF file.\n"); - return DMERR_FREAD; + return dmError(DMERR_NOT_SUPPORTED, + "ILBM: Not a IFF file.\n"); } // Check IFF ILBM signature if (!dm_fread_be32(fp, &idILBM) || (idILBM != IFF_ID_ILBM && idILBM != IFF_ID_PBM)) { - dmError("ILBM: Not a ILBM file.\n"); - return DMERR_INVALID_DATA; + return dmError(DMERR_INVALID_DATA, + "ILBM: Not a ILBM file.\n"); } iff.planar = (idILBM == IFF_ID_ILBM); @@ -1476,16 +1499,16 @@ { if (!dmReadIFFChunk(fp, &chunk)) { - dmError("ILBM: Error reading IFF ILBM data.\n"); - return DMERR_FREAD; + return dmError(DMERR_FREAD, + "ILBM: Error reading IFF ILBM data.\n"); } switch (chunk.id) { case IFF_ID_BMHD: // Check for multiple occurences of BMHD - if (!dmCheckIFFChunk(&iff.chBMHD, &chunk, FALSE, sizeof(iff.bmhd))) - return DMERR_FREAD; + if ((res = dmCheckIFFChunk(&iff.chBMHD, &chunk, FALSE, sizeof(iff.bmhd))) != DMERR_OK) + return res; // Read BMHD data if (!dm_fread_be16(fp, &iff.bmhd.w) || @@ -1502,9 +1525,10 @@ !dm_fread_be16(fp, (Uint16 *) &iff.bmhd.pagew) || !dm_fread_be16(fp, (Uint16 *) &iff.bmhd.pageh)) { - dmError("ILBM: Error reading BMHD chunk.\n"); - return DMERR_FREAD; + return dmError(DMERR_FREAD, + "ILBM: Error reading BMHD chunk.\n"); } + dmMsg(3, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n", iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking); @@ -1517,23 +1541,27 @@ iff.bmhd.masking != IFF_MASK_HAS_MASK && iff.bmhd.masking != IFF_MASK_TRANSP)) { - dmError("ILBM: Unsupported features, refusing to load.\n"); - return DMERR_NOT_SUPPORTED; + return dmError(DMERR_NOT_SUPPORTED, + "ILBM: Unsupported features, refusing to load.\n"); } - if (!dmSkipIFFChunkRest(fp, &chunk, sizeof(iff.bmhd))) - return DMERR_FREAD; + if ((res = dmSkipIFFChunkRest(fp, &chunk, sizeof(iff.bmhd))) != DMERR_OK) + return res; break; case IFF_ID_CMAP: // Check for multiple occurences of CMAP - if (!dmCheckIFFChunk(&iff.chCMAP, &chunk, FALSE, 3)) - return DMERR_FREAD; + if ((res = dmCheckIFFChunk(&iff.chCMAP, &chunk, FALSE, 3)) != DMERR_OK) + return res; // Check for sanity if (chunk.size % 3 != 0) - dmError("ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n"); + { + // Non-fatal + dmError(DMERR_INVALID_DATA, + "ILBM: CMAP chunk size not divisible by 3, possibly broken file.\n"); + } iff.ncolors = chunk.size / 3; dmMsg(3, "ILBM: CMAP %d entries (%d bytes)\n", @@ -1548,13 +1576,13 @@ if (!dmPaletteAlloc(&iff.pal, iff.ncolors, (iff.bmhd.masking == IFF_MASK_TRANSP) ? iff.bmhd.transp : -1)) { - dmError("ILBM: Could not allocate palette data.\n"); - return DMERR_MALLOC; + return dmError(DMERR_MALLOC, + "ILBM: Could not allocate palette data.\n"); } if (!dmReadPaletteData(fp, iff.pal, iff.ncolors)) { - dmError("ILBM: Error reading CMAP.\n"); - return DMERR_FREAD; + return dmError(DMERR_FREAD, + "ILBM: Error reading CMAP.\n"); } } @@ -1564,14 +1592,14 @@ case IFF_ID_BODY: // Check for multiple occurences of CMAP - if (!dmCheckIFFChunk(&iff.chBODY, &chunk, FALSE, 1)) - return DMERR_FREAD; + if ((res = dmCheckIFFChunk(&iff.chBODY, &chunk, FALSE, 1)) != DMERR_OK) + return res; // Check for sanity if (!iff.chBMHD.count) { - dmError("ILBM: BODY chunk before BMHD?\n"); - return DMERR_INVALID_DATA; + return dmError(DMERR_INVALID_DATA, + "ILBM: BODY chunk before BMHD?\n"); } dmMsg(3, "ILBM: BODY chunk size %d bytes\n", chunk.size); @@ -1588,8 +1616,8 @@ return res; } - if (!dmSkipIFFChunkRest(fp, &chunk, read)) - return DMERR_FREAD; + if ((res = dmSkipIFFChunkRest(fp, &chunk, read)) != DMERR_OK) + return res; if (iff.chCMAP.count) parsed = TRUE; @@ -1599,23 +1627,23 @@ case IFF_ID_CAMG: if (!dm_fread_be32(fp, &iff.camg)) { - dmError("ILBM: Error reading CAMG chunk.\n"); - return DMERR_FREAD; + return dmError(DMERR_FREAD, + "ILBM: Error reading CAMG chunk.\n"); } dmMsg(3, "ILBM: CAMG value 0x%08x\n", iff.camg); if ((iff.camg & IFF_CAMG_HAM)) { - dmError("ILBM: HAM files are not supported.\n"); - return DMERR_NOT_SUPPORTED; + return dmError(DMERR_NOT_SUPPORTED, + "ILBM: HAM files are not supported.\n"); } - if (!dmSkipIFFChunkRest(fp, &chunk, 4)) - return DMERR_FREAD; + if ((res = dmSkipIFFChunkRest(fp, &chunk, sizeof(Uint32))) != DMERR_OK) + return res; break; - + default: { dmMsg(4, "Unknown chunk ID '%s', size %d\n", @@ -1623,8 +1651,8 @@ if (fseeko(fp, chunk.size, SEEK_CUR) != 0) { - dmError("ILBM: Error skipping in file."); - return DMERR_FREAD; + return dmError(DMERR_FSEEK, + "ILBM: Error skipping in file."); } } break; @@ -1644,8 +1672,8 @@ if (iff.ncolors > 128) { - dmError("ILBM: Halfbrite enabled, but ncolors > 128.\n"); - return DMERR_NOT_SUPPORTED; + return dmError(DMERR_NOT_SUPPORTED, + "ILBM: Halfbrite enabled, but ncolors > 128.\n"); } if ((ptmp = dmRealloc(iff.pal, sizeof(DMColor) * iff.ncolors * 2)) == NULL) @@ -1681,8 +1709,9 @@ if ((fp = fopen(filename, "rb")) == NULL) { - dmError("ILBM: Could not open file '%s' for reading.\n", filename); - return DMERR_FOPEN; + return dmError(DMERR_FOPEN, + "ILBM: Could not open file '%s' for reading.\n", + filename); } res = dmReadILBMImageFILE(fp, pimg); diff -r b66653c9acb3 -r 985225a93aeb tests/blittest.c --- a/tests/blittest.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tests/blittest.c Fri Feb 27 03:58:25 2015 +0200 @@ -61,7 +61,7 @@ { if (w < 320 || h < 200 || w > 3200 || h > 3200) { - dmError("Invalid width or height: %d x %d\n", w, h); + dmErrorMsg("Invalid width or height: %d x %d\n", w, h); return FALSE; } optScrWidth = w; @@ -69,7 +69,7 @@ } else { - dmError("Invalid size argument '%s'.\n", optArg); + dmErrorMsg("Invalid size argument '%s'.\n", optArg); return FALSE; } } @@ -80,7 +80,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -115,7 +115,7 @@ *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE); if (*screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } @@ -295,7 +295,7 @@ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); goto error_exit; } initSDL = TRUE; @@ -303,7 +303,7 @@ if (TTF_Init() < 0) { - dmError("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); goto error_exit; } initTTF = TRUE; @@ -311,7 +311,7 @@ font = TTF_OpenFont(optFontFile, optFontSize); if (font == NULL) { - dmError("Could not load TTF font '%s' (%d): %s\n", + dmErrorMsg("Could not load TTF font '%s' (%d): %s\n", optFontFile, optFontSize, SDL_GetError()); goto error_exit; } @@ -322,7 +322,7 @@ screen = SDL_CreateRGBSurface(SDL_SWSURFACE, optScrWidth, optScrHeight, optScrDepth, 0, 0, 0, 0); if (screen == NULL) { - dmError("Could not create screen surface.\n"); + dmErrorMsg("Could not create screen surface.\n"); goto error_exit; } @@ -402,7 +402,7 @@ if (!optBenchmark && SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0) { - dmError("Can't lock surface.\n"); + dmErrorMsg("Can't lock surface.\n"); goto error_exit; } diff -r b66653c9acb3 -r 985225a93aeb tests/efu.c --- a/tests/efu.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tests/efu.c Fri Feb 27 03:58:25 2015 +0200 @@ -64,7 +64,7 @@ { if (w < 320 || h < 200 || w > 3200 || h > 3200) { - dmError("Invalid width or height: %d x %d\n", w, h); + dmErrorMsg("Invalid width or height: %d x %d\n", w, h); return FALSE; } optScrWidth = w; @@ -72,7 +72,7 @@ } else { - dmError("Invalid size argument '%s'.\n", optArg); + dmErrorMsg("Invalid size argument '%s'.\n", optArg); return FALSE; } } @@ -83,7 +83,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -118,7 +118,7 @@ *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE); if (*screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } @@ -293,7 +293,7 @@ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); goto error_exit; } initSDL = TRUE; @@ -301,7 +301,7 @@ if (TTF_Init() < 0) { - dmError("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); goto error_exit; } initTTF = TRUE; @@ -309,7 +309,7 @@ font = TTF_OpenFont(optFontFile, optFontSize); if (font == NULL) { - dmError("Could not load TTF font '%s' (%d): %s\n", + dmErrorMsg("Could not load TTF font '%s' (%d): %s\n", optFontFile, optFontSize, SDL_GetError()); goto error_exit; } @@ -318,14 +318,14 @@ if ((res = dmf_create_stdio(optBitmapFilename, "rb", &file)) != DMERR_OK) { - dmError("Could not open resource file '%s'.\n", optBitmapFilename); + dmErrorMsg("Could not open resource file '%s'.\n", optBitmapFilename); goto error_exit; } logo = dmLoadImage(file); dmf_close(file); if (logo == NULL) { - dmError("Could not load image file '%s'.\n", optBitmapFilename); + dmErrorMsg("Could not load image file '%s'.\n", optBitmapFilename); goto error_exit; } @@ -335,7 +335,7 @@ screen = SDL_CreateRGBSurface(SDL_SWSURFACE, optScrWidth, optScrHeight, optScrDepth, 0, 0, 0, 0); if (screen == NULL) { - dmError("Could not create screen surface.\n"); + dmErrorMsg("Could not create screen surface.\n"); goto error_exit; } @@ -418,7 +418,7 @@ if (!optBenchmark && SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0) { - dmError("Can't lock surface.\n"); + dmErrorMsg("Can't lock surface.\n"); goto error_exit; } diff -r b66653c9acb3 -r 985225a93aeb tests/evaltest.c --- a/tests/evaltest.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tests/evaltest.c Fri Feb 27 03:58:25 2015 +0200 @@ -53,7 +53,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -92,7 +92,7 @@ ret = dmEvalParseExpr(ev, optExpression, &expr); dmMsg(1, "parse ret=%d\n", ret); if (ev->err) - dmError("%s\n", ev->errStr); + dmErrorMsg("%s\n", ev->errStr); if (dmVerbosity > 0) dmEvalPrintOpTree(stdout, ev, expr); diff -r b66653c9acb3 -r 985225a93aeb tools/auval.c --- a/tools/auval.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/auval.c Fri Feb 27 03:58:25 2015 +0200 @@ -99,7 +99,7 @@ { if (w < 320 || h < 200 || w > 3200 || h > 3200) { - dmError("Invalid width or height: %d x %d\n", w, h); + dmErrorMsg("Invalid width or height: %d x %d\n", w, h); return FALSE; } optScrWidth = w; @@ -107,13 +107,13 @@ } else { - dmError("Invalid size argument '%s'.\n", optArg); + dmErrorMsg("Invalid size argument '%s'.\n", optArg); return FALSE; } } else { - dmError("Dimensions option %s requires an argument.\n", currArg); + dmErrorMsg("Dimensions option %s requires an argument.\n", currArg); } break; @@ -126,7 +126,7 @@ int tmp = atoi(optArg); if (tmp < 4000 || tmp > 96000) { - dmError("Invalid audio frequency '%s'.\n", optArg); + dmErrorMsg("Invalid audio frequency '%s'.\n", optArg); return FALSE; } optAudioFreq = tmp; @@ -138,7 +138,7 @@ int tmp = atoi(optArg); if (tmp < 32 || tmp > 512) { - dmError("Invalid bitmap size '%s'.\n", optArg); + dmErrorMsg("Invalid bitmap size '%s'.\n", optArg); return FALSE; } optBMPSize = tmp; @@ -154,7 +154,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -318,7 +318,7 @@ *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, optScrDepth, optVFlags | SDL_RESIZABLE); if (*screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } @@ -485,7 +485,7 @@ FILE *f = fopen(filename, "r"); if (f == NULL) { - dmError("Could not open input file '%s'.\n", filename); + dmErrorMsg("Could not open input file '%s'.\n", filename); return -1; } @@ -522,7 +522,7 @@ FILE *f = fopen(filename, "w"); if (f == NULL) { - dmError("Could not create output file '%s'.\n", filename); + dmErrorMsg("Could not create output file '%s'.\n", filename); return -1; } @@ -629,7 +629,7 @@ histBuf = dmCalloc(sizeof(histBuf[0]), optHistoryLen + 2); if (histBuf == NULL) { - dmError("Could not allocate memory for edit history buffer!\n"); + dmErrorMsg("Could not allocate memory for edit history buffer!\n"); goto error_exit; } @@ -651,14 +651,14 @@ /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); goto error_exit; } initSDL = TRUE; if (TTF_Init() < 0) { - dmError("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); goto error_exit; } initTTF = TRUE; @@ -666,7 +666,7 @@ font = TTF_OpenFont(optFontFile, optFontSize); if (font == NULL) { - dmError("Could not load TTF font '%s' (%d): %s\n", + dmErrorMsg("Could not load TTF font '%s' (%d): %s\n", optFontFile, optFontSize, SDL_GetError()); goto error_exit; } @@ -691,7 +691,7 @@ if (SDL_OpenAudio(&fmt, NULL) < 0) { - dmError("Could not initialize SDL audio.\n"); + dmErrorMsg("Could not initialize SDL audio.\n"); goto error_exit; } @@ -1030,7 +1030,7 @@ { if (SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0) { - dmError("Can't lock surface"); + dmErrorMsg("Can't lock surface"); goto error_exit; } diff -r b66653c9acb3 -r 985225a93aeb tools/data2inc.c --- a/tools/data2inc.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/data2inc.c Fri Feb 27 03:58:25 2015 +0200 @@ -119,7 +119,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -135,7 +135,7 @@ if (!optOutFilename) optOutFilename = currArg; else - dmError("Source and destination filenames already specified, extraneous argument '%s'.\n", currArg); + dmErrorMsg("Source and destination filenames already specified, extraneous argument '%s'.\n", currArg); return TRUE; } @@ -285,7 +285,7 @@ if (optOutFilename == NULL) { - dmError("Output format not specified and no output filename given (try --help)\n"); + dmErrorMsg("Output format not specified and no output filename given (try --help)\n"); exit(1); } @@ -329,7 +329,7 @@ case FMT_AUTO: default: - dmError("Internal error, FMT_AUTO at output function init.\n"); + dmErrorMsg("Internal error, FMT_AUTO at output function init.\n"); exit(2); } @@ -340,7 +340,7 @@ if ((sfile = fopen(optInFilename, "rb")) == NULL) { tmpRes = errno; - dmError("Error opening input file '%s'. (%s)\n", + dmErrorMsg("Error opening input file '%s'. (%s)\n", optInFilename, strerror(tmpRes)); exit(3); } @@ -351,7 +351,7 @@ if ((dfile = fopen(optOutFilename, "wa")) == NULL) { tmpRes = errno; - dmError("Error creating output file '%s'. (%s)\n", + dmErrorMsg("Error creating output file '%s'. (%s)\n", optOutFilename, strerror(tmpRes)); exit(4); } diff -r b66653c9acb3 -r 985225a93aeb tools/dumpmod.c --- a/tools/dumpmod.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/dumpmod.c Fri Feb 27 03:58:25 2015 +0200 @@ -78,7 +78,7 @@ break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -92,7 +92,7 @@ if (!optFilename) optFilename = currArg; else { - dmError("Gay error '%s'!\n", currArg); + dmErrorMsg("Gay error '%s'!\n", currArg); return FALSE; } @@ -403,7 +403,7 @@ if (result != DMERR_OK) { - dmError("Error opening input file '%s', #%d: %s\n", + dmErrorMsg("Error opening input file '%s', #%d: %s\n", optFilename, result, dmErrorStr(result)); return 1; } @@ -425,7 +425,7 @@ dmf_close(file); if (result != DMERR_OK) { - dmError("Error loading module file, %d: %s\n", + dmErrorMsg("Error loading module file, %d: %s\n", result, dmErrorStr(result)); return 3; } diff -r b66653c9acb3 -r 985225a93aeb tools/fontconv.c --- a/tools/fontconv.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/fontconv.c Fri Feb 27 03:58:25 2015 +0200 @@ -64,14 +64,14 @@ int w, h; if (sscanf(optArg, "%d:%d", &w, &h) != 2) { - dmError("Invalid argument for -s option, '%s'.\n", + dmErrorMsg("Invalid argument for -s option, '%s'.\n", optArg); return FALSE; } if (w < DMFONT_MIN_WIDTH || w > DMFONT_MAX_WIDTH || h < DMFONT_MIN_HEIGHT || h > DMFONT_MAX_HEIGHT) { - dmError("Invalid dimensions, must be %d < W %d, %d < H < %d.\n", + dmErrorMsg("Invalid dimensions, must be %d < W %d, %d < H < %d.\n", DMFONT_MIN_WIDTH , DMFONT_MAX_WIDTH, DMFONT_MIN_HEIGHT , DMFONT_MAX_HEIGHT); return FALSE; @@ -91,7 +91,7 @@ if (sscanf(optArg, "%02x%02x%02x", &colR, &colG, &colB) != 3 && sscanf(optArg, "%02x%02x%02x%02x", &colR, &colG, &colB, &colA) != 4) { - dmError("Invalid RGB hex representation '%s'.\n", + dmErrorMsg("Invalid RGB hex representation '%s'.\n", optArg); return FALSE; } @@ -104,7 +104,7 @@ break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -121,7 +121,7 @@ optOutFilename = currArg; else { - dmError("Too many filename arguments, '%s'\n", currArg); + dmErrorMsg("Too many filename arguments, '%s'\n", currArg); return FALSE; } @@ -287,14 +287,14 @@ // Check arguments if (!optInFilename || !optOutFilename) { - dmError("Input or output file not specified!\n"); + dmErrorMsg("Input or output file not specified!\n"); return 1; } #ifdef DM_GFX_TTF_TEXT if (TTF_Init() < 0) { - dmError("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize FreeType/TTF: %s\n", SDL_GetError()); goto error_exit; } initTTF = TRUE; @@ -303,7 +303,7 @@ // Open the source file if ((res = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) { - dmError("Error opening input file '%s', %d: %s\n", + dmErrorMsg("Error opening input file '%s', %d: %s\n", optInFilename, res, dmErrorStr(res)); return 1; } @@ -343,7 +343,7 @@ if ((fontbmap = dmLoadImage(inFile)) == NULL) { - dmError("Could not load image file '%s'.\n", optInFilename); + dmErrorMsg("Could not load image file '%s'.\n", optInFilename); goto error_exit; } @@ -353,7 +353,7 @@ if ((res = dmCreateBitmapFontFromImage(fontbmap, optSplitWidth, optSplitHeight, &font)) != DMERR_OK) { - dmError("Could not create a font from image, %d: %s\n", + dmErrorMsg("Could not create a font from image, %d: %s\n", res, dmErrorStr(res)); goto error_exit; } @@ -361,7 +361,7 @@ if (font == NULL) { - dmError("No font loaded.\n"); + dmErrorMsg("No font loaded.\n"); goto error_exit; } @@ -369,7 +369,7 @@ if ((res = dmf_create_stdio(optOutFilename, "wb", &outFile)) != DMERR_OK) { - dmError("Error creating file '%s', %d: %s\n", + dmErrorMsg("Error creating file '%s', %d: %s\n", optInFilename, res, dmErrorStr(res)); goto error_exit; } @@ -379,7 +379,7 @@ if (res != DMERR_OK) { - dmError("Error saving font, %d: %s\n", + dmErrorMsg("Error saving font, %d: %s\n", res, dmErrorStr(res)); } diff -r b66653c9acb3 -r 985225a93aeb tools/gentab.c --- a/tools/gentab.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/gentab.c Fri Feb 27 03:58:25 2015 +0200 @@ -113,7 +113,7 @@ int tmp; if (sscanf(optArg, "%d", &tmp) != 1) { - dmError("Invalid number of steps argument '%s'.\n", optArg); + dmErrorMsg("Invalid number of steps argument '%s'.\n", optArg); return FALSE; } optNSteps = tmp; @@ -132,7 +132,7 @@ return TRUE; } } - dmError("Invalid transformation type option '%s'.\n", + dmErrorMsg("Invalid transformation type option '%s'.\n", optArg); return FALSE; } @@ -147,7 +147,7 @@ DMFloat tmp; if (sscanf(optArg, "%f", &tmp) != 1) { - dmError("Invalid %s option argument '%s', expected a floating point value.\n", + dmErrorMsg("Invalid %s option argument '%s', expected a floating point value.\n", currArg, optArg); return FALSE; } @@ -163,7 +163,7 @@ break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -188,13 +188,13 @@ // Check settings if (optTransType < 0) { - dmError("No transformation type set, perhaps try --help\n"); + dmErrorMsg("No transformation type set, perhaps try --help\n"); return -1; } if (optObjectName == NULL) { - dmError("Object name not specified, try --help\n"); + dmErrorMsg("Object name not specified, try --help\n"); return -2; } @@ -204,7 +204,7 @@ if ((outFile = fopen(optOutFilename, "w")) == NULL) { int err = dmGetErrno(); - dmError("Could not open output file '%s', %d: %s\n", + dmErrorMsg("Could not open output file '%s', %d: %s\n", optOutFilename, err, dmErrorStr(err)); return -2; } diff -r b66653c9acb3 -r 985225a93aeb tools/gfxconv.c --- a/tools/gfxconv.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/gfxconv.c Fri Feb 27 03:58:25 2015 +0200 @@ -320,7 +320,7 @@ if ((end = split = strchr(opt, ':')) == NULL) { - dmError("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt); + dmErrorMsg("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt); goto error; } @@ -344,7 +344,7 @@ if (sscanf(opt + 1, "%2x%2x%2x", &colR, &colG, &colB) != 3 && sscanf(opt + 1, "%2X%2X%2X", &colR, &colG, &colB) != 3) { - dmError("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1); + dmErrorMsg("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1); goto error; } @@ -357,7 +357,7 @@ { if (!dmGetIntVal(opt, &value->from)) { - dmError("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); + dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); goto error; } value->triplet = FALSE; @@ -370,19 +370,19 @@ // Parse destination value if (!dmGetIntVal(split, &value->to)) { - dmError("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); + dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); goto error; } if (!value->triplet && value->from > 255) { - dmError("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from); + dmErrorMsg("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from); goto error; } if (value->to > nmax) { - dmError("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax); + dmErrorMsg("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax); goto error; } @@ -419,13 +419,13 @@ char *split = strchr(opt, ':'); if (split != NULL) { - dmError("Unexpected ':' in indexed %s '%s'.\n", msg, opt); + dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt); return FALSE; } if (!dmGetIntVal(opt, &value[index])) { - dmError("Invalid %s value '%s', could not parse.\n", msg, opt); + dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); return FALSE; } } @@ -467,7 +467,7 @@ if ((fp = fopen(filename, "r")) == NULL) { res = dmGetErrno(); - dmError("Could not open color remap file '%s' for reading, %d: %s\n", + dmErrorMsg("Could not open color remap file '%s' for reading, %d: %s\n", res, dmErrorStr(res)); return res; } @@ -486,7 +486,7 @@ (*nvalue)++; if (*nvalue >= nmax) { - dmError("Too many mapping pairs in '%s', maximum is %d.\n", + dmErrorMsg("Too many mapping pairs in '%s', maximum is %d.\n", filename, nmax); goto error; } @@ -527,7 +527,7 @@ case 'b': optInFormat = FFMT_BITMAP; break; case 'i': optInFormat = FFMT_IMAGE; break; default: - dmError("Invalid input format '%s'.\n", optArg); + dmErrorMsg("Invalid input format '%s'.\n", optArg); return FALSE; } @@ -546,7 +546,7 @@ optInMulticolor = FALSE; else { - dmError("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n", + dmErrorMsg("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n", tmp); return FALSE; } @@ -555,7 +555,7 @@ case FFMT_BITMAP: if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat)) { - dmError("Invalid bitmap subformat '%s', see format list for valid bformats.\n", + dmErrorMsg("Invalid bitmap subformat '%s', see format list for valid bformats.\n", tmp); return FALSE; } @@ -576,7 +576,7 @@ case 4: if (!dmGetIntVal(optArg, &optInSkip)) { - dmError("Invalid skip value argument '%s'.\n", optArg); + dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); return FALSE; } break; @@ -585,7 +585,7 @@ if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) && !dmGetC64FormatByExt(optArg, &optOutFormat, &optOutSubFormat)) { - dmError("Invalid output format '%s'.\n", optArg); + dmErrorMsg("Invalid output format '%s'.\n", optArg); return FALSE; } break; @@ -611,7 +611,7 @@ case 7: if (sscanf(optArg, "%d", &optItemCount) != 1) { - dmError("Invalid count value argument '%s'.\n", optArg); + dmErrorMsg("Invalid count value argument '%s'.\n", optArg); return FALSE; } break; @@ -627,18 +627,18 @@ optSpec.scaleY = optSpec.scaleX; else { - dmError("Invalid scale option value '%s', should be or :.\n", optArg); + dmErrorMsg("Invalid scale option value '%s', should be or :.\n", optArg); return FALSE; } } if (optSpec.scaleX < 1 || optSpec.scaleX > 50) { - dmError("Invalid X scale value '%d'.\n", optSpec.scaleX); + dmErrorMsg("Invalid X scale value '%d'.\n", optSpec.scaleX); return FALSE; } if (optSpec.scaleY < 1 || optSpec.scaleY > 50) { - dmError("Invalid Y scale value '%d'.\n", optSpec.scaleY); + dmErrorMsg("Invalid Y scale value '%d'.\n", optSpec.scaleY); return FALSE; } break; @@ -646,12 +646,12 @@ case 11: if (sscanf(optArg, "%d", &optPlanedWidth) != 1) { - dmError("Invalid planed width value argument '%s'.\n", optArg); + dmErrorMsg("Invalid planed width value argument '%s'.\n", optArg); return FALSE; } if (optPlanedWidth < 1 || optPlanedWidth > 512) { - dmError("Invalid planed width value '%d' [1..512].\n", optPlanedWidth); + dmErrorMsg("Invalid planed width value '%d' [1..512].\n", optPlanedWidth); return FALSE; } break; @@ -665,7 +665,7 @@ int tmp = atoi(optArg); if (tmp < 1 || tmp > 8) { - dmError("Invalid bitplanes/bpp value '%s'.\n", optArg); + dmErrorMsg("Invalid bitplanes/bpp value '%s'.\n", optArg); return FALSE; } optSpec.nplanes = tmp; @@ -696,7 +696,7 @@ } else { - dmError("No remap filename given.\n"); + dmErrorMsg("No remap filename given.\n"); return FALSE; } } @@ -738,14 +738,14 @@ } else { - dmError("Invalid crop mode / argument '%s'.\n", optArg); + dmErrorMsg("Invalid crop mode / argument '%s'.\n", optArg); return FALSE; } } break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -759,7 +759,7 @@ optInFilename = currArg; else { - dmError("Source filename already specified, extraneous argument '%s'.\n", + dmErrorMsg("Source filename already specified, extraneous argument '%s'.\n", currArg); return FALSE; } @@ -865,7 +865,7 @@ if (npal == NULL || mapping == NULL || mapped == NULL || used == NULL) { - dmError("Could not allocate memory for reused palette.\n"); + dmErrorMsg("Could not allocate memory for reused palette.\n"); return DMERR_MALLOC; } @@ -1040,7 +1040,7 @@ if ((outFile = fopen(filename, "wb")) == NULL) { res = dmGetErrno(); - dmError("Error opening output file '%s', %d: %s\n", + dmErrorMsg("Error opening output file '%s', %d: %s\n", filename, res, dmErrorStr(res)); goto error; } @@ -1048,7 +1048,7 @@ if (!dm_fwrite_str(outFile, buf, bufSize)) { res = dmGetErrno(); - dmError("Error writing image data to '%s', %d: %s\n", + dmErrorMsg("Error writing image data to '%s', %d: %s\n", filename, res, dmErrorStr(res)); } @@ -1110,7 +1110,7 @@ // Open data file for writing if ((fp = fopen(dataFilename, "w")) == NULL) - dmError("Could not create '%s'.\n", dataFilename); + dmErrorMsg("Could not create '%s'.\n", dataFilename); dmFree(dataFilename); @@ -1271,14 +1271,14 @@ default: ret = DMERR_INVALID_ARGS; - dmError("Invalid output format %d, internal error.\n", outFormat); + dmErrorMsg("Invalid output format %d, internal error.\n", outFormat); goto error; } if (outBlockW < 1 || outBlockH < 1) { ret = DMERR_INVALID_ARGS; - dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n", + dmErrorMsg("Source image dimensions too small for conversion, block dimensions %d x %d.\n", outBlockW, outBlockH); goto error; } @@ -1286,14 +1286,14 @@ if ((outFile = fopen(filename, "wb")) == NULL) { ret = dmGetErrno(); - dmError("Could not open '%s' for writing, %d: %s.\n", + dmErrorMsg("Could not open '%s' for writing, %d: %s.\n", filename, ret, dmErrorStr(ret)); goto error; } if ((buf = dmMalloc(outBufSize)) == NULL) { - dmError("Could not allocate %d bytes for conversion buffer.\n", + dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n", outBufSize); goto error; } @@ -1330,7 +1330,7 @@ if (!dm_fwrite_str(outFile, buf, outBufSize)) { ret = dmGetErrno(); - dmError("Error writing data block %d,%d to '%s', %d: %s\n", + dmErrorMsg("Error writing data block %d,%d to '%s', %d: %s\n", bx, by, filename, ret, dmErrorStr(ret)); goto error; } @@ -1371,13 +1371,13 @@ break; default: - dmError("Invalid input format %d, internal error.\n", optInFormat); + dmErrorMsg("Invalid input format %d, internal error.\n", optInFormat); return -1; } if ((bufData = dmMalloc(bufSize)) == NULL) { - dmError("Could not allocate temporary buffer of %d bytes.\n", bufSize); + dmErrorMsg("Could not allocate temporary buffer of %d bytes.\n", bufSize); return -2; } @@ -1396,7 +1396,7 @@ if ((outFile = fopen(optOutFilename, "w")) == NULL) { int res = dmGetErrno(); - dmError("Error opening output file '%s', %d: %s\n", + dmErrorMsg("Error opening output file '%s', %d: %s\n", optOutFilename, res, dmErrorStr(res)); goto error; } @@ -1407,7 +1407,7 @@ if (fread(bufData, 1, bufSize, inFile) != bufSize) { - dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n", + dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n", bufSize, dataOffs); error = TRUE; } @@ -1439,7 +1439,7 @@ { if (optOutFilename == NULL) { - dmError("Sequential image output requires filename template.\n"); + dmErrorMsg("Sequential image output requires filename template.\n"); goto error; } @@ -1454,7 +1454,7 @@ int outIWidth, outIHeight; if (optItemCount <= 0) { - dmError("Single-image output requires count to be set (-n).\n"); + dmErrorMsg("Single-image output requires count to be set (-n).\n"); goto error; } @@ -1477,7 +1477,7 @@ if (fread(bufData, 1, bufSize, inFile) != bufSize) { - dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n", + dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n", bufSize, dataOffs); break; } @@ -1485,7 +1485,7 @@ if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight, bufData, outWidth, outHeight, optInMulticolor, optColors)) != DMERR_OK) { - dmError("Internal error in conversion of raw data to bitmap: %d.\n", err); + dmErrorMsg("Internal error in conversion of raw data to bitmap: %d.\n", err); break; } @@ -1496,14 +1496,14 @@ outFilename = dm_strdup_printf("%s%04d.%s", optOutFilename, itemCount, convFormatList[optOutFormat].fext); if (outFilename == NULL) { - dmError("Could not allocate memory for filename template?\n"); + dmErrorMsg("Could not allocate memory for filename template?\n"); goto error; } eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); if (eres != DMERR_OK) { - dmError("Error writing output image, %s.\n", + dmErrorMsg("Error writing output image, %s.\n", dmErrorStr(eres)); } @@ -1526,7 +1526,7 @@ int eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); if (eres != DMERR_OK) { - dmError("Error writing output image, %s.\n", + dmErrorMsg("Error writing output image, %s.\n", dmErrorStr(eres)); } } @@ -1538,7 +1538,7 @@ { if (optSequential) { - dmError("Sequential output not supported for spr/char -> bitmap conversion.\n"); + dmErrorMsg("Sequential output not supported for spr/char -> bitmap conversion.\n"); goto error; } } @@ -1575,7 +1575,7 @@ #ifndef DM_USE_LIBPNG if (optOutFormat == IMGFMT_PNG) { - dmError("PNG output format support not compiled in, sorry.\n"); + dmErrorMsg("PNG output format support not compiled in, sorry.\n"); goto error; } #endif @@ -1596,8 +1596,8 @@ { if (optInFormat == FFMT_AUTO) { - dmError("Standard input cannot be used without specifying input format.\n"); - dmError("Perhaps you should try using --help\n"); + dmErrorMsg("Standard input cannot be used without specifying input format.\n"); + dmErrorMsg("Perhaps you should try using --help\n"); goto error; } inFile = stdin; @@ -1606,7 +1606,7 @@ if ((inFile = fopen(optInFilename, "rb")) == NULL) { int res = dmGetErrno(); - dmError("Error opening input file '%s', %d: %s\n", + dmErrorMsg("Error opening input file '%s', %d: %s\n", optInFilename, res, dmErrorStr(res)); goto error; } @@ -1638,7 +1638,7 @@ optInFormat = FFMT_BITMAP; else { - dmError("Could not decode input image.\n"); + dmErrorMsg("Could not decode input image.\n"); exit(3); } } @@ -1658,7 +1658,7 @@ if (optInFormat == FFMT_AUTO) { - dmError("No input format specified, and could not be determined automatically.\n"); + dmErrorMsg("No input format specified, and could not be determined automatically.\n"); exit(1); } @@ -1666,7 +1666,7 @@ if (fseek(inFile, optInSkip, SEEK_SET) != 0) { int res = dmGetErrno(); - dmError("Could not seek to file position %d (0x%x): %s\n", + dmErrorMsg("Could not seek to file position %d (0x%x): %s\n", optInSkip, optInSkip, dmErrorStr(res)); goto error; } @@ -1702,7 +1702,7 @@ if (optOutFilename == NULL) { - dmError("Output filename not set, required for bitmap formats.\n"); + dmErrorMsg("Output filename not set, required for bitmap formats.\n"); goto error; } @@ -1713,7 +1713,7 @@ if (res != DMERR_OK || outImage == NULL) { - dmError("Error in bitmap to image conversion.\n"); + dmErrorMsg("Error in bitmap to image conversion.\n"); goto error; } @@ -1731,7 +1731,7 @@ if (res != DMERR_OK || outImage == NULL) { - dmError("Error in bitmap to template image conversion.\n"); + dmErrorMsg("Error in bitmap to template image conversion.\n"); goto error; } @@ -1739,7 +1739,7 @@ break; default: - dmError("Unsupported output format for bitmap/image conversion.\n"); + dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); break; } @@ -1754,7 +1754,7 @@ if (optOutFilename == NULL) { - dmError("Output filename not set, required for image formats.\n"); + dmErrorMsg("Output filename not set, required for image formats.\n"); goto error; } @@ -1763,7 +1763,7 @@ if (ifmt->readFILE != NULL) res = ifmt->readFILE(inFile, &outImage); else - dmError("Unsupported input image format for bitmap/image conversion.\n"); + dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); if (res != DMERR_OK || outImage == NULL) break; @@ -1780,13 +1780,13 @@ break; default: - dmError("Unsupported output format for bitmap/image conversion.\n"); + dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); break; } if (res != DMERR_OK) { - dmError("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", + dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", dmErrorStr(res)); } diff -r b66653c9acb3 -r 985225a93aeb tools/lib64gfx.c --- a/tools/lib64gfx.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/lib64gfx.c Fri Feb 27 03:58:25 2015 +0200 @@ -668,16 +668,16 @@ { if (op->bank < 0 || op->bank >= C64_SCR_MAX_BANK) { - dmError("Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n", + return dmError(DMERR_INTERNAL, + "Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n", op->bank, op->type, i); - return DMERR_INTERNAL; } if (op->type < 0 || op->type >= DT_LAST) { - dmError("Invalid encode/decode operator type %d @ #%d.\n", + return dmError(DMERR_INTERNAL, + "Invalid encode/decode operator type %d @ #%d.\n", op->type, i); - return DMERR_INTERNAL; } return DMERR_OK; @@ -742,8 +742,8 @@ if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS) { - dmError("Invalid number of enc/dec ops in format. Internal error.\n"); - return DMERR_INTERNAL; + return dmError(DMERR_INTERNAL, + "Invalid number of enc/dec ops in format. Internal error.\n"); } // Clear the image structure, set basics @@ -768,19 +768,19 @@ // Check size if (!dmC64GetOpSize(op, fmt, &size)) { - dmError("Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " + return dmError(DMERR_INVALID_DATA, + "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n", i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size); - return DMERR_INVALID_DATA; } // Do we need to reallocate some more space? if (op->offs + size > len) { - dmError("Decode out of bounds, op #%d type=%d, offs=%d ($%04x), " + return dmError(DMERR_INVALID_DATA, + "Decode out of bounds, op #%d type=%d, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->type, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INVALID_DATA; } src = buf + op->offs; @@ -804,10 +804,10 @@ case DC_D023: img->d023 = *src; break; case DC_D024: img->d024 = *src; break; default: - dmError("Unhandled DT_COLOR_REG mode %d in ", - "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - op->size, i, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INTERNAL; + return dmError(DMERR_INTERNAL, + "Unhandled DT_COLOR_REG mode %d in ", + "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", + op->size, i, op->offs, op->offs, op->bank, size, size, len, len); } break; @@ -821,10 +821,10 @@ case DC_D023: img->d023 = op->offs; break; case DC_D024: img->d024 = op->offs; break; default: - dmError("Unhandled DT_COLOR_SET mode %d in ", - "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - op->size, i, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INTERNAL; + return dmError(DMERR_INTERNAL, + "Unhandled DT_COLOR_SET mode %d in ", + "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", + op->size, i, op->offs, op->offs, op->bank, size, size, len, len); } break; @@ -844,27 +844,27 @@ break; default: - dmError("Unhandled DT_CHAR_CONFIG mode %d in ", - "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - op->offs, i, op->bank, size, size, len, len); - return DMERR_INTERNAL; + return dmError(DMERR_INTERNAL, + "Unhandled DT_CHAR_CONFIG mode %d in ", + "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n", + op->offs, i, op->bank, size, size, len, len); } break; case DT_DEC_FUNCTION: if (op->decfunction == NULL) { - dmError("Decode op is a function, but function ptr is NULL: " + return dmError(DMERR_INTERNAL, + "Decode op is a function, but function ptr is NULL: " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INTERNAL; } if (!op->decfunction(img, op, buf, len)) { - dmError("Decode op custom function failed: op #%d, " + return dmError(DMERR_INTERNAL, + "Decode op custom function failed: op #%d, " "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INTERNAL; } break; } @@ -885,8 +885,8 @@ if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS) { - dmError("Invalid number of enc/dec ops in format. Internal error.\n"); - return DMERR_INTERNAL; + return dmError(DMERR_INTERNAL, + "Invalid number of enc/dec ops in format. Internal error.\n"); } // Allocate the output buffer @@ -898,9 +898,9 @@ if ((buf = dmMalloc(allocated)) == NULL) { - dmError("Could not allocate %d bytes of memory for C64 image encoding buffer.\n", + return dmError(DMERR_MALLOC, + "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", allocated); - res = DMERR_MALLOC; goto error; } @@ -918,10 +918,11 @@ // Check size if (!dmC64GetOpSize(op, fmt, &size)) { - dmError("Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " + res = dmError(DMERR_INVALID_DATA, + "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n", i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size); - return DMERR_INVALID_DATA; + goto error; } // Do we need to reallocate some more space? @@ -934,9 +935,9 @@ if ((buf = dmRealloc(buf, allocated)) == NULL) { - dmError("Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", + res = dmError(DMERR_MALLOC, + "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", allocated); - res = DMERR_MALLOC; goto error; } } @@ -963,28 +964,31 @@ case DC_D023: *dst = img->d023; break; case DC_D024: *dst = img->d024; break; default: - dmError("Unhandled DT_COLOR_REG mode %d in ", - "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen); - return DMERR_INTERNAL; + res = dmError(DMERR_INTERNAL, + "Unhandled DT_COLOR_REG mode %d in ", + "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", + op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen); + goto error; } break; case DT_ENC_FUNCTION: if (op->encfunction == NULL) { - dmError("Encode op is a function, but function ptr is NULL: " + res = dmError(DMERR_INTERNAL, + "Encode op is a function, but function ptr is NULL: " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->offs, op->offs, op->bank, size, size, *plen, *plen); - return DMERR_INTERNAL; + goto error; } /* if (!op->encfunction(op, buf, len)) { - dmError("Encode op custom function failed: op #%d, " + res = dmError(DMERR_INTERNAL, + "Encode op custom function failed: op #%d, " "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->offs, op->offs, op->bank, size, size, len, len); - return DMERR_INTERNAL; + goto out; } */ break; diff -r b66653c9acb3 -r 985225a93aeb tools/mod2wav.c --- a/tools/mod2wav.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/mod2wav.c Fri Feb 27 03:58:25 2015 +0200 @@ -98,7 +98,7 @@ break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -115,7 +115,7 @@ optOutFilename = currArg; else { - dmError("Too many filename arguments (only source and dest needed) '%s'\n", currArg); + dmErrorMsg("Too many filename arguments (only source and dest needed) '%s'\n", currArg); return FALSE; } @@ -145,7 +145,7 @@ // Check arguments if (optInFilename == NULL || optOutFilename == NULL) { - dmError("Input or output file not specified. Try --help.\n"); + dmErrorMsg("Input or output file not specified. Try --help.\n"); return 1; } @@ -155,7 +155,7 @@ // Open the source file if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) { - dmError("Error opening input file '%s', %d: %s\n", + dmErrorMsg("Error opening input file '%s', %d: %s\n", optInFilename, result, dmErrorStr(result)); return 1; } @@ -177,7 +177,7 @@ dmf_close(inFile); if (result != DMERR_OK) { - dmError("Error loading module file, %d: %s\n", + dmErrorMsg("Error loading module file, %d: %s\n", result, dmErrorStr(result)); return 3; } @@ -185,7 +185,7 @@ // Try to convert it if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK) { - dmError("Could not convert module for playing, %d: %s\n", + dmErrorMsg("Could not convert module for playing, %d: %s\n", result, dmErrorStr(result)); return 3; } @@ -194,14 +194,14 @@ dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); if (dev == NULL) { - dmError("jvmInit() returned NULL\n"); + dmErrorMsg("jvmInit() returned NULL\n"); return 4; } sampSize = jvmGetSampleSize(dev); if ((mb = dmMalloc(bufLen * sampSize)) == NULL) { - dmError("Could not allocate mixing buffer\n"); + dmErrorMsg("Could not allocate mixing buffer\n"); return 5; } @@ -212,7 +212,7 @@ // Initialize player if ((plr = jmpInit(dev)) == NULL) { - dmError("jmpInit() returned NULL.\n"); + dmErrorMsg("jmpInit() returned NULL.\n"); return 6; } @@ -241,7 +241,7 @@ // Open output file if ((outFile = fopen(optOutFilename, "wb")) == NULL) { - dmError("Error opening output file '%s'. (%s)\n", + dmErrorMsg("Error opening output file '%s'. (%s)\n", optInFilename, strerror(errno)); return 7; } @@ -273,7 +273,7 @@ dataWritten = fwrite(mb, sampSize, writeLen, outFile); if (dataWritten < writeLen) { - dmError("Error writing data!\n"); + dmErrorMsg("Error writing data!\n"); fclose(outFile); return 8; } @@ -287,7 +287,7 @@ // Write the correct header if (fseek(outFile, 0L, SEEK_SET) != 0) { - dmError("Error rewinding to header position!\n"); + dmErrorMsg("Error rewinding to header position!\n"); return 9; } diff -r b66653c9acb3 -r 985225a93aeb tools/objlink.c --- a/tools/objlink.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/objlink.c Fri Feb 27 03:58:25 2015 +0200 @@ -207,7 +207,7 @@ { if (startAddr > endAddr) { - dmError("ERROR! Block '%s' has startAddr=$%.4x > endAddr=$%.4x!\n", + dmErrorMsg("ERROR! Block '%s' has startAddr=$%.4x > endAddr=$%.4x!\n", blockName, startAddr, endAddr); exit(4); } @@ -222,7 +222,7 @@ } else { - dmError("Maximum number of memBlock definitions (%d) exceeded!\n", + dmErrorMsg("Maximum number of memBlock definitions (%d) exceeded!\n", MAX_FILENAMES); exit(4); } @@ -245,7 +245,7 @@ // Create a copy of the argument if ((str = dm_strdup(arg)) == NULL) { - dmError("Could not allocate temporary string!\n"); + dmErrorMsg("Could not allocate temporary string!\n"); exit(128); } @@ -253,7 +253,7 @@ if ((sep = strchr(str, '-')) == NULL && (sep = strchr(str, ':')) == NULL) { - dmError("Section definition '%s' invalid.\n", arg); + dmErrorMsg("Section definition '%s' invalid.\n", arg); goto error; } sectMode = *sep; @@ -262,7 +262,7 @@ // Get value if (!dmGetIntVal(str, sectStart)) { - dmError("Section start address '%s' in '%s' invalid.\n", str, arg); + dmErrorMsg("Section start address '%s' in '%s' invalid.\n", str, arg); goto error; } @@ -274,7 +274,7 @@ namesep++; if (*namesep == 0) { - dmError("Section definition '%s' name is empty. Either specify name or leave it out.\n", + dmErrorMsg("Section definition '%s' name is empty. Either specify name or leave it out.\n", arg); goto error; } @@ -283,7 +283,7 @@ else if (namesep != NULL) { - dmError("Section definition does not allow a name, syntax error in '%s' at '%s'.\n", + dmErrorMsg("Section definition does not allow a name, syntax error in '%s' at '%s'.\n", arg, namesep); goto error; } @@ -291,7 +291,7 @@ // Get end address or length if (!dmGetIntVal(sep + 1, &tmpi)) { - dmError("Section %s '%s' in '%s' invalid.\n", + dmErrorMsg("Section %s '%s' in '%s' invalid.\n", sectMode == '-' ? "end address" : "length", sep + 1, arg); goto error; @@ -305,7 +305,7 @@ { if (tmpi < *sectStart) { - dmError("Section start address > end address in '%s'.\n", + dmErrorMsg("Section start address > end address in '%s'.\n", arg); goto error; } @@ -332,7 +332,7 @@ *sep = 0; if (!dmGetIntVal(sep + 1, &tmpi)) { - dmError("Invalid %s address '%s' specified for '%s'.\n", + dmErrorMsg("Invalid %s address '%s' specified for '%s'.\n", desc, sep + 1, arg); return FALSE; } @@ -341,7 +341,7 @@ else if (requireAddr) { - dmError("No %s loading address specified for '%s'.\n", desc, arg); + dmErrorMsg("No %s loading address specified for '%s'.\n", desc, arg); return FALSE; } @@ -384,7 +384,7 @@ case 6: // Allow overlapping segments optAllowOverlap = TRUE; - dmError("Warning, allowing overlapping data.\n"); + dmErrorMsg("Warning, allowing overlapping data.\n"); break; case 7: @@ -392,7 +392,7 @@ optMemModel = atoi(optArg); if (optMemModel < 0 || optMemModel >= nmemoryModels) { - dmError("Invalid memory model number %i!\n", optMemModel); + dmErrorMsg("Invalid memory model number %i!\n", optMemModel); return FALSE; } break; @@ -417,7 +417,7 @@ break; default: - dmError("Invalid/unknown linker file format '%s'!\n", + dmErrorMsg("Invalid/unknown linker file format '%s'!\n", optArg); return FALSE; } @@ -435,14 +435,14 @@ case 'w': optInitValueType = 2; break; case 'd': optInitValueType = 4; break; default: - dmError("Invalid init value type '%c' specified for '%s'.\n", + dmErrorMsg("Invalid init value type '%c' specified for '%s'.\n", p[1], optArg); return FALSE; } } if (!dmGetIntVal(optArg, &tmpi)) { - dmError("Invalid initvalue '%s'.\n", optArg); + dmErrorMsg("Invalid initvalue '%s'.\n", optArg); return FALSE; } optInitValue = tmpi; @@ -491,12 +491,12 @@ { if (!dmGetIntVal(optArg, &tmpi)) { - dmError("Invalid loading address '%s'.\n", optArg); + dmErrorMsg("Invalid loading address '%s'.\n", optArg); return FALSE; } if (tmpi >= 64*1024) { - dmError("Invalid or insane loading address %d/$%x!\n", + dmErrorMsg("Invalid or insane loading address %d/$%x!\n", tmpi); return FALSE; } @@ -505,7 +505,7 @@ break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -522,7 +522,7 @@ // Open the input file if ((f = fopen(filename, "rb")) == NULL) { - dmError("Error opening input file '%s' (%s).\n", + dmErrorMsg("Error opening input file '%s' (%s).\n", filename, strerror(errno)); return 1; } @@ -530,14 +530,14 @@ // Get filesize if ((dataSize = dmGetFileSize(f) - 2) < 0) { - dmError("Error getting file size for '%s'.\n", filename); + dmErrorMsg("Error getting file size for '%s'.\n", filename); return 6; } // Get loading address if (!dm_fread_le16(f, &tmpAddr)) { - dmError("Error reading input file '%s' (%s).\n", + dmErrorMsg("Error reading input file '%s' (%s).\n", filename, strerror(errno)); return 2; } @@ -580,7 +580,7 @@ // Open the input file if ((f = fopen(filename, "rb")) == NULL) { - dmError("Error opening input file '%s' (%s).\n", + dmErrorMsg("Error opening input file '%s' (%s).\n", filename, strerror(errno)); return 1; } @@ -588,7 +588,7 @@ // Get filesize if ((dataSize = dmGetFileSize(f)) < 0) { - dmError("Error getting file size for '%s'.\n", filename); + dmErrorMsg("Error getting file size for '%s'.\n", filename); return 6; } @@ -631,7 +631,7 @@ tmpStr = dm_strdup(blockName); if (tmpStr == NULL) { - dmError("Could not allocate memory for string '%s'!\n", + dmErrorMsg("Could not allocate memory for string '%s'!\n", blockName); return -1; } @@ -775,7 +775,7 @@ if (nsrcFiles < 1) { - dmError("Nothing to do. (try --help)\n"); + dmErrorMsg("Nothing to do. (try --help)\n"); exit(0); } @@ -787,7 +787,7 @@ memory = (Uint8 *) dmMalloc(memModel->size + 32); if (memory == NULL) { - dmError("Could not allocate memory.\n"); + dmErrorMsg("Could not allocate memory.\n"); exit(2); } @@ -872,7 +872,7 @@ if (!optAllowOverlap && hasOverlaps) { - dmError("Error occured, overlaps not allowed.\n"); + dmErrorMsg("Error occured, overlaps not allowed.\n"); exit(5); } @@ -896,7 +896,7 @@ if (startAddr >= memModel->size || endAddr < startAddr) { - dmError("Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", startAddr, endAddr); + dmErrorMsg("Invalid saveblock addresses (start=$%.4x, end=$%.4x)!\n", startAddr, endAddr); exit(8); } @@ -906,7 +906,7 @@ dmMsg(1, "Writing linkfile to '%s'\n", optLinkFileName); if ((dfile = fopen(optLinkFileName, "wb")) == NULL) { - dmError("Error creating file '%s' (%s).\n", optLinkFileName, strerror(errno)); + dmErrorMsg("Error creating file '%s' (%s).\n", optLinkFileName, strerror(errno)); exit(1); } @@ -955,7 +955,7 @@ } else if ((dfile = fopen(optDestName, "wb")) == NULL) { - dmError("Error creating output file '%s' (%s).\n", optDestName, strerror(errno)); + dmErrorMsg("Error creating output file '%s' (%s).\n", optDestName, strerror(errno)); exit(1); } else @@ -981,7 +981,7 @@ // Save the data if (fwrite(&memory[startAddr], dataSize, 1, dfile) < 1) { - dmError("Error writing to file (%s)\n", strerror(errno)); + dmErrorMsg("Error writing to file (%s)\n", strerror(errno)); } fclose(dfile); diff -r b66653c9acb3 -r 985225a93aeb tools/packed.c --- a/tools/packed.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/packed.c Fri Feb 27 03:58:25 2015 +0200 @@ -110,7 +110,7 @@ unsigned int i; if (!dmGetIntVal(optArg, &i)) { - dmError("Invalid flags value '%s'.\n", optArg); + dmErrorMsg("Invalid flags value '%s'.\n", optArg); return FALSE; } optDefResFlags = i; @@ -125,14 +125,14 @@ } else { - dmError("Maximum number of exclusion patterns (%d) exceeded!\n", + dmErrorMsg("Maximum number of exclusion patterns (%d) exceeded!\n", SET_MAX_FILES); return FALSE; } break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -149,7 +149,7 @@ } else { - dmError("Maximum number of input files (%d) exceeded!\n", + dmErrorMsg("Maximum number of input files (%d) exceeded!\n", SET_MAX_FILES); return FALSE; } @@ -600,7 +600,7 @@ if (optCommand == CMD_NONE) { argShowHelp(); - dmError("Nothing to do.\n"); + dmErrorMsg("Nothing to do.\n"); exit(0); return 0; } @@ -654,7 +654,7 @@ } else { - dmError("Could not open packfile, error #%d: %s\n", res, + dmErrorMsg("Could not open packfile, error #%d: %s\n", res, dmErrorStr(res)); } break; @@ -699,7 +699,7 @@ dmMsg(1, "c=%d\n", dmPackClose(pack)); } else - dmError("Could not open packfile, error #%d: %s\n", res, + dmErrorMsg("Could not open packfile, error #%d: %s\n", res, dmErrorStr(res)); break; @@ -713,7 +713,7 @@ if (resFile == NULL) { int err = dmGetErrno(); - dmError("Could not create resource output file '%s' #%d: %s\n", + dmErrorMsg("Could not create resource output file '%s' #%d: %s\n", DMRES_RES_FILE, err, dmErrorStr(err)); } @@ -753,7 +753,7 @@ fclose(resFile); } else - dmError("Could not open packfile, error #%d: %s\n", res, + dmErrorMsg("Could not open packfile, error #%d: %s\n", res, dmErrorStr(res)); break; diff -r b66653c9acb3 -r 985225a93aeb tools/ppl.c --- a/tools/ppl.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/ppl.c Fri Feb 27 03:58:25 2015 +0200 @@ -105,7 +105,7 @@ { if (w < 320 || h < 200 || w > 3200 || h > 3200) { - dmError("Invalid width or height: %d x %d\n", w, h); + dmErrorMsg("Invalid width or height: %d x %d\n", w, h); return FALSE; } engine.optScrWidth = w; @@ -113,7 +113,7 @@ } else { - dmError("Invalid size argument '%s'.\n", optArg); + dmErrorMsg("Invalid size argument '%s'.\n", optArg); return FALSE; } } @@ -153,7 +153,7 @@ break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -167,7 +167,7 @@ optFilename = currArg; else { - dmError("Too many filename arguments '%s'\n", currArg); + dmErrorMsg("Too many filename arguments '%s'\n", currArg); return FALSE; } @@ -239,7 +239,7 @@ if (engine.screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } @@ -577,13 +577,13 @@ // Open the files if (optFilename == NULL) { - dmError("No filename specified.\n"); + dmErrorMsg("No filename specified.\n"); return 1; } if ((result = dmf_create_stdio(optFilename, "rb", &file)) != DMERR_OK) { - dmError("Error opening file '%s', %d: (%s)\n", + dmErrorMsg("Error opening file '%s', %d: (%s)\n", optFilename, result, dmErrorStr(result)); return 1; } @@ -609,7 +609,7 @@ if (result != DMERR_OK) { - dmError("Error loading module file, %d: %s\n", + dmErrorMsg("Error loading module file, %d: %s\n", result, dmErrorStr(result)); goto error_exit; } @@ -617,7 +617,7 @@ // Try to convert it if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK) { - dmError("Could not convert module for playing, %d: %s\n", + dmErrorMsg("Could not convert module for playing, %d: %s\n", result, dmErrorStr(result)); goto error_exit; } @@ -626,7 +626,7 @@ result = dmf_create_memio(NULL, "pplfont.fnt", engineSetupFont, sizeof(engineSetupFont), &file); if (result != DMERR_OK) { - dmError("Error opening font file 'pplfont.fnt', #%d: %s\n", + dmErrorMsg("Error opening font file 'pplfont.fnt', #%d: %s\n", result, dmErrorStr(result)); goto error_exit; } @@ -634,7 +634,7 @@ dmf_close(file); if (result != DMERR_OK) { - dmError("Could not load font from file, %d: %s\n", + dmErrorMsg("Could not load font from file, %d: %s\n", result, dmErrorStr(result)); goto error_exit; } @@ -642,7 +642,7 @@ // Initialize SDL components if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); goto error_exit; } initSDL = TRUE; @@ -655,7 +655,7 @@ engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO); if (engine.dev == NULL) { - dmError("jvmInit() returned NULL\n"); + dmErrorMsg("jvmInit() returned NULL\n"); goto error_exit; } @@ -666,7 +666,7 @@ case JSS_AUDIO_S8: engine.afmt.format = AUDIO_S8; break; case JSS_AUDIO_U8: engine.afmt.format = AUDIO_U8; break; default: - dmError("Unsupported audio format %d (could not set matching SDL format)\n", + dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n", optOutFormat); goto error_exit; } @@ -680,7 +680,7 @@ // Open the audio device if (SDL_OpenAudio(&engine.afmt, NULL) < 0) { - dmError("Couldn't open SDL audio: %s\n", + dmErrorMsg("Couldn't open SDL audio: %s\n", SDL_GetError()); goto error_exit; } @@ -689,7 +689,7 @@ // Initialize player if ((engine.plr = jmpInit(engine.dev)) == NULL) { - dmError("jmpInit() returned NULL\n"); + dmErrorMsg("jmpInit() returned NULL\n"); goto error_exit; } @@ -841,7 +841,7 @@ // Draw frame if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) { - dmError("Can't lock surface.\n"); + dmErrorMsg("Can't lock surface.\n"); goto error_exit; } diff -r b66653c9acb3 -r 985225a93aeb tools/view64.c --- a/tools/view64.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/view64.c Fri Feb 27 03:58:25 2015 +0200 @@ -81,7 +81,7 @@ { if (factor < 1 || factor >= 10) { - dmError("Invalid scale factor %1.0f, see help for valid values.\n", factor); + dmErrorMsg("Invalid scale factor %1.0f, see help for valid values.\n", factor); return FALSE; } @@ -89,7 +89,7 @@ } else { - dmError("Invalid scale factor '%s'.\n", optArg); + dmErrorMsg("Invalid scale factor '%s'.\n", optArg); return FALSE; } } @@ -102,21 +102,21 @@ { if (i < 0 || i >= ndmC64ImageFormats) { - dmError("Invalid image format index %d, see help for valid values.\n", i); + dmErrorMsg("Invalid image format index %d, see help for valid values.\n", i); return FALSE; } optForcedFormat = i; } else { - dmError("Invalid image format argument '%s'.\n", optArg); + dmErrorMsg("Invalid image format argument '%s'.\n", optArg); return FALSE; } } break; default: - dmError("Unknown option '%s'.\n", currArg); + dmErrorMsg("Unknown option '%s'.\n", currArg); return FALSE; } @@ -133,7 +133,7 @@ } else { - dmError("Too many filenames specified ('%s')\n", filename); + dmErrorMsg("Too many filenames specified ('%s')\n", filename); return FALSE; } } @@ -144,7 +144,7 @@ *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 8, optVFlags | SDL_RESIZABLE); if (*screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); return FALSE; } return TRUE; @@ -175,7 +175,7 @@ if (optFilename == NULL) { - dmError("No input file specified, perhaps you need some --help\n"); + dmErrorMsg("No input file specified, perhaps you need some --help\n"); goto error; } @@ -198,7 +198,7 @@ if (ret < 0) { - dmError("Failed to decode bitmap data %d: %s\n", ret, dmErrorStr(ret)); + dmErrorMsg("Failed to decode bitmap data %d: %s\n", ret, dmErrorStr(ret)); goto error; } @@ -210,14 +210,14 @@ if (fmt == NULL) { - dmError("Probing could not find any matching image format. Perhaps try forcing a format via -f.\n"); + dmErrorMsg("Probing could not find any matching image format. Perhaps try forcing a format via -f.\n"); goto error; } // Initialize libSDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { - dmError("Could not initialize SDL: %s\n", SDL_GetError()); + dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); goto error; } initSDL = TRUE; @@ -227,7 +227,7 @@ screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 8, optVFlags | SDL_RESIZABLE); if (screen == NULL) { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); goto error; } @@ -304,7 +304,7 @@ if (SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0) { - dmError("Can't lock surface.\n"); + dmErrorMsg("Can't lock surface.\n"); goto error; } diff -r b66653c9acb3 -r 985225a93aeb tools/xm2jss.c --- a/tools/xm2jss.c Fri Feb 27 02:21:57 2015 +0200 +++ b/tools/xm2jss.c Fri Feb 27 03:58:25 2015 +0200 @@ -108,7 +108,7 @@ optPatternMode = atoi(optArg); if (optPatternMode <= 0 || optPatternMode >= PATMODE_LAST) { - dmError("Unknown pattern conversion mode %d\n", optPatternMode); + dmErrorMsg("Unknown pattern conversion mode %d\n", optPatternMode); return FALSE; } break; @@ -123,7 +123,7 @@ case 9: optOptimize = TRUE; break; default: - dmError("Unknown argument '%s'.\n", currArg); + dmErrorMsg("Unknown argument '%s'.\n", currArg); return FALSE; } @@ -141,7 +141,7 @@ optOutFilename = currArg; else { - dmError("Too many filename arguments specified, '%s'.\n", currArg); + dmErrorMsg("Too many filename arguments specified, '%s'.\n", currArg); return FALSE; } @@ -716,7 +716,7 @@ } else { - dmError("Pattern 0x%x is used on order 0x%x, but has no data!\n", + dmErrorMsg("Pattern 0x%x is used on order 0x%x, but has no data!\n", pattern, i); // Fix it. @@ -726,7 +726,7 @@ else if (pattern != jsetMaxPatterns) { - dmError("Order 0x%x has invalid pattern number 0x%x!\n", + dmErrorMsg("Order 0x%x has invalid pattern number 0x%x!\n", i, pattern); // Fix it. @@ -751,7 +751,7 @@ } else { - dmError("Ext.instrument #%d sNumForNotes[%d] value out range (%d < %d).\n", + dmErrorMsg("Ext.instrument #%d sNumForNotes[%d] value out range (%d < %d).\n", i, m->ninstruments, q); } } @@ -771,7 +771,7 @@ else { if (i >= m->npatterns) - dmError("Pattern 0x%x >= 0x%x, but used!\n", i, m->npatterns); + dmErrorMsg("Pattern 0x%x >= 0x%x, but used!\n", i, m->npatterns); mapPatterns[i] = r->npatterns; r->patterns[r->npatterns] = m->patterns[i]; @@ -797,7 +797,7 @@ { JSSInstrument *ip = m->instruments[i]; if (i >= m->ninstruments) - dmError("Instrument 0x%x >= 0x%x, but used!\n", i, m->ninstruments); + dmErrorMsg("Instrument 0x%x >= 0x%x, but used!\n", i, m->ninstruments); mapInstruments[i] = r->ninstruments; r->instruments[r->ninstruments] = ip; @@ -820,7 +820,7 @@ { if (i >= m->nextInstruments && !optStripExtInstr) { - dmError("Ext.instrument 0x%x >= 0x%x, but used!\n", + dmErrorMsg("Ext.instrument 0x%x >= 0x%x, but used!\n", i, m->nextInstruments); } else @@ -847,7 +847,7 @@ else { map = jsetNotSet; - dmError("e=%d, note=%d, q=%d/%d\n", i, note, q, r->ninstruments); + dmErrorMsg("e=%d, note=%d, q=%d/%d\n", i, note, q, r->ninstruments); } e->sNumForNotes[note] = map; } @@ -888,7 +888,7 @@ n->instrument = mapExtInstruments[n->instrument]; if (n->instrument != jsetNotSet && r->extInstruments[n->instrument] == NULL) - dmError("Non-existing instrument used #%d.\n", n->instrument); + dmErrorMsg("Non-existing instrument used #%d.\n", n->instrument); } JMPGETEFFECT(effect, n->effect); @@ -935,14 +935,14 @@ // Check arguments if (optInFilename == NULL || optOutFilename == NULL) { - dmError("Input or output file not specified. Try --help.\n"); + dmErrorMsg("Input or output file not specified. Try --help.\n"); return 1; } // Read the source file if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) { - dmError("Error opening input file '%s', %d: %s\n", + dmErrorMsg("Error opening input file '%s', %d: %s\n", optInFilename, result, dmErrorStr(result)); return 1; } @@ -956,7 +956,7 @@ dmf_close(inFile); if (result != 0) { - dmError("Error while loading XM file (%i), ", result); + dmErrorMsg("Error while loading XM file (%i), ", result); if (optIgnoreErrors) fprintf(stderr, "ignoring. This may cause problems.\n"); else @@ -1021,7 +1021,7 @@ // Write output file if ((outFile = fopen(optOutFilename, "wb")) == NULL) { - dmError("Error creating output file '%s', %d: %s\n", + dmErrorMsg("Error creating output file '%s', %d: %s\n", optOutFilename, errno, strerror(errno)); return 1; } @@ -1035,9 +1035,9 @@ if (result != 0) { - dmError("Error while saving JSSMOD file, %d: %s\n", + dmErrorMsg("Error while saving JSSMOD file, %d: %s\n", result, dmErrorStr(result)); - dmError("WARNING: The resulting file may be broken!\n"); + dmErrorMsg("WARNING: The resulting file may be broken!\n"); } else {