From a5e1dce082aa5a8e57c6e4223ab0f6732bef885a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 14 Oct 2015 09:18:13 +0200 Subject: [PATCH] Fixed supportsUTF8 and call it Removed some warnings Closes #7 --- CMakeLists.txt | 5 +++-- src/catimg.c | 6 ++++-- src/sh_image.c | 24 ++++++++---------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2618206..5952dd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,9 @@ project(catimg) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) # set soem options -#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -std=c99 -g") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c99") +#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -g -std=c99 -Wno-unused-result") +#set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c99 -Wno-unused-result") set(CMAKE_BUILD_TYPE Release) set(SRC ${PROJECT_SOURCE_DIR}/src) diff --git a/src/catimg.c b/src/catimg.c index 2fc1557..49661cd 100644 --- a/src/catimg.c +++ b/src/catimg.c @@ -40,7 +40,9 @@ char supportsUTF8() { const char* LANG = getenv("LANG"); const char* LC_CTYPE = getenv("LC_CTYPE"); const char* UTF = "UTF-8"; - return strstr(LC_ALL, UTF) || strstr(LANG, UTF) || strstr(LC_CTYPE, UTF); + return (LC_ALL && strstr(LC_ALL, UTF)) + || (LANG && strstr(LANG, UTF)) + || (LC_CTYPE && strstr(LC_CTYPE, UTF)); } int main(int argc, char *argv[]) @@ -81,7 +83,7 @@ int main(int argc, char *argv[]) } if (precision == 0 || precision > 2) { - if (supportsUTF8) + if (supportsUTF8()) precision = 2; else precision = 1; diff --git a/src/sh_image.c b/src/sh_image.c index 1160f01..a1c3915 100644 --- a/src/sh_image.c +++ b/src/sh_image.c @@ -23,8 +23,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra stbi__start_file(&s, f); - if (stbi__gif_test(&s)) - { + if (stbi__gif_test(&s)) { stbi__gif g; gif_result head; gif_result *prev = 0, *gr = &head; @@ -34,10 +33,8 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra *frames = 0; - while (gr->data = stbi__gif_load_next(&s, &g, channels, 4)) - { - if (gr->data == (unsigned char*)&s) - { + while ((gr->data = stbi__gif_load_next(&s, &g, channels, 4))) { + if (gr->data == (unsigned char*)&s) { gr->data = 0; break; } @@ -53,16 +50,14 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra if (gr != &head) STBI_FREE(gr); - if (*frames > 0) - { + if (*frames > 0) { *x = g.w; *y = g.h; } result = head.data; - if (*frames > 1) - { + if (*frames > 1) { unsigned int size = 4 * g.w * g.h; unsigned char *p = 0; @@ -70,8 +65,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra gr = &head; p = result; - while (gr) - { + while (gr) { prev = gr; memcpy(p, gr->data, size); p += size; @@ -83,9 +77,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra if (prev != &head) STBI_FREE(prev); } } - } - else - { + } else { result = stbi__load_main(&s, x, y, channels, 0); *frames = !!result; } @@ -142,7 +134,7 @@ void img_load_from_file(image_t *img, const char* file) } // fill the array - void (*pixelSetter)(color_t *pixel, unsigned char* ptr); + void (*pixelSetter)(color_t *pixel, unsigned char* ptr) = &setPixelGray; switch (channels) { case 1: pixelSetter = &setPixelGray;