/****************************************************************************
- * Copyright (c) 2017-2018,2019 Free Software Foundation, Inc. *
+ * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 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 *
* authorization. *
****************************************************************************/
/*
- * $Id: picsmap.c,v 1.127 2019/01/21 19:45:57 tom Exp $
+ * $Id: picsmap.c,v 1.139 2021/05/08 15:56:05 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 P2I(n) (((int)(my_intptr_t)(n)) - 1)
#define I2P(n) (void *)(my_intptr_t)((n) + 1)
-#define stop_curses() if (in_curses) endwin()
+#define pause_curses() if (in_curses) stop_curses()
#define debugmsg if (debugging) logmsg
#define debugmsg2 if (debugging) logmsg2
-static void cleanup(int) GCC_NORETURN;
+static GCC_NORETURN void cleanup(int);
static void giveup(const char *fmt, ...) GCC_PRINTFLIKE(1, 2);
static void logmsg(const char *fmt, ...) GCC_PRINTFLIKE(1, 2);
static void logmsg2(const char *fmt, ...) GCC_PRINTFLIKE(1, 2);
static void
cleanup(int code)
{
- stop_curses();
+ pause_curses();
close_log();
ExitProgram(code);
/* NOTREACHED */
reading_ncols = 0;
}
-#if HAVE_TSEARCH && HAVE_TDESTROY
-static void
-never_free(void *node GCC_UNUSED)
-{
-}
-#endif
-
static void
dispose_c_values(void)
{
#if HAVE_TSEARCH
if (reading_ntree != 0) {
-#if HAVE_TDESTROY
- tdestroy(reading_ntree, never_free);
-#else
int n;
for (n = 0; n < reading_last; ++n) {
tdelete(I2P(n), &reading_ntree, compare_c_values);
}
-#endif
reading_ntree = 0;
}
#endif
struct stat sb;
if (!quiet) {
- stop_curses();
+ pause_curses();
printf("** %s\n", filename);
}
if (is_file(filename, &sb)) {
size_t size = (size_t) sb.st_size;
char *blob = typeCalloc(char, size + 1);
- bool had_line = TRUE;
bool binary = FALSE;
- unsigned j;
unsigned k = 0;
result = typeCalloc(char *, size + 1);
FILE *fp = fopen(filename, "r");
if (fp != 0) {
logmsg("opened %s", filename);
+
if (fread(blob, sizeof(char), size, fp) == size) {
+ bool had_line = TRUE;
+ unsigned j;
+
for (j = 0; (size_t) j < size; ++j) {
if (blob[j] == '\0' ||
(UChar(blob[j]) < 32 &&
};
size_t n;
- stop_curses();
+ pause_curses();
fflush(stdout);
for (n = 0; n < SIZEOF(msg); n++)
{
va_list ap;
- stop_curses();
+ pause_curses();
fflush(stdout);
va_start(ap, fmt);
continue;
}
}
- s += strlen(s);
if (tries & 2) {
int len = (int) strlen(filename);
if ((power2 != COLORS) || ((shift % 3) != 0)) {
if (all_colors == 0) {
init_palette(getenv("TERM"));
- }
- if (all_colors == 0) {
- giveup("With %d colors, you need a palette-file", COLORS);
+ if (all_colors == 0) {
+ giveup("With %d colors, you need a palette-file", COLORS);
+ }
}
}
}
arg1[cpp] = '\0';
result = 1;
} else {
- char *t;
const char *s = skip_cs(source);
size_t have = strlen(source);
memcpy(arg1, s, (size_t) cpp);
s += cpp;
while (*s++ == '\t') {
+ char *t;
for (t = arg2; (*s != '\0') && strchr("\t\"", *s) == 0;) {
if (*s == ' ') {
s = skip_cs(s);
return result;
}
+#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
+
+static int
+CaselessCmp(const char *a, const char *b)
+{ /* strcasecmp isn't portable */
+ while (*a && *b) {
+ int cmp = LOWERCASE(*a) - LOWERCASE(*b);
+ if (cmp != 0)
+ break;
+ a++, b++;
+ }
+ return LOWERCASE(*a) - LOWERCASE(*b);
+}
+
static RGB_NAME *
lookup_rgb(const char *name)
{
if (rgb_table != 0) {
int n;
for (n = 0; rgb_table[n].name != 0; ++n) {
- if (!strcasecmp(name, rgb_table[n].name)) {
+ if (!CaselessCmp(name, rgb_table[n].name)) {
result = &rgb_table[n];
break;
}
{
int n;
int state = 0;
- char buf[BUFSIZ];
+ char buf[2048];
int num;
char ch;
char *s;
case 0:
case 1:
case 2:
- if (sscanf(s, "#define %s %d%c", buf, &num, &ch) >= 2) {
+ if (sscanf(s, "#define %1024s %d%c", buf, &num, &ch) >= 2) {
if ((t = strstr(buf, "_width")) != 0) {
state |= 1;
result->wide = (short) bytes_of(num);
}
break;
case 3:
- if (sscanf(s, "static char %[^_ ]_bits[]%c", buf, &ch) >= 1) {
+ if (sscanf(s, "static char %1024[^_ ]_bits[]%c", buf, &ch) >= 1) {
if (strcmp(result->name, buf)) {
goto finish;
}
/* subsequent lines begin "col,row: (r,g,b,a) #RGB" */
int r, g, b, nocolor;
unsigned check;
- int which, c;
char *t;
char *s = t = strchr(buffer, '#');
+
if (s != 0) {
/* after the "#RGB", there are differences - just ignore */
while (*s != '\0' && !isspace(UChar(*s)))
&col, &row,
&r, &g, &b, &nocolor,
&check)) {
+ int which, c;
+
if ((s - t) > 8) /* 6 hex digits vs 8 */
check /= 256;
if (r > MaxRGB ||
static void
init_display(const char *palette_path, int opt_d)
{
+ (void) opt_d;
if (isatty(fileno(stdout))) {
in_curses = TRUE;
initscr();
init_palette(palette_path);
}
scrollok(stdscr, FALSE);
- exit_curses();
+ stop_curses();
}
}
{
int y, x;
int n;
- int my_pair, my_color;
debugmsg("called show_picture");
logmsg("...using %dx%d screen", LINES, COLS);
if (has_colors()) {
logmsg("...using %d colors", pics->colors);
for (n = 0; n < pics->colors; ++n) {
- my_pair = (n + 1);
- my_color = map_color(fg_color(pics, n));
+ int my_pair = (n + 1);
+ int my_color = map_color(fg_color(pics, n));
#if USE_EXTENDED_COLORS
if (use_extended_pairs) {
init_extended_pair(my_pair, my_color, my_color);
if (y >= LINES)
break;
move(y, 0);
+
for (x = 0; x < pics->wide; ++x) {
+ int my_pair;
+
if (x >= COLS)
break;
n = (y * pics->wide + x);
static void
report_colors(PICS_HEAD * pics)
{
- int j, k;
- int high;
- int wide = 4;
int accum;
double level;
+ int j;
int shift;
int total;
char buffer[256];
*/
if (debugging && (pics->colors < 1000)) {
int digits = 0;
+ int high;
+ int wide = 4;
for (j = pics->colors; j != 0; j /= 10) {
++digits;
if (j < 10)
logmsg("These colors were used:");
high = (pics->colors + wide - 1) / wide;
for (j = 0; j < high && j < pics->colors; ++j) {
+ int k;
char *s = buffer;
*s = '\0';
for (k = 0; k < wide; ++k) {
int n = j + (k * high);
size_t want = (sizeof(buffer) - (size_t) (s - buffer));
- if (want < 100)
+ if (want < 100 || want >= sizeof(buffer))
break;
if (n >= pics->colors)
break;