mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-18 03:50:30 +01:00
WRaster: Improve error messages to provide useful information to user
The original error messages tended to be a bit sparse, now they try to be a little bit more helpful, and translatable in user's language. In xutil.c:122, took opportunity fix a problem because calling 'perror' after other function which are likely to have changed the errno is likely to provide a wrong error string. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
e5f7ef23a6
commit
bcb53700d6
@@ -407,7 +407,8 @@ static Bool setupPseudoColorColormap(RContext * context)
|
||||
}
|
||||
|
||||
if (theMap < 0) {
|
||||
puts("wrlib: no std cmap found");
|
||||
fprintf(stderr, _("wrlib: no standard colormap found for visual 0x%lX\n"),
|
||||
context->visual->visualid);
|
||||
}
|
||||
|
||||
if (theMap >= 0 && allocateStandardPseudoColor(context, &maps[theMap])) {
|
||||
|
||||
@@ -47,48 +47,48 @@
|
||||
* implied warranty.
|
||||
*/
|
||||
|
||||
char pm_getc(FILE * const fileP)
|
||||
char pm_getc(FILE *const fileP, const char *filename)
|
||||
{
|
||||
int ich;
|
||||
char ch;
|
||||
|
||||
ich = getc(fileP);
|
||||
if (ich == EOF)
|
||||
fprintf(stderr, "EOF / read error reading a byte\n");
|
||||
fprintf(stderr, _("wrlib: EOF / read error reading a byte from PPM file \"%s\"\n"), filename);
|
||||
ch = (char)ich;
|
||||
|
||||
if (ch == '#') {
|
||||
do {
|
||||
ich = getc(fileP);
|
||||
if (ich == EOF)
|
||||
fprintf(stderr, "EOF / read error reading a byte\n");
|
||||
fprintf(stderr, _("wrlib: EOF / read error reading a byte from PPM file \"%s\"\n"), filename);
|
||||
ch = (char)ich;
|
||||
} while (ch != '\n' && ch != '\r');
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
unsigned char pm_getrawbyte(FILE * const file)
|
||||
unsigned char pm_getrawbyte(FILE *const file, const char *filename)
|
||||
{
|
||||
int iby;
|
||||
|
||||
iby = getc(file);
|
||||
if (iby == EOF)
|
||||
fprintf(stderr, "EOF / read error reading a one-byte sample\n");
|
||||
fprintf(stderr, _("wrlib: EOF / read error reading a byte from PPM file \"%s\"\n"), filename);
|
||||
return (unsigned char)iby;
|
||||
}
|
||||
|
||||
int pm_getuint(FILE * const ifP)
|
||||
int pm_getuint(FILE *const ifP, const char *filename)
|
||||
{
|
||||
char ch;
|
||||
unsigned int i;
|
||||
|
||||
do {
|
||||
ch = pm_getc(ifP);
|
||||
ch = pm_getc(ifP, filename);
|
||||
} while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
|
||||
|
||||
if (ch < '0' || ch > '9') {
|
||||
fprintf(stderr, "junk in file where an unsigned integer should be\n");
|
||||
fprintf(stderr, _("wrlib: junk in PPM file \"%s\", expected an unsigned integer but got 0x%02X\n"), filename, (int)ch);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -97,20 +97,20 @@ int pm_getuint(FILE * const ifP)
|
||||
unsigned int const digitVal = ch - '0';
|
||||
|
||||
if (i > INT_MAX / 10) {
|
||||
fprintf(stderr, "ASCII decimal integer in file is too large to be processed\n");
|
||||
fprintf(stderr, _("wrlib: ASCII decimal integer in PPM file \"%s\" is too large to be processed\n"), filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
i *= 10;
|
||||
|
||||
if (i > INT_MAX - digitVal) {
|
||||
fprintf(stderr, "ASCII decimal integer in file is too large to be processed\n");
|
||||
fprintf(stderr, _("wrlib: ASCII decimal integer in PPM file \"%s\" is too large to be processed\n"), filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
i += digitVal;
|
||||
|
||||
ch = pm_getc(ifP);
|
||||
ch = pm_getc(ifP, filename);
|
||||
} while (ch >= '0' && ch <= '9');
|
||||
|
||||
return i;
|
||||
@@ -119,7 +119,7 @@ int pm_getuint(FILE * const ifP)
|
||||
/******************************************************************************************/
|
||||
|
||||
/* PGM: support for portable graymap ascii and binary encoding */
|
||||
static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
||||
static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const char *filename)
|
||||
{
|
||||
RImage *image;
|
||||
unsigned char *ptr;
|
||||
@@ -143,7 +143,7 @@ static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
||||
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
val = pm_getuint(file);
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
@@ -189,7 +189,7 @@ static RImage *load_graymap(FILE * file, int w, int h, int max, int raw)
|
||||
}
|
||||
|
||||
/* PPM: support for portable pixmap ascii and binary encoding */
|
||||
static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
||||
static RImage *load_pixmap(FILE *file, int w, int h, int max, int raw, const char *filename)
|
||||
{
|
||||
RImage *image;
|
||||
int i;
|
||||
@@ -214,7 +214,7 @@ static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
||||
for (y = 0; y < h; y++) {
|
||||
for (x = 0; x < w; x++) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
val = pm_getuint(file);
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
@@ -249,7 +249,7 @@ static RImage *load_pixmap(FILE * file, int w, int h, int max, int raw)
|
||||
}
|
||||
|
||||
/* PBM: support for portable bitmap ascii and binary encoding */
|
||||
static RImage *load_bitmap(FILE * file, int w, int h, int max, int raw)
|
||||
static RImage *load_bitmap(FILE *file, int w, int h, int max, int raw, const char *filename)
|
||||
{
|
||||
RImage *image;
|
||||
int val;
|
||||
@@ -271,7 +271,7 @@ static RImage *load_bitmap(FILE * file, int w, int h, int max, int raw)
|
||||
int i = 0;
|
||||
|
||||
while (i < w * h) {
|
||||
val = pm_getuint(file);
|
||||
val = pm_getuint(file, filename);
|
||||
|
||||
if (val > max || val < 0) {
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
@@ -295,7 +295,7 @@ static RImage *load_bitmap(FILE * file, int w, int h, int max, int raw)
|
||||
bitshift = -1;
|
||||
for (x = 0; x < w; x++) {
|
||||
if (bitshift == -1) {
|
||||
buf = pm_getrawbyte(file);
|
||||
buf = pm_getrawbyte(file, filename);
|
||||
bitshift = 7;
|
||||
}
|
||||
val = (buf >> bitshift) & 1;
|
||||
@@ -380,13 +380,13 @@ RImage *RLoadPPM(const char *file_name)
|
||||
|
||||
if (type == '1' || type == '4') {
|
||||
/* Portable Bit Map: P1 is for 'plain' (ascii, rare), P4 for 'regular' (binary) */
|
||||
image = load_bitmap(file, w, h, m, type);
|
||||
image = load_bitmap(file, w, h, m, type, file_name);
|
||||
} else if (type == '2' || type == '5') {
|
||||
/* Portable Gray Map: P2 is for 'plain' (ascii, rare), P5 for 'regular' (binary) */
|
||||
image = load_graymap(file, w, h, m, type);
|
||||
image = load_graymap(file, w, h, m, type, file_name);
|
||||
} else if (type == '3' || type == '6') {
|
||||
/* Portable Pix Map: P3 is for 'plain' (ascii, rare), P6 for 'regular' (binary) */
|
||||
image = load_pixmap(file, w, h, m, type);
|
||||
image = load_pixmap(file, w, h, m, type, file_name);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <webp/decode.h>
|
||||
|
||||
@@ -33,6 +34,34 @@
|
||||
#include "wr_i18n.h"
|
||||
|
||||
|
||||
/*
|
||||
* webp_message_from_status
|
||||
*
|
||||
* return the text message from a VP8 status code
|
||||
*/
|
||||
static const char *webp_message_from_status(VP8StatusCode status)
|
||||
{
|
||||
static const char *const known_message[] = {
|
||||
/* Known codes as per libWebP 0.4.1 */
|
||||
[VP8_STATUS_OUT_OF_MEMORY] = N_("out of memory"),
|
||||
[VP8_STATUS_INVALID_PARAM] = N_("invalid parameter"),
|
||||
[VP8_STATUS_BITSTREAM_ERROR] = N_("error in the bitstream"),
|
||||
[VP8_STATUS_UNSUPPORTED_FEATURE] = N_("feature is not supported"),
|
||||
[VP8_STATUS_SUSPENDED] = N_("operation suspended"),
|
||||
[VP8_STATUS_USER_ABORT] = N_("aborted by user"),
|
||||
[VP8_STATUS_NOT_ENOUGH_DATA] = N_("not enough data")
|
||||
};
|
||||
static char custom_message[128];
|
||||
|
||||
if (status >= 0 && status < sizeof(known_message) / sizeof(known_message[0]))
|
||||
if (known_message[status] != NULL)
|
||||
return known_message[status];
|
||||
|
||||
snprintf(custom_message, sizeof(custom_message),
|
||||
_("unknow status code %d"), status);
|
||||
return custom_message;
|
||||
}
|
||||
|
||||
RImage *RLoadWEBP(const char *file_name)
|
||||
{
|
||||
FILE *file;
|
||||
@@ -41,6 +70,7 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
int raw_data_size;
|
||||
int r;
|
||||
uint8_t *raw_data;
|
||||
VP8StatusCode status;
|
||||
WebPBitstreamFeatures features;
|
||||
uint8_t *ret = NULL;
|
||||
|
||||
@@ -73,7 +103,8 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
raw_data_size = ftell(file);
|
||||
|
||||
if (raw_data_size <= 0) {
|
||||
fprintf(stderr, "wrlib: Failed to find the WEBP file size for \"%s\"\n", file_name);
|
||||
fprintf(stderr, _("wrlib: could not get size of WebP file \"%s\", %s\n"),
|
||||
file_name, strerror(errno));
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
fclose(file);
|
||||
return NULL;
|
||||
@@ -97,8 +128,10 @@ RImage *RLoadWEBP(const char *file_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (WebPGetFeatures(raw_data, raw_data_size, &features) != VP8_STATUS_OK) {
|
||||
fprintf(stderr, "wrlib: WebPGetFeatures has failed on \"%s\"\n", file_name);
|
||||
status = WebPGetFeatures(raw_data, raw_data_size, &features);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
fprintf(stderr, _("wrlib: could not get features from WebP file \"%s\", %s\n"),
|
||||
file_name, webp_message_from_status(status));
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
free(raw_data);
|
||||
return NULL;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -111,17 +112,17 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
||||
rximg->info.shmid = shmget(IPC_PRIVATE, rximg->image->bytes_per_line * height, IPC_CREAT | 0777);
|
||||
if (rximg->info.shmid < 0) {
|
||||
context->attribs->use_shared_memory = 0;
|
||||
perror("wrlib: could not allocate shared memory segment");
|
||||
fprintf(stderr, _("wrlib: could not allocate shared memory segment, %s: %s\n"), "shmget", strerror(errno));
|
||||
XDestroyImage(rximg->image);
|
||||
goto retry_without_shm;
|
||||
}
|
||||
|
||||
rximg->info.shmaddr = shmat(rximg->info.shmid, 0, 0);
|
||||
if (rximg->info.shmaddr == (void *)-1) {
|
||||
fprintf(stderr, _("wrlib: could not allocate shared memory segment, %s: %s\n"), "shmat", strerror(errno));
|
||||
context->attribs->use_shared_memory = 0;
|
||||
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib: shmctl");
|
||||
perror("wrlib: could not allocate shared memory");
|
||||
fprintf(stderr, _("wrlib: error occured while aborting %s, %s\n"), "shmctl", strerror(errno));
|
||||
XDestroyImage(rximg->image);
|
||||
goto retry_without_shm;
|
||||
}
|
||||
@@ -137,14 +138,13 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
|
||||
/* rximg->image->obdata = &(rximg->info); */
|
||||
|
||||
if (shmError) {
|
||||
fprintf(stderr, _("wrlib: could not attach shared memory segment to XImage\n"));
|
||||
context->attribs->use_shared_memory = 0;
|
||||
XDestroyImage(rximg->image);
|
||||
if (shmdt(rximg->info.shmaddr) < 0)
|
||||
perror("wrlib: shmdt");
|
||||
fprintf(stderr, _("wrlib: error occured while aborting %s, %s\n"), "shmdt", strerror(errno));
|
||||
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib: shmctl");
|
||||
/* printf("wrlib:error attaching shared memory segment to XImage\n");
|
||||
*/
|
||||
fprintf(stderr, _("wrlib: error occured while aborting %s, %s\n"), "shmctl", strerror(errno));
|
||||
goto retry_without_shm;
|
||||
}
|
||||
}
|
||||
@@ -166,9 +166,9 @@ void RDestroyXImage(RContext * context, RXImage * rximage)
|
||||
XShmDetach(context->dpy, &rximage->info);
|
||||
XDestroyImage(rximage->image);
|
||||
if (shmdt(rximage->info.shmaddr) < 0)
|
||||
perror("wrlib: shmdt");
|
||||
fprintf(stderr, _("wrlib: error occured while releasing XImage, %s: %s\n"), "shmdt", strerror(errno));
|
||||
if (shmctl(rximage->info.shmid, IPC_RMID, 0) < 0)
|
||||
perror("wrlib: shmctl");
|
||||
fprintf(stderr, _("wrlib: error occured while releasing XImage, %s: %s\n"), "shmctl", strerror(errno));
|
||||
} else {
|
||||
XDestroyImage(rximage->image);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user