+#if !NCURSES_EXT_COLORS
+ /*
+ * Without ext-colors, we cannot represent more than 256 color pairs.
+ */
+ if (maxpairs > 256)
+ maxpairs = 256;
+#endif
+
+ if (maxpairs > 0 && maxcolors > 0) {
+ SP_PARM->_pair_limit = maxpairs;
+
+#if NCURSES_EXT_FUNCS
+ /*
+ * If using default colors, allocate extra space in table to
+ * allow for default-color as a component of a color-pair.
+ */
+ SP_PARM->_pair_limit += (1 + (2 * maxcolors));
+#endif
+ SP_PARM->_pair_count = maxpairs;
+ SP_PARM->_color_count = maxcolors;
+#if !USE_REENTRANT
+ COLOR_PAIRS = maxpairs;
+ COLORS = maxcolors;
+#endif
+
+ SP_PARM->_color_pairs = TYPE_CALLOC(colorpair_t, SP_PARM->_pair_limit);
+ if (SP_PARM->_color_pairs != 0) {
+ SP_PARM->_color_table = TYPE_CALLOC(color_t, maxcolors);
+ if (SP_PARM->_color_table != 0) {
+ SP_PARM->_color_pairs[0] = PAIR_OF(default_fg(NCURSES_SP_ARG),
+ default_bg(NCURSES_SP_ARG));
+ init_color_table(NCURSES_SP_ARG);
+
+ T(("started color: COLORS = %d, COLOR_PAIRS = %d",
+ COLORS, COLOR_PAIRS));
+
+ SP_PARM->_coloron = 1;
+ result = OK;
+ } else if (SP_PARM->_color_pairs != 0) {
+ FreeAndNull(SP_PARM->_color_pairs);
+ }
+ }
+ } else {
+ result = OK;
+ }
+ }
+ returnCode(result);
+}