mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-26 17:45:52 +01:00
wmrlib: Avoid code duplication
We can put common repeated code into a helper function, and increase readability a bit.
This commit is contained in:
114
wrlib/nxpm.c
114
wrlib/nxpm.c
@@ -52,6 +52,21 @@
|
|||||||
|
|
||||||
#ifndef USE_XPM
|
#ifndef USE_XPM
|
||||||
|
|
||||||
|
static void free_color_symbol_table(unsigned char *color_table[],
|
||||||
|
unsigned short *symbol_table)
|
||||||
|
{
|
||||||
|
if (color_table[0])
|
||||||
|
free(color_table[0]);
|
||||||
|
if (color_table[1])
|
||||||
|
free(color_table[1]);
|
||||||
|
if (color_table[2])
|
||||||
|
free(color_table[2]);
|
||||||
|
if (color_table[3])
|
||||||
|
free(color_table[3]);
|
||||||
|
if (symbol_table)
|
||||||
|
free(symbol_table);
|
||||||
|
}
|
||||||
|
|
||||||
RImage *RGetImageFromXPMData(RContext * context, char **data)
|
RImage *RGetImageFromXPMData(RContext * context, char **data)
|
||||||
{
|
{
|
||||||
RImage *image = NULL;
|
RImage *image = NULL;
|
||||||
@@ -81,16 +96,7 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
|||||||
|
|
||||||
if (!color_table[0] || !color_table[1] || !color_table[2] || !color_table[3] || !symbol_table || !bsize) {
|
if (!color_table[0] || !color_table[1] || !color_table[2] || !color_table[3] || !symbol_table || !bsize) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,16 +145,7 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
|||||||
|
|
||||||
image = RCreateImage(w, h, transp);
|
image = RCreateImage(w, h, transp);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,30 +215,12 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
|
|||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
return image;
|
return image;
|
||||||
|
|
||||||
bad_format:
|
bad_format:
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (image)
|
if (image)
|
||||||
RReleaseImage(image);
|
RReleaseImage(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -302,16 +281,7 @@ RImage *RLoadXPM(RContext * context, char *file, int index)
|
|||||||
!color_table[3] || !symbol_table || !bsize || !buffer) {
|
!color_table[3] || !symbol_table || !bsize || !buffer) {
|
||||||
RErrorCode = RERR_NOMEMORY;
|
RErrorCode = RERR_NOMEMORY;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -368,16 +338,7 @@ RImage *RLoadXPM(RContext * context, char *file, int index)
|
|||||||
image = RCreateImage(w, h, transp);
|
image = RCreateImage(w, h, transp);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -456,16 +417,7 @@ RImage *RLoadXPM(RContext * context, char *file, int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return image;
|
return image;
|
||||||
@@ -473,16 +425,7 @@ RImage *RLoadXPM(RContext * context, char *file, int index)
|
|||||||
bad_format:
|
bad_format:
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (image)
|
if (image)
|
||||||
@@ -492,16 +435,7 @@ RImage *RLoadXPM(RContext * context, char *file, int index)
|
|||||||
bad_file:
|
bad_file:
|
||||||
RErrorCode = RERR_BADIMAGEFILE;
|
RErrorCode = RERR_BADIMAGEFILE;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (color_table[0])
|
free_color_symbol_table(color_table[], symbol_table);
|
||||||
free(color_table[0]);
|
|
||||||
if (color_table[1])
|
|
||||||
free(color_table[1]);
|
|
||||||
if (color_table[2])
|
|
||||||
free(color_table[2]);
|
|
||||||
if (color_table[3])
|
|
||||||
free(color_table[3]);
|
|
||||||
if (symbol_table)
|
|
||||||
free(symbol_table);
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (image)
|
if (image)
|
||||||
|
|||||||
Reference in New Issue
Block a user