/****************************************************************************
- * Copyright (c) 2017,2018 Free Software Foundation, Inc. *
+ * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 2017 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 *
#endif
-MODULE_ID("$Id: new_pair.c,v 1.15 2018/03/01 15:02:12 tom Exp $")
+MODULE_ID("$Id: new_pair.c,v 1.23 2021/08/16 22:11:26 tom Exp $")
#if NCURSES_EXT_COLORS
char bigbuf[256 * 20];
char *p = bigbuf;
int n;
- sprintf(p, "%s", tag);
- p += strlen(p);
- for (n = 0; n < sp->_pair_limit; ++n) {
+ size_t have = sizeof(bigbuf);
+
+ _nc_STRCPY(p, tag, have);
+ for (n = 0; n < sp->_pair_alloc; ++n) {
if (list[n].mode != cpFREE) {
- sprintf(p, " %d%c(%d,%d)",
- n, n == pair ? '@' : ':', list[n].next, list[n].prev);
p += strlen(p);
+ if ((size_t) (p - bigbuf) + 50 > have)
+ break;
+ _nc_SPRINTF(p, _nc_SLIMIT(have - (p - bigbuf))
+ " %d%c(%d,%d)",
+ n, n == pair ? '@' : ':', list[n].next, list[n].prev);
}
}
T(("(%d/%d) %ld - %s",
_nc_find_color_pair(SCREEN *sp, int fg, int bg)
{
colorpair_t find;
- int result;
- void *pp;
+ int result = -1;
find.fg = fg;
find.bg = bg;
- if (sp != 0 &&
- (pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) {
- colorpair_t *temp = *(colorpair_t **) pp;
- result = (int) (temp - sp->_color_pairs);
- } else {
- result = -1;
+ if (sp != 0) {
+ void *pp;
+ if ((pp = tfind(&find, &sp->_ordered_pairs, compare_data)) != 0) {
+ colorpair_t *temp = *(colorpair_t **) pp;
+ result = (int) (temp - sp->_color_pairs);
+ }
}
return result;
}
_nc_reset_color_pair(SCREEN *sp, int pair, colorpair_t * next)
{
colorpair_t *last;
+
if (ValidPair(sp, pair)) {
- last = _nc_reserve_pairs(sp, pair);
+ bool used;
+
+ ReservePairs(sp, pair);
+ last = &(sp->_color_pairs[pair]);
delink_color_pair(sp, pair);
if (last->mode > cpFREE &&
(last->fg != next->fg || last->bg != next->bg)) {
/* remove the old entry from fast index */
tdelete(last, &sp->_ordered_pairs, compare_data);
+ used = FALSE;
+ } else {
+ used = (last->mode != cpFREE);
+ }
+ if (!used) {
/* create a new entry in fast index */
*last = *next;
tsearch(last, &sp->_ordered_pairs, compare_data);
}
if (!found && (SP_PARM->_pair_alloc < SP_PARM->_pair_limit)) {
pair = SP_PARM->_pair_alloc;
- if (_nc_reserve_pairs(sp, pair) == 0) {
+ ReservePairs(SP_PARM, pair);
+ if (SP_PARM->_color_pairs == 0) {
pair = -1;
} else {
found = TRUE;
}
}
- if (!found) {
+ if (!found && SP_PARM->_color_pairs != NULL) {
for (pair = 1; pair <= hint; pair++) {
if (SP_PARM->_color_pairs[pair].mode == cpFREE) {
T(("found gap %d", pair));