+#define MAX_OF_TYPE(t) (int)(((unsigned t)(~0))>>1)
+#define LIMIT_TYPED(n,t) (t)(((t)(n) < 0) ? MAX_OF_TYPE(t) : (n))
+
+#define limit_COLOR(n) LIMIT_TYPED(n,NCURSES_COLOR_T)
+#define limit_PAIRS(n) LIMIT_TYPED(n,NCURSES_PAIRS_T)
+
+#define MAX_XCURSES_PAIR MAX_OF_TYPE(NCURSES_PAIRS_T)
+
+#if USE_NEW_PAIR
+#define OPTIONAL_PAIR GCC_UNUSED
+#define USE_NEW_PAIR NCURSES_EXT_COLORS
+#define get_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ *(int*)(opts) = color_pair; \
+ }
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = *(const int*)(opts); \
+ }
+#else
+#define OPTIONAL_PAIR /* nothing */
+#define USE_NEW_PAIR NCURSES_EXT_COLORS
+#define get_extended_pair(opts, color_pair) /* nothing */
+#define set_extended_pair(opts, color_pair) \
+ if ((opts) != NULL) { \
+ color_pair = -1; \
+ }
+#endif
+