* authorization. *
****************************************************************************/
/*
- * $Id: picsmap.c,v 1.117 2018/02/12 09:57:31 tom Exp $
+ * $Id: picsmap.c,v 1.123 2018/06/16 22:55:45 tom Exp $
*
* Author: Thomas E. Dickey
*
#if HAVE_TSEARCH
#include <search.h>
+#if HAVE_TDESTROY && !defined(_GNU_SOURCE)
+#undef HAVE_TDESTROY
+#define HAVE_TDESTROY 0
+#endif
#endif
#undef CUR /* use only the curses interface */
#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"
strcpy(s, filename);
if (tries & 4) {
char *t = s;
+ char *tc;
int num;
char chr;
int found = 0;
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;
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) {
&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);
} else if ((t = strstr(buf, "_height")) != 0) {
state |= 2;
result->high = (short) num;
+ } else {
+ break;
}
*t = '\0';
if (result->name) {
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;
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;
&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;
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) {