Skip to content

Commit

Permalink
Fixed supportsUTF8 and call it
Browse files Browse the repository at this point in the history
Removed some warnings
Closes #7
  • Loading branch information
posva committed Oct 14, 2015
1 parent 52ee42e commit a5e1dce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/catimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down Expand Up @@ -81,7 +83,7 @@ int main(int argc, char *argv[])
}

if (precision == 0 || precision > 2) {
if (supportsUTF8)
if (supportsUTF8())
precision = 2;
else
precision = 1;
Expand Down
24 changes: 8 additions & 16 deletions src/sh_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -53,25 +50,22 @@ 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;

result = (unsigned char*)stbi__malloc(*frames * (size + 2));
gr = &head;
p = result;

while (gr)
{
while (gr) {
prev = gr;
memcpy(p, gr->data, size);
p += size;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a5e1dce

Please sign in to comment.