- unsigned result;
-
- T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b));
-
- if ((pair < 1) || (pair >= COLOR_PAIRS))
- returnCode(ERR);
- if (SP->_default_color)
- {
- if (f < 0)
- f = C_MASK;
- if (b < 0)
- b = C_MASK;
- if (f >= COLORS && f != C_MASK)
- returnCode(ERR);
- if (b >= COLORS && b != C_MASK)
- returnCode(ERR);
- }
- else
- if ((f < 0) || (f >= COLORS)
- || (b < 0) || (b >= COLORS))
- returnCode(ERR);
-
- /*
- * When a pair's content is changed, replace its colors (if pair was
- * initialized before a screen update is performed replacing original
- * pair colors with the new ones).
- */
- result = PAIR_OF(f,b);
- if (SP->_color_pairs[pair] != 0
- && SP->_color_pairs[pair] != result) {
- int y, x;
- attr_t z = COLOR_PAIR(pair);
-
- for (y = 0; y <= curscr->_maxy; y++) {
- struct ldat *ptr = &(curscr->_line[y]);
- bool changed = FALSE;
- for (x = 0; x <= curscr->_maxx; x++) {
- if ((ptr->text[x] & A_COLOR) == z) {
- /* Set the old cell to zero to ensure it will be
- updated on the next doupdate() */
- ptr->text[x] = 0;
- CHANGED_CELL(ptr,x);
- changed = TRUE;
- }
+ colorpair_t result;
+
+ T((T_CALLED("init_pair(%d,%d,%d)"), pair, f, b));
+
+ if ((pair < 0) || (pair >= COLOR_PAIRS) || SP == 0 || !SP->_coloron)
+ returnCode(ERR);
+#if NCURSES_EXT_FUNCS
+ if (SP->_default_color) {
+ if (f < 0)
+ f = COLOR_DEFAULT;
+ if (b < 0)
+ b = COLOR_DEFAULT;
+ if (!OkColorHi(f) && !isDefaultColor(f))
+ returnCode(ERR);
+ if (!OkColorHi(b) && !isDefaultColor(b))
+ returnCode(ERR);
+ } else
+#endif
+ {
+ if ((f < 0) || !OkColorHi(f)
+ || (b < 0) || !OkColorHi(b)
+ || (pair < 1))
+ returnCode(ERR);
+ }
+
+ /*
+ * When a pair's content is changed, replace its colors (if pair was
+ * initialized before a screen update is performed replacing original
+ * pair colors with the new ones).
+ */
+ result = PAIR_OF(f, b);
+ if (SP->_color_pairs[pair] != 0
+ && SP->_color_pairs[pair] != result) {
+ int y, x;
+
+ for (y = 0; y <= curscr->_maxy; y++) {
+ struct ldat *ptr = &(curscr->_line[y]);
+ bool changed = FALSE;
+ for (x = 0; x <= curscr->_maxx; x++) {
+ if (GetPair(ptr->text[x]) == pair) {
+ /* Set the old cell to zero to ensure it will be
+ updated on the next doupdate() */
+ SetChar(ptr->text[x], 0, 0);
+ CHANGED_CELL(ptr, x);
+ changed = TRUE;