Skip to content

Commit a5e1dce

Browse files
committed
Fixed supportsUTF8 and call it
Removed some warnings Closes #7
1 parent 52ee42e commit a5e1dce

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ project(catimg)
44
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
55

66
# set soem options
7-
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -std=c99 -g")
8-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c99")
7+
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -g -std=c99 -Wno-unused-result")
8+
#set(CMAKE_BUILD_TYPE Debug)
9+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra -Os -std=c99 -Wno-unused-result")
910
set(CMAKE_BUILD_TYPE Release)
1011

1112
set(SRC ${PROJECT_SOURCE_DIR}/src)

src/catimg.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ char supportsUTF8() {
4040
const char* LANG = getenv("LANG");
4141
const char* LC_CTYPE = getenv("LC_CTYPE");
4242
const char* UTF = "UTF-8";
43-
return strstr(LC_ALL, UTF) || strstr(LANG, UTF) || strstr(LC_CTYPE, UTF);
43+
return (LC_ALL && strstr(LC_ALL, UTF))
44+
|| (LANG && strstr(LANG, UTF))
45+
|| (LC_CTYPE && strstr(LC_CTYPE, UTF));
4446
}
4547

4648
int main(int argc, char *argv[])
@@ -81,7 +83,7 @@ int main(int argc, char *argv[])
8183
}
8284

8385
if (precision == 0 || precision > 2) {
84-
if (supportsUTF8)
86+
if (supportsUTF8())
8587
precision = 2;
8688
else
8789
precision = 1;

src/sh_image.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra
2323

2424
stbi__start_file(&s, f);
2525

26-
if (stbi__gif_test(&s))
27-
{
26+
if (stbi__gif_test(&s)) {
2827
stbi__gif g;
2928
gif_result head;
3029
gif_result *prev = 0, *gr = &head;
@@ -34,10 +33,8 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra
3433

3534
*frames = 0;
3635

37-
while (gr->data = stbi__gif_load_next(&s, &g, channels, 4))
38-
{
39-
if (gr->data == (unsigned char*)&s)
40-
{
36+
while ((gr->data = stbi__gif_load_next(&s, &g, channels, 4))) {
37+
if (gr->data == (unsigned char*)&s) {
4138
gr->data = 0;
4239
break;
4340
}
@@ -53,25 +50,22 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra
5350
if (gr != &head)
5451
STBI_FREE(gr);
5552

56-
if (*frames > 0)
57-
{
53+
if (*frames > 0) {
5854
*x = g.w;
5955
*y = g.h;
6056
}
6157

6258
result = head.data;
6359

64-
if (*frames > 1)
65-
{
60+
if (*frames > 1) {
6661
unsigned int size = 4 * g.w * g.h;
6762
unsigned char *p = 0;
6863

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

73-
while (gr)
74-
{
68+
while (gr) {
7569
prev = gr;
7670
memcpy(p, gr->data, size);
7771
p += size;
@@ -83,9 +77,7 @@ STBIDEF unsigned char *stbi_xload(char const *filename, int *x, int *y, int *fra
8377
if (prev != &head) STBI_FREE(prev);
8478
}
8579
}
86-
}
87-
else
88-
{
80+
} else {
8981
result = stbi__load_main(&s, x, y, channels, 0);
9082
*frames = !!result;
9183
}
@@ -142,7 +134,7 @@ void img_load_from_file(image_t *img, const char* file)
142134
}
143135

144136
// fill the array
145-
void (*pixelSetter)(color_t *pixel, unsigned char* ptr);
137+
void (*pixelSetter)(color_t *pixel, unsigned char* ptr) = &setPixelGray;
146138
switch (channels) {
147139
case 1:
148140
pixelSetter = &setPixelGray;

0 commit comments

Comments
 (0)