+/*
+ * Reset color pairs and definitions. Actually we do both more to accommodate
+ * badly-written terminal descriptions than for the relatively rare case where
+ * someone has changed the color definitions.
+ */
+NCURSES_EXPORT(bool)
+NCURSES_SP_NAME(_nc_reset_colors) (NCURSES_SP_DCL0)
+{
+ int result = FALSE;
+
+ T((T_CALLED("_nc_reset_colors(%p)"), (void *) SP_PARM));
+ if (SP_PARM->_color_defs > 0)
+ SP_PARM->_color_defs = -(SP_PARM->_color_defs);
+ if (reset_color_pair(NCURSES_SP_ARG))
+ result = TRUE;
+
+#ifdef USE_TERM_DRIVER
+ result = CallDriver(SP_PARM, rescolors);
+#else
+ if (orig_colors != 0) {
+ NCURSES_PUTP2("orig_colors", orig_colors);
+ result = TRUE;
+ }
+#endif
+ returnBool(result);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(bool)
+_nc_reset_colors(void)
+{
+ return NCURSES_SP_NAME(_nc_reset_colors) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+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));
+
+ if (SP_PARM == 0) {
+ result = ERR;
+ } else if (SP_PARM->_coloron) {
+ result = OK;
+ } else {
+ maxpairs = MaxPairs;
+ maxcolors = MaxColors;
+ if (reset_color_pair(NCURSES_SP_ARG) != TRUE) {
+ set_foreground_color(NCURSES_SP_ARGx
+ default_fg(NCURSES_SP_ARG),
+ NCURSES_SP_NAME(_nc_outch));
+ set_background_color(NCURSES_SP_ARGx
+ default_bg(NCURSES_SP_ARG),
+ NCURSES_SP_NAME(_nc_outch));
+ }
+#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;