blob: 621dd41720003477b070353ed4274da1e8a22bf9 [file] [log] [blame]
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +00001
2#ifndef Py_CURSES_H
3#define Py_CURSES_H
4
5#ifdef HAVE_NCURSES_H
6#include <ncurses.h>
7#else
8#include <curses.h>
Martin v. Löwis69532332001-10-13 09:12:41 +00009#ifdef HAVE_TERM_H
10/* for tigetstr, which is not declared in SysV curses */
11#include <term.h>
12#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000013#endif
14
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000015#ifdef HAVE_NCURSES_H
16/* configure was checking <curses.h>, but we will
17 use <ncurses.h>, which has all these features. */
18#ifndef WINDOW_HAS_FLAGS
19#define WINDOW_HAS_FLAGS 1
20#endif
21#ifndef MVWDELCH_IS_EXPRESSION
22#define MVWDELCH_IS_EXPRESSION 1
23#endif
24#endif
25
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000026#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define PyCurses_API_pointers 4
31
32/* Type declarations */
33
34typedef struct {
35 PyObject_HEAD
36 WINDOW *win;
37} PyCursesWindowObject;
38
39#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
40
41#ifdef CURSES_MODULE
42/* This section is used when compiling _cursesmodule.c */
43
44#else
45/* This section is used in modules that use the _cursesmodule API */
46
47static void **PyCurses_API;
48
49#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
50#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
51#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
52#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
53
54#define import_curses() \
55{ \
56 PyObject *module = PyImport_ImportModule("_curses"); \
57 if (module != NULL) { \
58 PyObject *module_dict = PyModule_GetDict(module); \
59 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
60 if (PyCObject_Check(c_api_object)) { \
61 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
62 } \
63 } \
64}
65#endif
66
67/* general error messages */
68static char *catchall_ERR = "curses function returned ERR";
69static char *catchall_NULL = "curses function returned NULL";
70
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000071/* Function Prototype Macros - They are ugly but very, very useful. ;-)
72
73 X - function name
74 TYPE - parameter Type
75 ERGSTR - format string for construction of the return value
76 PARSESTR - format string for argument parsing
77 */
78
79#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000080static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000081{ \
82 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000083 return PyCursesCheckERR(X(), # X); }
84
85#define NoArgOrFlagNoReturnFunction(X) \
86static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
87{ \
88 int flag = 0; \
89 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000090 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000091 case 0: \
92 return PyCursesCheckERR(X(), # X); \
93 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000094 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000095 if (flag) return PyCursesCheckERR(X(), # X); \
96 else return PyCursesCheckERR(no ## X (), # X); \
97 default: \
98 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
99 return NULL; } }
100
101#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000102static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000103{ \
104 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000105 return PyInt_FromLong((long) X()); }
106
107
108#define NoArgReturnStringFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000109static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000110{ \
111 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000112 return PyString_FromString(X()); }
113
114#define NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000115static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000116{ \
117 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000118 if (X () == FALSE) { \
119 Py_INCREF(Py_False); \
120 return Py_False; \
121 } \
122 Py_INCREF(Py_True); \
123 return Py_True; }
124
125#define NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000126static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000127{ \
128 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000129 X(); \
130 Py_INCREF(Py_None); \
131 return Py_None; }
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* !defined(Py_CURSES_H) */
138
139