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