- Got rid of newmodule.c
[python/dscho.git] / Include / py_curses.h
blob621dd41720003477b070353ed4274da1e8a22bf9
2 #ifndef Py_CURSES_H
3 #define Py_CURSES_H
5 #ifdef HAVE_NCURSES_H
6 #include <ncurses.h>
7 #else
8 #include <curses.h>
9 #ifdef HAVE_TERM_H
10 /* for tigetstr, which is not declared in SysV curses */
11 #include <term.h>
12 #endif
13 #endif
15 #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
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 #define PyCurses_API_pointers 4
32 /* Type declarations */
34 typedef struct {
35 PyObject_HEAD
36 WINDOW *win;
37 } PyCursesWindowObject;
39 #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
41 #ifdef CURSES_MODULE
42 /* This section is used when compiling _cursesmodule.c */
44 #else
45 /* This section is used in modules that use the _cursesmodule API */
47 static void **PyCurses_API;
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;}
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 } \
65 #endif
67 /* general error messages */
68 static char *catchall_ERR = "curses function returned ERR";
69 static char *catchall_NULL = "curses function returned NULL";
71 /* Function Prototype Macros - They are ugly but very, very useful. ;-)
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
79 #define NoArgNoReturnFunction(X) \
80 static PyObject *PyCurses_ ## X (PyObject *self) \
81 { \
82 PyCursesInitialised \
83 return PyCursesCheckERR(X(), # X); }
85 #define NoArgOrFlagNoReturnFunction(X) \
86 static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
87 { \
88 int flag = 0; \
89 PyCursesInitialised \
90 switch(PyTuple_Size(args)) { \
91 case 0: \
92 return PyCursesCheckERR(X(), # X); \
93 case 1: \
94 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
95 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; } }
101 #define NoArgReturnIntFunction(X) \
102 static PyObject *PyCurses_ ## X (PyObject *self) \
104 PyCursesInitialised \
105 return PyInt_FromLong((long) X()); }
108 #define NoArgReturnStringFunction(X) \
109 static PyObject *PyCurses_ ## X (PyObject *self) \
111 PyCursesInitialised \
112 return PyString_FromString(X()); }
114 #define NoArgTrueFalseFunction(X) \
115 static PyObject *PyCurses_ ## X (PyObject *self) \
117 PyCursesInitialised \
118 if (X () == FALSE) { \
119 Py_INCREF(Py_False); \
120 return Py_False; \
122 Py_INCREF(Py_True); \
123 return Py_True; }
125 #define NoArgNoReturnVoidFunction(X) \
126 static PyObject *PyCurses_ ## X (PyObject *self) \
128 PyCursesInitialised \
129 X(); \
130 Py_INCREF(Py_None); \
131 return Py_None; }
133 #ifdef __cplusplus
135 #endif
137 #endif /* !defined(Py_CURSES_H) */