X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fpicsmap.c;h=4e5b2634d2ca39f2f84a1a84e5941ed98b96ecfe;hb=b93d96b78ac5250135975df892cee793dc3c0797;hp=ccfe57b4a39ba1787efcdb79c1f272c10322950d;hpb=e33150410925e7858dacebb585a9bd90db683d86;p=ncurses.git diff --git a/test/picsmap.c b/test/picsmap.c index ccfe57b4..4e5b2634 100644 --- a/test/picsmap.c +++ b/test/picsmap.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: picsmap.c,v 1.116 2018/01/16 09:14:52 tom Exp $ + * $Id: picsmap.c,v 1.118 2018/03/24 22:37:42 tom Exp $ * * Author: Thomas E. Dickey * @@ -71,10 +71,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" @@ -589,7 +591,7 @@ read_palette(const char *filename) if (*t == '-') { if (sscanf(t, "-%d%c", &num, &chr) == 2 && chr == 'c' && - !strncmp(strchr(t, chr), "color", 5)) { + !(strncmp) (strchr(t, chr), "color", 5)) { found = 1; } break; @@ -597,7 +599,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 +652,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 +663,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); @@ -1043,7 +1045,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; @@ -1204,7 +1206,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 +1281,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 +1349,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;