7 ** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
8 ** against multiple definition of wchar_t.
10 #ifdef _BSD_WCHAR_T_DEFINED_
14 /* the following define is necessary for OS X 10.6; without it, the
15 Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
16 can't get at the WINDOW flags field. */
17 #define NCURSES_OPAQUE 0
18 #endif /* __APPLE__ */
22 ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
23 ** against multiple definition of wchar_t and wint_t.
25 #ifdef _XOPEN_SOURCE_EXTENDED
26 #ifndef __FreeBSD_version
27 #include <osreldate.h>
29 #if __FreeBSD_version >= 500000
52 /* for tigetstr, which is not declared in SysV curses */
58 /* configure was checking <curses.h>, but we will
59 use <ncurses.h>, which has all these features. */
60 #ifndef WINDOW_HAS_FLAGS
61 #define WINDOW_HAS_FLAGS 1
63 #ifndef MVWDELCH_IS_EXPRESSION
64 #define MVWDELCH_IS_EXPRESSION 1
72 #define PyCurses_API_pointers 4
74 /* Type declarations */
79 } PyCursesWindowObject
;
81 #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
84 /* This section is used when compiling _cursesmodule.c */
87 /* This section is used in modules that use the _cursesmodule API */
89 static void **PyCurses_API
;
91 #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
92 #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
93 #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
94 #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
96 #define import_curses() \
98 PyObject *module = PyImport_ImportModuleNoBlock("_curses"); \
99 if (module != NULL) { \
100 PyObject *module_dict = PyModule_GetDict(module); \
101 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
102 if (PyCObject_Check(c_api_object)) { \
103 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
109 /* general error messages */
110 static char *catchall_ERR
= "curses function returned ERR";
111 static char *catchall_NULL
= "curses function returned NULL";
113 /* Function Prototype Macros - They are ugly but very, very useful. ;-)
116 TYPE - parameter Type
117 ERGSTR - format string for construction of the return value
118 PARSESTR - format string for argument parsing
121 #define NoArgNoReturnFunction(X) \
122 static PyObject *PyCurses_ ## X (PyObject *self) \
124 PyCursesInitialised \
125 return PyCursesCheckERR(X(), # X); }
127 #define NoArgOrFlagNoReturnFunction(X) \
128 static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
131 PyCursesInitialised \
132 switch(PyTuple_Size(args)) { \
134 return PyCursesCheckERR(X(), # X); \
136 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
137 if (flag) return PyCursesCheckERR(X(), # X); \
138 else return PyCursesCheckERR(no ## X (), # X); \
140 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
143 #define NoArgReturnIntFunction(X) \
144 static PyObject *PyCurses_ ## X (PyObject *self) \
146 PyCursesInitialised \
147 return PyInt_FromLong((long) X()); }
150 #define NoArgReturnStringFunction(X) \
151 static PyObject *PyCurses_ ## X (PyObject *self) \
153 PyCursesInitialised \
154 return PyString_FromString(X()); }
156 #define NoArgTrueFalseFunction(X) \
157 static PyObject *PyCurses_ ## X (PyObject *self) \
159 PyCursesInitialised \
160 if (X () == FALSE) { \
161 Py_INCREF(Py_False); \
164 Py_INCREF(Py_True); \
167 #define NoArgNoReturnVoidFunction(X) \
168 static PyObject *PyCurses_ ## X (PyObject *self) \
170 PyCursesInitialised \
172 Py_INCREF(Py_None); \
179 #endif /* !defined(Py_CURSES_H) */