X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fpicsmap.c;h=ad9a351b4504280c751ecb73e9c2fb6a964e7982;hp=f95b9b0cf9934b3f10467dd33c0be874858b26ad;hb=d60228973b72d3b457e3ec2653ea5b2cb38fc0c9;hpb=0fbd5e192896b3e446832d0a451df2cec5f5ae40 diff --git a/test/picsmap.c b/test/picsmap.c index f95b9b0c..ad9a351b 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2017 Free Software Foundation, Inc. * + * Copyright (c) 2017,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.114 2017/12/16 23:49:40 tom Exp $ + * $Id: picsmap.c,v 1.123 2018/06/16 22:55:45 tom Exp $ * * Author: Thomas E. Dickey * @@ -52,7 +52,7 @@ #include #include -#ifdef HAVE_STDINT_H +#if HAVE_STDINT_H #include #define my_intptr_t intptr_t #else @@ -61,6 +61,10 @@ #if HAVE_TSEARCH #include +#if HAVE_TDESTROY && !defined(_GNU_SOURCE) +#undef HAVE_TDESTROY +#define HAVE_TDESTROY 0 +#endif #endif #undef CUR /* use only the curses interface */ @@ -71,10 +75,12 @@ #define L_CURLY '{' #define R_CURLY '}' +#define MaxSCALE 1000 /* input curses ranges 0..1000 */ +#define MaxRGB 255 /* output color ranges 0..255 */ #define okCOLOR(n) ((n) >= 0 && (n) < COLORS) -#define okRGB(n) ((n) >= 0 && (n) <= 1000) -#define Scaled256(n) (NCURSES_COLOR_T) (int)(((n) * 1000.0) / 256) -#define ScaledColor(n) (NCURSES_COLOR_T) (int)(((n) * 1000.0) / scale) +#define okSCALE(n) ((n) >= 0 && (n) <= MaxSCALE) +#define Scaled256(n) (NCURSES_COLOR_T) (int)(((double)(n) * MaxSCALE) / 255) +#define ScaledColor(n) (NCURSES_COLOR_T) (int)(((double)(n) * MaxSCALE) / scale) #ifndef RGB_PATH #define RGB_PATH "/etc/X11/rgb.txt" @@ -582,6 +588,7 @@ read_palette(const char *filename) strcpy(s, filename); if (tries & 4) { char *t = s; + char *tc; int num; char chr; int found = 0; @@ -589,7 +596,8 @@ read_palette(const char *filename) if (*t == '-') { if (sscanf(t, "-%d%c", &num, &chr) == 2 && chr == 'c' && - !strncmp(strchr(t, chr), "color", 5)) { + (tc = strchr(t, chr)) != 0 && + !(strncmp) (tc, "color", 5)) { found = 1; } break; @@ -597,7 +605,7 @@ read_palette(const char *filename) ++t; } if (found && (t != s) - && strncmp(s, "xterm", (size_t) (t - s))) { + && (strncmp) (s, "xterm", (size_t) (t - s))) { sprintf(s, "xterm%s", filename + (t - s)); } else { continue; @@ -650,7 +658,7 @@ init_palette(const char *palette_file) if (data != 0) { int n; int red, green, blue; - int scale = 1000; + int scale = MaxSCALE; int c; for (n = 0; data[n] != 0; ++n) { if (sscanf(data[n], "scale:%d", &c) == 1) { @@ -661,9 +669,9 @@ init_palette(const char *palette_file) &green, &blue) == 4 && okCOLOR(c) - && okRGB(red) - && okRGB(green) - && okRGB(blue)) { + && okSCALE(red) + && okSCALE(green) + && okSCALE(blue)) { /* *INDENT-EQLS* */ all_colors[c].red = ScaledColor(red); all_colors[c].green = ScaledColor(green); @@ -1007,6 +1015,8 @@ parse_xbm(char **data) } else if ((t = strstr(buf, "_height")) != 0) { state |= 2; result->high = (short) num; + } else { + break; } *t = '\0'; if (result->name) { @@ -1043,7 +1053,7 @@ parse_xbm(char **data) if (isdigit(UChar(*s))) { long value = strtol(s, &t, 0); int b; - if (t != s || value > 255 || value < 0) { + if (t != s || value > MaxRGB || value < 0) { s = t; } else { state = -1; @@ -1188,7 +1198,7 @@ parse_xpm(char **data) if (num_colors >= result->colors) { finish_c_values(result); state = 4; - if (list != 0 && list[0] == 0) + if (list[0] == 0) list[0] = strdup("\033"); } break; @@ -1204,7 +1214,7 @@ parse_xpm(char **data) /* should not happen... */ continue; } - if (!strncmp(cs, list[c], (size_t) cpp)) { + if (!(strncmp) (cs, list[c], (size_t) cpp)) { result->cells[which].ch = list[c][0]; result->cells[which].fg = c; result->fgcol[c].count++; @@ -1279,7 +1289,7 @@ parse_img(const char *filename) size_t n = strlen(filename); debugmsg2("...read %s", buffer); if (strlen(buffer) > n && - !strncmp(buffer, filename, n) && + !(strncmp) (buffer, filename, n) && isspace(UChar(buffer[n])) && sscanf(skip_word(buffer + n), " %dx%d ", &pic_x, &pic_y) == 2) { /* distort image to make it show normally on terminal */ @@ -1347,9 +1357,9 @@ parse_img(const char *filename) &check)) { if ((s - t) > 8) /* 6 hex digits vs 8 */ check /= 256; - if (r > 255 || - g > 255 || - b > 255 || + if (r > MaxRGB || + g > MaxRGB || + b > MaxRGB || check != (unsigned) ((r << 16) | (g << 8) | b)) { okay = FALSE; break; @@ -1475,7 +1485,7 @@ show_picture(PICS_HEAD * pics) debugmsg("called show_picture"); logmsg("...using %dx%d screen", LINES, COLS); -#if USE_EXTENDED_COLORS +#if HAVE_RESET_COLOR_PAIRS reset_color_pairs(); #elif HAVE_CURSCR wclear(curscr); @@ -1577,6 +1587,8 @@ report_colors(PICS_HEAD * pics) if (j < 10) ++digits; } + if (digits > 8) + digits = 8; logmsg("These colors were used:"); high = (pics->colors + wide - 1) / wide; for (j = 0; j < high && j < pics->colors; ++j) {