/****************************************************************************
- * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc. *
+ * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 1998-2016,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 *
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_color.c,v 1.138 2018/05/16 08:24:08 tom Exp $")
+MODULE_ID("$Id: lib_color.c,v 1.146 2021/02/14 00:17:09 tom Exp $")
#ifdef USE_TERM_DRIVER
#define CanChange InfoOf(SP_PARM).canchange
#endif
/* *INDENT-ON* */
-
#if NCURSES_EXT_FUNCS
/*
* These are called from _nc_do_color(), which in turn is called from
if (set_a_background) {
TPUTS_TRACE("set_a_background");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
- TPARM_1(set_a_background, bg),
+ TIPARM_1(set_a_background, bg),
1, outc);
} else {
TPUTS_TRACE("set_background");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
- TPARM_1(set_background, toggled_colors(bg)),
+ TIPARM_1(set_background, toggled_colors(bg)),
1, outc);
}
#endif
if (set_a_foreground) {
TPUTS_TRACE("set_a_foreground");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
- TPARM_1(set_a_foreground, fg),
+ TIPARM_1(set_a_foreground, fg),
1, outc);
} else {
TPUTS_TRACE("set_foreground");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
- TPARM_1(set_foreground, toggled_colors(fg)),
+ TIPARM_1(set_foreground, toggled_colors(fg)),
1, outc);
}
#endif
{
static NCURSES_CONST char name[] = "RGB";
- int n;
- const char *s;
- int width;
rgb_bits_t *result = &(SP_PARM->_direct_color);
result->value = 0;
if (COLORS >= 8) {
+ int n;
+ const char *s;
+ int width;
+
/* find the number of bits needed for the maximum color value */
for (width = 0; (1 << width) - 1 < (COLORS - 1); ++width) {
;
NCURSES_SP_NAME(start_color) (NCURSES_SP_DCL0)
{
int result = ERR;
- int maxpairs = 0, maxcolors = 0;
T((T_CALLED("start_color(%p)"), (void *) SP_PARM));
} else if (SP_PARM->_coloron) {
result = OK;
} else {
- maxpairs = MaxPairs;
- maxcolors = MaxColors;
+ int maxpairs = MaxPairs;
+ int maxcolors = MaxColors;
if (reset_color_pair(NCURSES_SP_ARG) != TRUE) {
set_foreground_color(NCURSES_SP_ARGx
default_fg(NCURSES_SP_ARG),
* allow for default-color as a component of a color-pair.
*/
SP_PARM->_pair_limit += (1 + (2 * maxcolors));
+#if !NCURSES_EXT_COLORS
SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);
#endif
+#endif /* NCURSES_EXT_FUNCS */
SP_PARM->_pair_count = maxpairs;
SP_PARM->_color_count = maxcolors;
#if !USE_REENTRANT
COLORS = maxcolors;
#endif
- _nc_reserve_pairs(SP_PARM, 16);
+ ReservePairs(SP_PARM, 16);
if (SP_PARM->_color_pairs != 0) {
if (init_direct_colors(NCURSES_SP_ARG)) {
result = OK;
}
}
-NCURSES_EXPORT(colorpair_t *)
+NCURSES_EXPORT(void)
_nc_reserve_pairs(SCREEN *sp, int want)
{
- colorpair_t *result = 0;
int have = sp->_pair_alloc;
- if ((sp->_color_pairs != 0) && (want < sp->_pair_alloc)) {
- result = &(sp->_color_pairs[want]);
- } else {
-
- if (have == 0)
- have = 1;
- while (have <= want)
- have *= 2;
- if (have > sp->_pair_limit)
- have = sp->_pair_limit;
+ if (have == 0)
+ have = 1;
+ while (have <= want)
+ have *= 2;
+ if (have > sp->_pair_limit)
+ have = sp->_pair_limit;
- if (sp->_color_pairs == 0) {
- sp->_color_pairs = TYPE_CALLOC(colorpair_t, have);
- } else if (have > sp->_pair_alloc) {
+ if (sp->_color_pairs == 0) {
+ sp->_color_pairs = TYPE_CALLOC(colorpair_t, have);
+ } else if (have > sp->_pair_alloc) {
#if NCURSES_EXT_COLORS
- colorpair_t *next;
-
- if ((next = typeCalloc(colorpair_t, have)) == 0)
- _nc_err_abort(MSG_NO_MEMORY);
- memcpy(next, sp->_color_pairs, (size_t) sp->_pair_alloc * sizeof(*next));
- _nc_copy_pairs(sp, next, sp->_color_pairs, sp->_pair_alloc);
- free(sp->_color_pairs);
- sp->_color_pairs = next;
+ colorpair_t *next;
+
+ if ((next = typeCalloc(colorpair_t, have)) == 0)
+ _nc_err_abort(MSG_NO_MEMORY);
+ memcpy(next, sp->_color_pairs, (size_t) sp->_pair_alloc * sizeof(*next));
+ _nc_copy_pairs(sp, next, sp->_color_pairs, sp->_pair_alloc);
+ free(sp->_color_pairs);
+ sp->_color_pairs = next;
#else
- TYPE_REALLOC(colorpair_t, have, sp->_color_pairs);
- if (sp->_color_pairs != 0) {
- memset(sp->_color_pairs + sp->_pair_alloc, 0,
- sizeof(colorpair_t) * (size_t) (have - sp->_pair_alloc));
- }
-#endif
- }
+ TYPE_REALLOC(colorpair_t, have, sp->_color_pairs);
if (sp->_color_pairs != 0) {
- sp->_pair_alloc = have;
- result = &(sp->_color_pairs[want]);
+ memset(sp->_color_pairs + sp->_pair_alloc, 0,
+ sizeof(colorpair_t) * (size_t) (have - sp->_pair_alloc));
}
+#endif
+ }
+ if (sp->_color_pairs != 0) {
+ sp->_pair_alloc = have;
}
- return result;
}
/*
maxcolors = MaxColors;
- _nc_reserve_pairs(sp, pair);
+ ReservePairs(sp, pair);
previous = sp->_color_pairs[pair];
#if NCURSES_EXT_FUNCS
if (sp->_default_color || sp->_assumed_color) {
(int) tp[b].red, (int) tp[b].green, (int) tp[b].blue));
NCURSES_PUTP2("initialize_pair",
- TPARM_7(initialize_pair,
- pair,
- (int) tp[f].red,
- (int) tp[f].green,
- (int) tp[f].blue,
- (int) tp[b].red,
- (int) tp[b].green,
- (int) tp[b].blue));
+ TIPARM_7(initialize_pair,
+ pair,
+ (int) tp[f].red,
+ (int) tp[f].green,
+ (int) tp[f].blue,
+ (int) tp[b].red,
+ (int) tp[b].green,
+ (int) tp[b].blue));
}
#endif
CallDriver_4(sp, td_initcolor, color, r, g, b);
#else
NCURSES_PUTP2("initialize_color",
- TPARM_4(initialize_color, color, r, g, b));
+ TIPARM_4(initialize_color, color, r, g, b));
#endif
sp->_color_defs = max(color + 1, sp->_color_defs);
int code = FALSE;
(void) SP_PARM;
- T((T_CALLED("has_colors()")));
+ T((T_CALLED("has_colors(%p)"), (void *) SP_PARM));
if (HasTerminal(SP_PARM)) {
#ifdef USE_TERM_DRIVER
code = HasColor;
int fg;
int bg;
- _nc_reserve_pairs(sp, pair);
+ ReservePairs(sp, pair);
fg = FORE_OF(sp->_color_pairs[pair]);
bg = BACK_OF(sp->_color_pairs[pair]);
#if NCURSES_EXT_FUNCS
if (set_color_pair) {
TPUTS_TRACE("set_color_pair");
NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
- TPARM_1(set_color_pair, pair),
+ TIPARM_1(set_color_pair, pair),
1, outc);
return;
} else if (SP_PARM != 0) {
free(SP_PARM->_color_pairs);
SP_PARM->_color_pairs = 0;
SP_PARM->_pair_alloc = 0;
- _nc_reserve_pairs(SP_PARM, 16);
+ ReservePairs(SP_PARM, 16);
clearok(CurScreen(SP_PARM), TRUE);
touchwin(StdScreen(SP_PARM));
}