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
|
---|
14 |
|
---|
15 | #ifdef __FreeBSD__
|
---|
16 | /*
|
---|
17 | ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
|
---|
18 | ** against multiple definition of wchar_t and wint_t.
|
---|
19 | */
|
---|
20 | #ifdef _XOPEN_SOURCE_EXTENDED
|
---|
21 | #ifndef __FreeBSD_version
|
---|
22 | #include <osreldate.h>
|
---|
23 | #endif
|
---|
24 | #if __FreeBSD_version >= 500000
|
---|
25 | #ifndef __wchar_t
|
---|
26 | #define __wchar_t
|
---|
27 | #endif
|
---|
28 | #ifndef __wint_t
|
---|
29 | #define __wint_t
|
---|
30 | #endif
|
---|
31 | #else
|
---|
32 | #ifndef _WCHAR_T
|
---|
33 | #define _WCHAR_T
|
---|
34 | #endif
|
---|
35 | #ifndef _WINT_T
|
---|
36 | #define _WINT_T
|
---|
37 | #endif
|
---|
38 | #endif
|
---|
39 | #endif
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifdef HAVE_NCURSES_H
|
---|
43 | #include <ncurses.h>
|
---|
44 | #else
|
---|
45 | #include <curses.h>
|
---|
46 | #ifdef HAVE_TERM_H
|
---|
47 | /* for tigetstr, which is not declared in SysV curses */
|
---|
48 | #include <term.h>
|
---|
49 | #endif
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #ifdef HAVE_NCURSES_H
|
---|
53 | /* configure was checking <curses.h>, but we will
|
---|
54 | use <ncurses.h>, which has all these features. */
|
---|
55 | #ifndef WINDOW_HAS_FLAGS
|
---|
56 | #define WINDOW_HAS_FLAGS 1
|
---|
57 | #endif
|
---|
58 | #ifndef MVWDELCH_IS_EXPRESSION
|
---|
59 | #define MVWDELCH_IS_EXPRESSION 1
|
---|
60 | #endif
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #ifdef __cplusplus
|
---|
64 | extern "C" {
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #define PyCurses_API_pointers 4
|
---|
68 |
|
---|
69 | /* Type declarations */
|
---|
70 |
|
---|
71 | typedef struct {
|
---|
72 | PyObject_HEAD
|
---|
73 | WINDOW *win;
|
---|
74 | } PyCursesWindowObject;
|
---|
75 |
|
---|
76 | #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
|
---|
77 |
|
---|
78 | #ifdef CURSES_MODULE
|
---|
79 | /* This section is used when compiling _cursesmodule.c */
|
---|
80 |
|
---|
81 | #else
|
---|
82 | /* This section is used in modules that use the _cursesmodule API */
|
---|
83 |
|
---|
84 | static void **PyCurses_API;
|
---|
85 |
|
---|
86 | #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
|
---|
87 | #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
|
---|
88 | #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
|
---|
89 | #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
|
---|
90 |
|
---|
91 | #define import_curses() \
|
---|
92 | { \
|
---|
93 | PyObject *module = PyImport_ImportModule("_curses"); \
|
---|
94 | if (module != NULL) { \
|
---|
95 | PyObject *module_dict = PyModule_GetDict(module); \
|
---|
96 | PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
|
---|
97 | if (PyCObject_Check(c_api_object)) { \
|
---|
98 | PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
|
---|
99 | } \
|
---|
100 | } \
|
---|
101 | }
|
---|
102 | #endif
|
---|
103 |
|
---|
104 | /* general error messages */
|
---|
105 | static char *catchall_ERR = "curses function returned ERR";
|
---|
106 | static char *catchall_NULL = "curses function returned NULL";
|
---|
107 |
|
---|
108 | /* Function Prototype Macros - They are ugly but very, very useful. ;-)
|
---|
109 |
|
---|
110 | X - function name
|
---|
111 | TYPE - parameter Type
|
---|
112 | ERGSTR - format string for construction of the return value
|
---|
113 | PARSESTR - format string for argument parsing
|
---|
114 | */
|
---|
115 |
|
---|
116 | #define NoArgNoReturnFunction(X) \
|
---|
117 | static PyObject *PyCurses_ ## X (PyObject *self) \
|
---|
118 | { \
|
---|
119 | PyCursesInitialised \
|
---|
120 | return PyCursesCheckERR(X(), # X); }
|
---|
121 |
|
---|
122 | #define NoArgOrFlagNoReturnFunction(X) \
|
---|
123 | static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
|
---|
124 | { \
|
---|
125 | int flag = 0; \
|
---|
126 | PyCursesInitialised \
|
---|
127 | switch(PyTuple_Size(args)) { \
|
---|
128 | case 0: \
|
---|
129 | return PyCursesCheckERR(X(), # X); \
|
---|
130 | case 1: \
|
---|
131 | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
|
---|
132 | if (flag) return PyCursesCheckERR(X(), # X); \
|
---|
133 | else return PyCursesCheckERR(no ## X (), # X); \
|
---|
134 | default: \
|
---|
135 | PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
|
---|
136 | return NULL; } }
|
---|
137 |
|
---|
138 | #define NoArgReturnIntFunction(X) \
|
---|
139 | static PyObject *PyCurses_ ## X (PyObject *self) \
|
---|
140 | { \
|
---|
141 | PyCursesInitialised \
|
---|
142 | return PyInt_FromLong((long) X()); }
|
---|
143 |
|
---|
144 |
|
---|
145 | #define NoArgReturnStringFunction(X) \
|
---|
146 | static PyObject *PyCurses_ ## X (PyObject *self) \
|
---|
147 | { \
|
---|
148 | PyCursesInitialised \
|
---|
149 | return PyString_FromString(X()); }
|
---|
150 |
|
---|
151 | #define NoArgTrueFalseFunction(X) \
|
---|
152 | static PyObject *PyCurses_ ## X (PyObject *self) \
|
---|
153 | { \
|
---|
154 | PyCursesInitialised \
|
---|
155 | if (X () == FALSE) { \
|
---|
156 | Py_INCREF(Py_False); \
|
---|
157 | return Py_False; \
|
---|
158 | } \
|
---|
159 | Py_INCREF(Py_True); \
|
---|
160 | return Py_True; }
|
---|
161 |
|
---|
162 | #define NoArgNoReturnVoidFunction(X) \
|
---|
163 | static PyObject *PyCurses_ ## X (PyObject *self) \
|
---|
164 | { \
|
---|
165 | PyCursesInitialised \
|
---|
166 | X(); \
|
---|
167 | Py_INCREF(Py_None); \
|
---|
168 | return Py_None; }
|
---|
169 |
|
---|
170 | #ifdef __cplusplus
|
---|
171 | }
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #endif /* !defined(Py_CURSES_H) */
|
---|
175 |
|
---|
176 |
|
---|