• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef Py_CURSES_H
3 #define Py_CURSES_H
4 
5 #ifdef __APPLE__
6 /*
7 ** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
8 ** against multiple definition of wchar_t.
9 */
10 #ifdef _BSD_WCHAR_T_DEFINED_
11 #define _WCHAR_T
12 #endif
13 #endif /* __APPLE__ */
14 
15 /* On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
16    against multiple definition of wchar_t and wint_t. */
17 #if defined(__FreeBSD__) && defined(_XOPEN_SOURCE_EXTENDED)
18 # ifndef __wchar_t
19 #   define __wchar_t
20 # endif
21 # ifndef __wint_t
22 #   define __wint_t
23 # endif
24 #endif
25 
26 #if defined(WINDOW_HAS_FLAGS) && defined(__APPLE__)
27 /* gh-109617, gh-115383: we can rely on the default value for NCURSES_OPAQUE on
28    most platforms, but not on macOS. This is because, starting with Xcode 15,
29    Apple-provided ncurses.h comes from ncurses 6 (which defaults to opaque
30    structs) but can still be linked to older versions of ncurses dynamic
31    libraries which don't provide functions such as is_pad() to deal with opaque
32    structs. Setting NCURSES_OPAQUE to 0 is harmless in all ncurses releases to
33    this date (provided that a thread-safe implementation is not required), but
34    this might change in the future. This fix might become irrelevant once
35    support for macOS 13 or earlier is dropped. */
36 #define NCURSES_OPAQUE 0
37 #endif
38 
39 #if defined(HAVE_NCURSESW_NCURSES_H)
40 #  include <ncursesw/ncurses.h>
41 #elif defined(HAVE_NCURSESW_CURSES_H)
42 #  include <ncursesw/curses.h>
43 #elif defined(HAVE_NCURSES_NCURSES_H)
44 #  include <ncurses/ncurses.h>
45 #elif defined(HAVE_NCURSES_CURSES_H)
46 #  include <ncurses/curses.h>
47 #elif defined(HAVE_NCURSES_H)
48 #  include <ncurses.h>
49 #elif defined(HAVE_CURSES_H)
50 #  include <curses.h>
51 #endif
52 
53 #ifdef NCURSES_VERSION
54 /* configure was checking <curses.h>, but we will
55    use <ncurses.h>, which has some or all these features. */
56 #if !defined(WINDOW_HAS_FLAGS) && \
57     (NCURSES_VERSION_PATCH+0 < 20070303 || !(NCURSES_OPAQUE+0))
58 /* the WINDOW flags field was always accessible in ncurses prior to 20070303;
59    after that, it depends on the value of NCURSES_OPAQUE. */
60 #define WINDOW_HAS_FLAGS 1
61 #endif
62 #if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906
63 #define HAVE_CURSES_IS_PAD 1
64 #endif
65 #ifndef MVWDELCH_IS_EXPRESSION
66 #define MVWDELCH_IS_EXPRESSION 1
67 #endif
68 #endif
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 #define PyCurses_API_pointers 4
75 
76 /* Type declarations */
77 
78 typedef struct {
79     PyObject_HEAD
80     WINDOW *win;
81     char *encoding;
82 } PyCursesWindowObject;
83 
84 #define PyCursesWindow_Check(v) Py_IS_TYPE((v), &PyCursesWindow_Type)
85 
86 #define PyCurses_CAPSULE_NAME "_curses._C_API"
87 
88 
89 #ifdef CURSES_MODULE
90 /* This section is used when compiling _cursesmodule.c */
91 
92 #else
93 /* This section is used in modules that use the _cursesmodule API */
94 
95 static void **PyCurses_API;
96 
97 #define PyCursesWindow_Type (*_PyType_CAST(PyCurses_API[0]))
98 #define PyCursesSetupTermCalled  {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
99 #define PyCursesInitialised      {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
100 #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
101 
102 #define import_curses() \
103     PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
104 
105 #endif
106 
107 /* general error messages */
108 static const char catchall_ERR[]  = "curses function returned ERR";
109 static const char catchall_NULL[] = "curses function returned NULL";
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* !defined(Py_CURSES_H) */
116 
117