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