Index: Modules/_py_curses.h =================================================================== --- Modules/_py_curses.h (revision 57414) +++ Modules/_py_curses.h (working copy) @@ -1,176 +1,47 @@ - #ifndef Py_CURSES_H #define Py_CURSES_H -#ifdef __APPLE__ -/* -** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards -** against multiple definition of wchar_t. -*/ -#ifdef _BSD_WCHAR_T_DEFINED_ -#define _WCHAR_T -#endif -#endif - #ifdef __FreeBSD__ -/* -** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards -** against multiple definition of wchar_t and wint_t. -*/ -#ifdef _XOPEN_SOURCE_EXTENDED -#ifndef __FreeBSD_version -#include + /* + ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards + ** against multiple definition of wchar_t and wint_t. + */ + #ifdef _XOPEN_SOURCE_EXTENDED + #ifndef __FreeBSD_version + #include + #endif + #endif #endif -#if __FreeBSD_version >= 500000 -#ifndef __wchar_t -#define __wchar_t -#endif -#ifndef __wint_t -#define __wint_t -#endif -#else -#ifndef _WCHAR_T -#define _WCHAR_T -#endif -#ifndef _WINT_T -#define _WINT_T -#endif -#endif -#endif -#endif #ifdef HAVE_NCURSES_H -#include + #include #else -#include -#ifdef HAVE_TERM_H -/* for tigetstr, which is not declared in SysV curses */ -#include + #include + #ifdef HAVE_TERM_H + /* for tigetstr, which is not declared in SysV curses */ + #include + #endif #endif -#endif -#ifdef HAVE_NCURSES_H -/* configure was checking , but we will - use , which has all these features. */ -#ifndef WINDOW_HAS_FLAGS -#define WINDOW_HAS_FLAGS 1 -#endif -#ifndef MVWDELCH_IS_EXPRESSION -#define MVWDELCH_IS_EXPRESSION 1 -#endif -#endif #ifdef __cplusplus -extern "C" { + extern "C" { #endif -#define PyCurses_API_pointers 4 - /* Type declarations */ typedef struct { - PyObject_HEAD - WINDOW *win; + PyObject_HEAD + WINDOW *win; } PyCursesWindowObject; -#define PyCursesWindow_Check(v) (Py_Type(v) == &PyCursesWindow_Type) +#define PyCursesWindow_Check(v) (Py_Type(v) == PyCursesWindow_Type) -#ifdef CURSES_MODULE -/* This section is used when compiling _cursesmodule.c */ +extern int PyCurses_IsInitialised(void); -#else -/* This section is used in modules that use the _cursesmodule API */ - -static void **PyCurses_API; - -#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0]) -#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;} -#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;} -#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;} - -#define import_curses() \ -{ \ - PyObject *module = PyImport_ImportModule("_curses"); \ - if (module != NULL) { \ - PyObject *module_dict = PyModule_GetDict(module); \ - PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \ - if (PyCObject_Check(c_api_object)) { \ - PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \ - } \ - } \ -} -#endif - -/* general error messages */ -static char *catchall_ERR = "curses function returned ERR"; -static char *catchall_NULL = "curses function returned NULL"; - -/* Function Prototype Macros - They are ugly but very, very useful. ;-) - - X - function name - TYPE - parameter Type - ERGSTR - format string for construction of the return value - PARSESTR - format string for argument parsing - */ - -#define NoArgNoReturnFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self) \ -{ \ - PyCursesInitialised \ - return PyCursesCheckERR(X(), # X); } - -#define NoArgOrFlagNoReturnFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \ -{ \ - int flag = 0; \ - PyCursesInitialised \ - switch(PyTuple_Size(args)) { \ - case 0: \ - return PyCursesCheckERR(X(), # X); \ - case 1: \ - if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \ - if (flag) return PyCursesCheckERR(X(), # X); \ - else return PyCursesCheckERR(no ## X (), # X); \ - default: \ - PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ - return NULL; } } - -#define NoArgReturnIntFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self) \ -{ \ - PyCursesInitialised \ - return PyInt_FromLong((long) X()); } - - -#define NoArgReturnStringFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self) \ -{ \ - PyCursesInitialised \ - return PyString_FromString(X()); } - -#define NoArgTrueFalseFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self) \ -{ \ - PyCursesInitialised \ - if (X () == FALSE) { \ - Py_INCREF(Py_False); \ - return Py_False; \ - } \ - Py_INCREF(Py_True); \ - return Py_True; } - -#define NoArgNoReturnVoidFunction(X) \ -static PyObject *PyCurses_ ## X (PyObject *self) \ -{ \ - PyCursesInitialised \ - X(); \ - Py_INCREF(Py_None); \ - return Py_None; } - #ifdef __cplusplus } #endif #endif /* !defined(Py_CURSES_H) */ - Index: Modules/_curses_panel.c =================================================================== --- Modules/_curses_panel.c (revision 57414) +++ Modules/_curses_panel.c (working copy) @@ -4,21 +4,22 @@ * Original version by Thomas Gellekum */ -/* Release Number */ -static char *PyCursesVersion = "2.1"; - /* Includes */ #include "Python.h" - -#include "py_curses.h" - +#include "_py_curses.h" #include static PyObject *PyCursesError; +static PyTypeObject *PyCursesWindow_Type = NULL; +static int *initialised = NULL; /* points into _cursesmodule.c */ + +#define PyCurses_IS_INITIALISED() {if (!(initialised && *initialised)) return NULL; } + + /* Utility Functions */ /* @@ -30,15 +31,15 @@ PyCursesCheckERR(int code, char *fname) { if (code != ERR) { - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } else { - if (fname == NULL) { - PyErr_SetString(PyCursesError, catchall_ERR); - } else { - PyErr_Format(PyCursesError, "%s() returned ERR", fname); - } - return NULL; + if (fname == NULL) { + PyErr_SetString(PyCursesError, "_curses_panel function returned ERR"); + } else { + PyErr_Format(PyCursesError, "%s() returned ERR", fname); + } + return NULL; } } @@ -51,12 +52,12 @@ typedef struct { PyObject_HEAD PANEL *pan; - PyCursesWindowObject *wo; /* for reference counts */ + PyCursesWindowObject *wo; /* for reference counts */ } PyCursesPanelObject; PyTypeObject PyCursesPanel_Type; -#define PyCursesPanel_Check(v) (Py_Type(v) == &PyCursesPanel_Type) +#define PyCursesPanel_Check(v) (Py_Type(v) == &PyCursesPanel_Type) /* Some helper functions. The problem is that there's always a window associated with a panel. To ensure that Python's GC doesn't pull @@ -90,8 +91,8 @@ list_of_panels *new; if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) { - PyErr_NoMemory(); - return -1; + PyErr_NoMemory(); + return -1; } new->po = po; new->next = lop; @@ -107,17 +108,17 @@ temp = lop; if (temp->po == po) { - lop = temp->next; - free(temp); - return; + lop = temp->next; + free(temp); + return; } while (temp->next == NULL || temp->next->po != po) { - if (temp->next == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "remove_lop: can't find Panel Object"); - return; - } - temp = temp->next; + if (temp->next == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "remove_lop: can't find Panel Object"); + return; + } + temp = temp->next; } n = temp->next->next; free(temp->next); @@ -131,11 +132,14 @@ { list_of_panels *temp; for (temp = lop; temp->po->pan != pan; temp = temp->next) - if (temp->next == NULL) return NULL; /* not found!? */ + if (temp->next == NULL) + /* not found!? */ + return NULL; return temp->po; } /* Function Prototype Macros - They are ugly but very, very useful. ;-) + s/but very, very/and pretty marginally/ X - function name TYPE - parameter Type @@ -143,21 +147,24 @@ PARSESTR - format string for argument parsing */ #define Panel_NoArgNoReturnFunction(X) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ -{ return PyCursesCheckERR(X(self->pan), # X); } +static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) { \ + return PyCursesCheckERR(X(self->pan), # X); \ +} #define Panel_NoArgTrueFalseFunction(X) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ -{ \ - if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ - else { Py_INCREF(Py_True); return Py_True; } } +static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) { \ + PyObject *rv = (X (self->pan) == FALSE) ? Py_False : Py_True; \ + Py_INCREF(rv); \ + return rv; \ +} #define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \ -{ \ +static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) { \ TYPE arg1, arg2; \ - if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \ - return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); } + if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) \ + return NULL; \ + return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); \ +} /* ------------- PANEL routines --------------- */ @@ -176,13 +183,14 @@ PyCursesPanelObject *po; po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type); - if (po == NULL) return NULL; + if (po == NULL) + return NULL; po->pan = pan; po->wo = wo; Py_INCREF(wo); if (insert_lop(po) < 0) { - PyObject_DEL(po); - return NULL; + PyObject_DEL(po); + return NULL; } return (PyObject *)po; } @@ -206,16 +214,18 @@ pan = panel_above(self->pan); - if (pan == NULL) { /* valid output, it means the calling panel - is on top of the stack */ - Py_INCREF(Py_None); - return Py_None; + if (pan == NULL) { + /* valid output, it means the calling panel + * is on top of the stack + */ + Py_INCREF(Py_None); + return Py_None; } po = find_po(pan); if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_above: can't find Panel Object"); - return NULL; + PyErr_SetString(PyExc_RuntimeError, + "panel_above: can't find Panel Object"); + return NULL; } Py_INCREF(po); return (PyObject *)po; @@ -231,16 +241,17 @@ pan = panel_below(self->pan); - if (pan == NULL) { /* valid output, it means the calling panel - is on the bottom of the stack */ - Py_INCREF(Py_None); - return Py_None; + if (pan == NULL) { + /* valid output, it means the calling panel + * is on the bottom of the stack */ + Py_INCREF(Py_None); + return Py_None; } po = find_po(pan); if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_below: can't find Panel Object"); - return NULL; + PyErr_SetString(PyExc_RuntimeError, + "panel_below: can't find Panel Object"); + return NULL; } Py_INCREF(po); return (PyObject *)po; @@ -261,24 +272,25 @@ int rtn; if (PyTuple_Size(args) != 1) { - PyErr_SetString(PyExc_TypeError, "replace requires one argument"); - return NULL; + PyErr_SetString(PyExc_TypeError, "replace requires one argument"); + return NULL; } if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; + PyCursesWindow_Type, &temp)) { + return NULL; + } po = find_po(self->pan); if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "replace_panel: can't find Panel Object"); - return NULL; + PyErr_SetString(PyExc_RuntimeError, + "replace_panel: can't find Panel Object"); + return NULL; } rtn = replace_panel(self->pan, temp->win); if (rtn == ERR) { - PyErr_SetString(PyCursesError, "replace_panel() returned ERR"); - return NULL; + PyErr_SetString(PyCursesError, "replace_panel() returned ERR"); + return NULL; } Py_DECREF(po->wo); po->wo = temp; @@ -299,11 +311,11 @@ PyCursesPanel_userptr(PyCursesPanelObject *self) { PyObject *obj; - PyCursesInitialised; + PyCurses_IS_INITIALISED(); obj = (PyObject *) panel_userptr(self->pan); if (obj == NULL) { - PyErr_SetString(PyCursesError, "no userptr set"); - return NULL; + PyErr_SetString(PyCursesError, "no userptr set"); + return NULL; } Py_INCREF(obj); @@ -326,7 +338,7 @@ {"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS}, {"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS}, {"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS}, - {NULL, NULL} /* sentinel */ + {NULL, NULL} /* sentinel */ }; static PyObject * @@ -339,20 +351,20 @@ PyTypeObject PyCursesPanel_Type = { PyVarObject_HEAD_INIT(NULL, 0) - "_curses_panel.curses panel", /*tp_name*/ - sizeof(PyCursesPanelObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ + "_curses_panel.curses panel", /*tp_name*/ + sizeof(PyCursesPanelObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ /* methods */ (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ + 0, /*tp_print*/ (getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/ (setattrfunc)0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ }; /* Wrapper for panel_above(NULL). This function returns the bottom @@ -365,20 +377,22 @@ PANEL *pan; PyCursesPanelObject *po; - PyCursesInitialised; + PyCurses_IS_INITIALISED(); pan = panel_above(NULL); - if (pan == NULL) { /* valid output, it means - there's no panel at all */ - Py_INCREF(Py_None); - return Py_None; + if (pan == NULL) { + /* valid output, it means + * there's no panel at all + */ + Py_INCREF(Py_None); + return Py_None; } po = find_po(pan); if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_above: can't find Panel Object"); - return NULL; + PyErr_SetString(PyExc_RuntimeError, + "panel_above: can't find Panel Object"); + return NULL; } Py_INCREF(po); return (PyObject *)po; @@ -390,12 +404,12 @@ PyCursesWindowObject *win; PANEL *pan; - if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win)) + if (!PyArg_ParseTuple(args, "O!", PyCursesWindow_Type, &win)) return NULL; pan = new_panel(win->win); if (pan == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; + PyErr_SetString(PyCursesError, "_curses_panel function returned NULL"); + return NULL; } return (PyObject *)PyCursesPanel_New(pan, win); } @@ -411,20 +425,22 @@ PANEL *pan; PyCursesPanelObject *po; - PyCursesInitialised; + PyCurses_IS_INITIALISED(); pan = panel_below(NULL); - if (pan == NULL) { /* valid output, it means - there's no panel at all */ - Py_INCREF(Py_None); - return Py_None; + if (pan == NULL) { + /* valid output, it means + * there's no panel at all + */ + Py_INCREF(Py_None); + return Py_None; } po = find_po(pan); if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_below: can't find Panel Object"); - return NULL; + PyErr_SetString(PyExc_RuntimeError, + "panel_below: can't find Panel Object"); + return NULL; } Py_INCREF(po); return (PyObject *)po; @@ -432,7 +448,7 @@ static PyObject *PyCurses_update_panels(PyObject *self) { - PyCursesInitialised; + PyCurses_IS_INITIALISED(); update_panels(); Py_INCREF(Py_None); return Py_None; @@ -446,7 +462,7 @@ {"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS}, {"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS}, {"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS}, - {NULL, NULL} /* sentinel */ + {NULL, NULL} /* sentinel */ }; /* Initialization function for the module */ @@ -456,15 +472,30 @@ { PyObject *m, *d, *v; + PyObject *module = PyImport_ImportModule("_curses"); + if (module != NULL) { + PyObject *dict = PyModule_GetDict(module); + PyObject *__initialised = PyDict_GetItemString(dict, "__initialised"); + PyObject *__window_type = PyDict_GetItemString(dict, "__window_type"); + if (PyCObject_Check(__initialised)) { + initialised = (int *)PyCObject_AsVoidPtr(__initialised); + } + if (PyType_Check(__window_type)) { + PyCursesWindow_Type = (PyTypeObject *)__window_type; + } + } + + if (!(initialised && PyCursesWindow_Type)) { + return; + } + /* Initialize object type */ Py_Type(&PyCursesPanel_Type) = &PyType_Type; - import_curses(); - /* Create the module and add the functions */ m = Py_InitModule("_curses_panel", PyCurses_methods); if (m == NULL) - return; + return; d = PyModule_GetDict(m); /* For exception _curses_panel.error */ @@ -472,8 +503,9 @@ PyDict_SetItemString(d, "error", PyCursesError); /* Make the version available */ - v = PyUnicode_FromString(PyCursesVersion); + v = PyUnicode_FromString("2.1"); PyDict_SetItemString(d, "version", v); PyDict_SetItemString(d, "__version__", v); Py_DECREF(v); } + Index: Modules/_cursesmodule.c =================================================================== --- Modules/_cursesmodule.c (revision 57414) +++ Modules/_cursesmodule.c (working copy) @@ -42,56 +42,56 @@ Here's a list of currently unsupported functions: - addchnstr addchstr color_set define_key - del_curterm delscreen dupwin inchnstr inchstr innstr keyok - mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr - mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr - mvwinchnstr mvwinchstr mvwinnstr newterm - restartterm ripoffline scr_dump - scr_init scr_restore scr_set scrl set_curterm set_term setterm - tgetent tgetflag tgetnum tgetstr tgoto timeout tputs - vidattr vidputs waddchnstr waddchstr - wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl + addchnstr addchstr color_set define_key + del_curterm delscreen dupwin inchnstr inchstr innstr keyok + mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr + mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr + mvwinchnstr mvwinchstr mvwinnstr newterm + restartterm ripoffline scr_dump + scr_init scr_restore scr_set scrl set_curterm set_term setterm + tgetent tgetflag tgetnum tgetstr tgoto timeout tputs + vidattr vidputs waddchnstr waddchstr + wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl Low-priority: - slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff - slk_attron slk_attrset slk_clear slk_color slk_init slk_label - slk_noutrefresh slk_refresh slk_restore slk_set slk_touch + slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff + slk_attron slk_attrset slk_clear slk_color slk_init slk_label + slk_noutrefresh slk_refresh slk_restore slk_set slk_touch Menu extension (ncurses and probably SYSV): - current_item free_item free_menu item_count item_description - item_index item_init item_name item_opts item_opts_off - item_opts_on item_term item_userptr item_value item_visible - menu_back menu_driver menu_fore menu_format menu_grey - menu_init menu_items menu_mark menu_opts menu_opts_off - menu_opts_on menu_pad menu_pattern menu_request_by_name - menu_request_name menu_spacing menu_sub menu_term menu_userptr - menu_win new_item new_menu pos_menu_cursor post_menu - scale_menu set_current_item set_item_init set_item_opts - set_item_term set_item_userptr set_item_value set_menu_back - set_menu_fore set_menu_format set_menu_grey set_menu_init - set_menu_items set_menu_mark set_menu_opts set_menu_pad - set_menu_pattern set_menu_spacing set_menu_sub set_menu_term - set_menu_userptr set_menu_win set_top_row top_row unpost_menu + current_item free_item free_menu item_count item_description + item_index item_init item_name item_opts item_opts_off + item_opts_on item_term item_userptr item_value item_visible + menu_back menu_driver menu_fore menu_format menu_grey + menu_init menu_items menu_mark menu_opts menu_opts_off + menu_opts_on menu_pad menu_pattern menu_request_by_name + menu_request_name menu_spacing menu_sub menu_term menu_userptr + menu_win new_item new_menu pos_menu_cursor post_menu + scale_menu set_current_item set_item_init set_item_opts + set_item_term set_item_userptr set_item_value set_menu_back + set_menu_fore set_menu_format set_menu_grey set_menu_init + set_menu_items set_menu_mark set_menu_opts set_menu_pad + set_menu_pattern set_menu_spacing set_menu_sub set_menu_term + set_menu_userptr set_menu_win set_top_row top_row unpost_menu Form extension (ncurses and probably SYSV): - current_field data_ahead data_behind dup_field - dynamic_fieldinfo field_arg field_back field_buffer - field_count field_fore field_index field_info field_init - field_just field_opts field_opts_off field_opts_on field_pad - field_status field_term field_type field_userptr form_driver - form_fields form_init form_opts form_opts_off form_opts_on - form_page form_request_by_name form_request_name form_sub - form_term form_userptr form_win free_field free_form - link_field link_fieldtype move_field new_field new_form - new_page pos_form_cursor post_form scale_form - set_current_field set_field_back set_field_buffer - set_field_fore set_field_init set_field_just set_field_opts - set_field_pad set_field_status set_field_term set_field_type - set_field_userptr set_fieldtype_arg set_fieldtype_choice - set_form_fields set_form_init set_form_opts set_form_page - set_form_sub set_form_term set_form_userptr set_form_win - set_max_field set_new_page unpost_form + current_field data_ahead data_behind dup_field + dynamic_fieldinfo field_arg field_back field_buffer + field_count field_fore field_index field_info field_init + field_just field_opts field_opts_off field_opts_on field_pad + field_status field_term field_type field_userptr form_driver + form_fields form_init form_opts form_opts_off form_opts_on + form_page form_request_by_name form_request_name form_sub + form_term form_userptr form_win free_field free_form + link_field link_fieldtype move_field new_field new_form + new_page pos_form_cursor post_form scale_form + set_current_field set_field_back set_field_buffer + set_field_fore set_field_init set_field_just set_field_opts + set_field_pad set_field_status set_field_term set_field_type + set_field_userptr set_fieldtype_arg set_fieldtype_choice + set_form_fields set_form_init set_form_opts set_form_page + set_form_sub set_form_term set_form_userptr set_form_win + set_max_field set_new_page unpost_form */ @@ -104,17 +104,22 @@ #include "Python.h" -#ifdef __osf__ -#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ -#endif +#include "_py_curses.h" -#ifdef __hpux -#define STRICT_SYSV_CURSES + +#ifdef HAVE_NCURSES_H +/* configure was checking , but we will + use , which has all these features. */ +#ifndef WINDOW_HAS_FLAGS +#define WINDOW_HAS_FLAGS 1 #endif +#endif -#define CURSES_MODULE -#include "py_curses.h" +/* general error messages */ +static char *catchall_ERR = "_cursesmodule function returned ERR"; +static char *catchall_NULL = "_cursesmodule function returned NULL"; + /* These prototypes are in , but including this header #defines many common symbols (such as "lines") which breaks the curses module in other ways. So the code will just specify @@ -129,8 +134,8 @@ typedef chtype attr_t; /* No attr_t type is available */ #endif -#if defined(_AIX) -#define STRICT_SYSV_CURSES +#if defined(_AIX) || defined(__osf__) || defined(__hpux) +#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ #endif /* Definition of exception curses.error */ @@ -147,24 +152,87 @@ static int initialisedcolors = FALSE; /* Utility Macros */ -#define PyCursesSetupTermCalled \ +#define PyCurses_SETUP_TERM_WAS_CALLED() \ if (initialised_setupterm != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call (at least) setupterm() first"); \ return 0; } -#define PyCursesInitialised \ +#define PyCurses_IS_INITIALISED() \ if (initialised != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call initscr() first"); \ return 0; } -#define PyCursesInitialisedColor \ +#define PyCurses_COLOR_IS_INITIALISED() \ if (initialisedcolors != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call start_color() first"); \ return 0; } + +/* Function Prototype Macros - They are ugly but very, very useful. ;-) + s/but very, very/if (slightly)/ + + X - function name + TYPE - parameter Type + ERGSTR - format string for construction of the return value + PARSESTR - format string for argument parsing + */ + +#define NoArgNoReturnFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self) { \ + PyCurses_IS_INITIALISED(); \ + return PyCursesCheckERR(X(), # X); \ +} + +#define NoArgOrFlagNoReturnFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) { \ + int flag = 0; \ + PyCurses_IS_INITIALISED(); \ + switch (PyTuple_Size(args)) { \ + case 0: \ + return PyCursesCheckERR(X(), # X); \ + case 1: \ + if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) \ + return NULL; \ + if (flag) \ + return PyCursesCheckERR(X(), # X); \ + return PyCursesCheckERR(no ## X (), # X); \ + default: \ + PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ + Py_RETURN_NONE; \ + } \ +} + +#define NoArgReturnIntFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self) { \ + PyCurses_IS_INITIALISED(); \ + return PyInt_FromLong((long) X()); \ +} + + +#define NoArgReturnStringFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self) { \ + PyCurses_IS_INITIALISED(); \ + return PyString_FromString(X()); \ +} + +#define NoArgTrueFalseFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self) { \ + PyCurses_IS_INITIALISED(); \ + PyObject *returnValue = (X () == FALSE) ? Py_False : Py_True; \ + Py_INCREF(returnValue); \ + return returnValue; \ + } + +#define NoArgNoReturnVoidFunction(X) \ +static PyObject *PyCurses_ ## X (PyObject *self) { \ + PyCurses_IS_INITIALISED(); \ + X(); \ + Py_RETURN_NONE; \ +} + #ifndef MIN #define MIN(x,y) ((x) < (y) ? (x) : (y)) #endif @@ -180,56 +248,34 @@ static PyObject * PyCursesCheckERR(int code, char *fname) { - if (code != ERR) { - Py_INCREF(Py_None); - return Py_None; - } else { + if (code != ERR) { + Py_RETURN_NONE; + } if (fname == NULL) { - PyErr_SetString(PyCursesError, catchall_ERR); + PyErr_SetString(PyCursesError, catchall_ERR); } else { - PyErr_Format(PyCursesError, "%s() returned ERR", fname); + PyErr_Format(PyCursesError, "%s() returned ERR", fname); } - return NULL; - } + Py_RETURN_NONE; } static int PyCurses_ConvertToChtype(PyObject *obj, chtype *ch) { - if (PyInt_CheckExact(obj)) { - *ch = (chtype) PyInt_AsLong(obj); - } else if(PyString_Check(obj) - && (PyString_Size(obj) == 1)) { - *ch = (chtype) *PyString_AsString(obj); - } else if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) { - *ch = (chtype) *PyUnicode_AS_UNICODE(obj); - } else { - return 0; - } - return 1; -} - -/* Function versions of the 3 functions for tested whether curses has been - initialised or not. */ - -static int func_PyCursesSetupTermCalled(void) -{ - PyCursesSetupTermCalled; + if (PyInt_CheckExact(obj)) { + *ch = (chtype) PyInt_AsLong(obj); + } else if(PyString_Check(obj) + && (PyString_Size(obj) == 1)) { + *ch = (chtype) *PyString_AsString(obj); + } else if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) { + *ch = (chtype) *PyUnicode_AS_UNICODE(obj); + } else { + return 0; + } return 1; } -static int func_PyCursesInitialised(void) -{ - PyCursesInitialised; - return 1; -} -static int func_PyCursesInitialisedColor(void) -{ - PyCursesInitialisedColor; - return 1; -} - /***************************************************************************** The Window Object ******************************************************************************/ @@ -247,46 +293,54 @@ */ #define Window_NoArgNoReturnFunction(X) \ -static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ -{ return PyCursesCheckERR(X(self->win), # X); } +static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) { \ + return PyCursesCheckERR(X(self->win), # X); \ +} #define Window_NoArgTrueFalseFunction(X) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \ -{ \ - if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ - else { Py_INCREF(Py_True); return Py_True; } } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) { \ + PyObject *returnValue = (X (self->win) == FALSE) ? Py_False : Py_True; \ + Py_INCREF(returnValue); \ + return returnValue; \ +} #define Window_NoArgNoReturnVoidFunction(X) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \ -{ \ - X(self->win); Py_INCREF(Py_None); return Py_None; } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) { \ + X(self->win); \ + Py_RETURN_NONE; \ +} #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \ -{ \ - TYPE arg1, arg2; \ - X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) { \ + TYPE arg1, arg2; \ + X(self->win,arg1,arg2); \ + return Py_BuildValue(ERGSTR, arg1, arg2); \ +} #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ -{ \ - TYPE arg1; \ - if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ - X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) { \ + TYPE arg1; \ + if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) \ + return NULL; \ + X(self->win,arg1); \ + Py_RETURN_NONE; \ +} #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ -{ \ - TYPE arg1; \ - if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ - return PyCursesCheckERR(X(self->win, arg1), # X); } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) { \ + TYPE arg1; \ + if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) \ + return NULL; \ + return PyCursesCheckERR(X(self->win, arg1), # X); \ +} #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ -static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \ -{ \ - TYPE arg1, arg2; \ - if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ - return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } +static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) { \ + TYPE arg1, arg2; \ + if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) \ + return NULL; \ + return PyCursesCheckERR(X(self->win, arg1, arg2), # X); \ +} /* ------------- WINDOW routines --------------- */ @@ -350,19 +404,21 @@ static PyObject * PyCursesWindow_New(WINDOW *win) { - PyCursesWindowObject *wo; + PyCursesWindowObject *wo; - wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); - if (wo == NULL) return NULL; - wo->win = win; - return (PyObject *)wo; + wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); + if (wo == NULL) + return NULL; + wo->win = win; + return (PyObject *)wo; } static void PyCursesWindow_Dealloc(PyCursesWindowObject *wo) { - if (wo->win != stdscr) delwin(wo->win); - PyObject_DEL(wo); + if (wo->win != stdscr) + delwin(wo->win); + PyObject_DEL(wo); } /* Addch, Addstr, Addnstr */ @@ -370,166 +426,166 @@ static PyObject * PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args) { - int rtn, x, y, use_xy = FALSE; - PyObject *temp; - chtype ch = 0; - attr_t attr = A_NORMAL; + int rtn, x, y, use_xy = FALSE; + PyObject *temp; + chtype ch = 0; + attr_t attr = A_NORMAL; - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", - &y, &x, &temp, &attr)) - return NULL; - use_xy = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments"); - return NULL; - } + switch (PyTuple_Size(args)) { + case 1: + if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) + return NULL; + break; + case 2: + if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr)) + return NULL; + break; + case 3: + if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) + return NULL; + use_xy = TRUE; + break; + case 4: + if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", + &y, &x, &temp, &attr)) + return NULL; + use_xy = TRUE; + break; + default: + PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments"); + return NULL; + } - if (!PyCurses_ConvertToChtype(temp, &ch)) { - PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); - return NULL; - } + if (!PyCurses_ConvertToChtype(temp, &ch)) { + PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); + return NULL; + } - if (use_xy == TRUE) - rtn = mvwaddch(self->win,y,x, ch | attr); - else { - rtn = waddch(self->win, ch | attr); - } - return PyCursesCheckERR(rtn, "addch"); + if (use_xy == TRUE) + rtn = mvwaddch(self->win,y,x, ch | attr); + else { + rtn = waddch(self->win, ch | attr); + } + return PyCursesCheckERR(rtn, "addch"); } static PyObject * PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) { - int rtn; - int x, y; - char *str; - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - int use_xy = FALSE, use_attr = FALSE; + int rtn; + int x, y; + char *str; + attr_t attr = A_NORMAL , attr_old = A_NORMAL; + int use_xy = FALSE, use_attr = FALSE; - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"s;str", &str)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr)) - return NULL; - use_attr = TRUE; - break; - case 3: - if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &attr)) - return NULL; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); - return NULL; - } + switch (PyTuple_Size(args)) { + case 1: + if (!PyArg_ParseTuple(args,"s;str", &str)) + return NULL; + break; + case 2: + if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr)) + return NULL; + use_attr = TRUE; + break; + case 3: + if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str)) + return NULL; + use_xy = TRUE; + break; + case 4: + if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &attr)) + return NULL; + use_xy = use_attr = TRUE; + break; + default: + PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); + return NULL; + } - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - wattrset(self->win,attr); - } - if (use_xy == TRUE) - rtn = mvwaddstr(self->win,y,x,str); - else - rtn = waddstr(self->win,str); - if (use_attr == TRUE) - wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, "addstr"); + if (use_attr == TRUE) { + attr_old = getattrs(self->win); + wattrset(self->win,attr); + } + if (use_xy == TRUE) + rtn = mvwaddstr(self->win,y,x,str); + else + rtn = waddstr(self->win,str); + if (use_attr == TRUE) + wattrset(self->win,attr_old); + return PyCursesCheckERR(rtn, "addstr"); } static PyObject * PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) { - int rtn, x, y, n; - char *str; - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - int use_xy = FALSE, use_attr = FALSE; + int rtn, x, y, n; + char *str; + attr_t attr = A_NORMAL , attr_old = A_NORMAL; + int use_xy = FALSE, use_attr = FALSE; - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"si;str,n", &str, &n)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr)) - return NULL; - use_attr = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n)) - return NULL; - use_xy = TRUE; - break; - case 5: - if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr)) - return NULL; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); - return NULL; - } + switch (PyTuple_Size(args)) { + case 2: + if (!PyArg_ParseTuple(args,"si;str,n", &str, &n)) + return NULL; + break; + case 3: + if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr)) + return NULL; + use_attr = TRUE; + break; + case 4: + if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n)) + return NULL; + use_xy = TRUE; + break; + case 5: + if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr)) + return NULL; + use_xy = use_attr = TRUE; + break; + default: + PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); + return NULL; + } - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - wattrset(self->win,attr); - } - if (use_xy == TRUE) - rtn = mvwaddnstr(self->win,y,x,str,n); - else - rtn = waddnstr(self->win,str,n); - if (use_attr == TRUE) - wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, "addnstr"); + if (use_attr == TRUE) { + attr_old = getattrs(self->win); + wattrset(self->win,attr); + } + if (use_xy == TRUE) + rtn = mvwaddnstr(self->win,y,x,str,n); + else + rtn = waddnstr(self->win,str,n); + if (use_attr == TRUE) + wattrset(self->win,attr_old); + return PyCursesCheckERR(rtn, "addnstr"); } static PyObject * PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) { - PyObject *temp; - chtype bkgd; - attr_t attr = A_NORMAL; + PyObject *temp; + chtype bkgd; + attr_t attr = A_NORMAL; - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); - return NULL; - } + switch (PyTuple_Size(args)) { + case 1: + if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) + return NULL; + break; + case 2: + if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr)) + return NULL; + break; + default: + PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); + return NULL; + } if (!PyCurses_ConvertToChtype(temp, &bkgd)) { - PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); - return NULL; + PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); + return NULL; } return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); @@ -538,79 +594,74 @@ static PyObject * PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) { - PyObject *temp; - chtype bkgd; - attr_t attr = A_NORMAL; + PyObject *temp; + chtype bkgd; + attr_t attr = A_NORMAL; - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) + switch (PyTuple_Size(args)) { + case 1: + if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) + return NULL; + break; + case 2: + if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr)) + return NULL; + break; + default: + PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); + return NULL; + } + + if (!PyCurses_ConvertToChtype(temp, &bkgd)) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int"); return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); - return NULL; - } + } - if (!PyCurses_ConvertToChtype(temp, &bkgd)) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int"); - return NULL; - } - - wbkgdset(self->win, bkgd | attr); - return PyCursesCheckERR(0, "bkgdset"); + wbkgdset(self->win, bkgd | attr); + return PyCursesCheckERR(0, "bkgdset"); } static PyObject * PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) { - PyObject *temp[8]; - chtype ch[8]; - int i; + PyObject *temp[8]; + chtype ch[8]; + int i; - /* Clear the array of parameters */ - for(i=0; i<8; i++) { - temp[i] = NULL; - ch[i] = 0; - } + /* Clear the array of parameters */ + for(i=0; i<8; i++) { + temp[i] = NULL; + ch[i] = 0; + } - if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", + if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", &temp[0], &temp[1], &temp[2], &temp[3], &temp[4], &temp[5], &temp[6], &temp[7])) - return NULL; + return NULL; - for(i=0; i<8; i++) { - if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) { - PyErr_Format(PyExc_TypeError, + for (i = 0; i < 8; i++) { + if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) { + PyErr_Format(PyExc_TypeError, "argument %i must be a ch or an int", i+1); - return NULL; - } - } + return NULL; + } + } - wborder(self->win, - ch[0], ch[1], ch[2], ch[3], - ch[4], ch[5], ch[6], ch[7]); - Py_INCREF(Py_None); - return Py_None; + wborder(self->win, + ch[0], ch[1], ch[2], ch[3], + ch[4], ch[5], ch[6], ch[7]); + Py_INCREF(Py_None); + return Py_None; } static PyObject * PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) { - chtype ch1=0,ch2=0; - switch(PyTuple_Size(args)){ - case 0: break; - default: - if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2)) - return NULL; - } - box(self->win,ch1,ch2); - Py_INCREF(Py_None); - return Py_None; + chtype ch1=0,ch2=0; + if (PyTuple_Size(args) && !PyArg_ParseTuple(args, "ll;vertint,horint", &ch1, &ch2)) + return NULL; + box(self->win,ch1,ch2); + Py_RETURN_NONE; } #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION) @@ -618,10 +669,10 @@ #else int py_mvwdelch(WINDOW *w, int y, int x) { - mvwdelch(w,y,x); - /* On HP/UX, mvwdelch already returns. On other systems, - we may well run into this return statement. */ - return 0; + mvwdelch(w,y,x); + /* On HP/UX, mvwdelch already returns. On other systems, + we may well run into this return statement. */ + return 0; } #endif @@ -630,49 +681,49 @@ static PyObject * PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args) { - int rtn; - int x, y; - int num = -1; - short color; - attr_t attr = A_NORMAL; - int use_xy = FALSE; + int rtn; + int x, y; + int num = -1; + short color; + attr_t attr = A_NORMAL; + int use_xy = FALSE; - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"l;attr", &attr)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"il;n,attr", &num, &attr)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &attr)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &attr)) - return NULL; - use_xy = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); - return NULL; - } + switch (PyTuple_Size(args)) { + case 1: + if (!PyArg_ParseTuple(args,"l;attr", &attr)) + return NULL; + break; + case 2: + if (!PyArg_ParseTuple(args,"il;n,attr", &num, &attr)) + return NULL; + break; + case 3: + if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &attr)) + return NULL; + use_xy = TRUE; + break; + case 4: + if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &attr)) + return NULL; + use_xy = TRUE; + break; + default: + PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); + return NULL; + } - color = (short)((attr >> 8) & 0xff); - attr = attr - (color << 8); + color = (short)((attr >> 8) & 0xff); + attr = attr - (color << 8); - if (use_xy == TRUE) { - rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); - touchline(self->win,y,1); - } else { - getyx(self->win,y,x); - rtn = wchgat(self->win,num,attr,color,NULL); - touchline(self->win,y,1); - } - return PyCursesCheckERR(rtn, "chgat"); + if (use_xy == TRUE) { + rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); + touchline(self->win,y,1); + } else { + getyx(self->win,y,x); + rtn = wchgat(self->win,num,attr,color,NULL); + touchline(self->win,y,1); + } + return PyCursesCheckERR(rtn, "chgat"); } @@ -713,7 +764,7 @@ break; case 4: if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) + &nlines,&ncols,&begin_y,&begin_x)) return NULL; break; default: @@ -762,22 +813,22 @@ #ifdef WINDOW_HAS_FLAGS if (self->win->_flags & _ISPAD) return PyCursesCheckERR(pechochar(self->win, ch | attr), - "echochar"); + "echochar"); else #endif return PyCursesCheckERR(wechochar(self->win, ch | attr), - "echochar"); + "echochar"); } #ifdef NCURSES_MOUSE_VERSION static PyObject * PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) { - int x, y; - if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) - return NULL; + int x, y; + if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) + return NULL; - return PyInt_FromLong( wenclose(self->win,y,x) ); + return PyInt_FromLong( wenclose(self->win,y,x) ); } #endif @@ -928,7 +979,7 @@ break; case 5: if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", - &y, &x, &temp, &n, &attr)) + &y, &x, &temp, &n, &attr)) return NULL; code = wmove(self->win, y, x); break; @@ -940,7 +991,7 @@ if (code != ERR) { if (!PyCurses_ConvertToChtype(temp, &ch)) { PyErr_SetString(PyExc_TypeError, - "argument 1 or 3 must be a ch or an int"); + "argument 1 or 3 must be a ch or an int"); return NULL; } return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); @@ -982,7 +1033,7 @@ if (!PyCurses_ConvertToChtype(temp, &ch)) { PyErr_SetString(PyExc_TypeError, - "argument 1 or 3 must be a ch or an int"); + "argument 1 or 3 must be a ch or an int"); return NULL; } @@ -1152,7 +1203,7 @@ erg = is_linetouched(self->win, line); if (erg == ERR) { PyErr_SetString(PyExc_TypeError, - "is_linetouched: line number outside of boundaries"); + "is_linetouched: line number outside of boundaries"); return NULL; } else if (erg == FALSE) { @@ -1178,21 +1229,21 @@ switch(PyTuple_Size(args)) { case 6: if (!PyArg_ParseTuple(args, - "iiiiii;" \ - "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", - &pminrow, &pmincol, &sminrow, - &smincol, &smaxrow, &smaxcol)) - return NULL; + "iiiiii;" \ + "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", + &pminrow, &pmincol, &sminrow, + &smincol, &smaxrow, &smaxcol)) + return NULL; Py_BEGIN_ALLOW_THREADS rtn = pnoutrefresh(self->win, - pminrow, pmincol, sminrow, - smincol, smaxrow, smaxcol); + pminrow, pmincol, sminrow, + smincol, smaxrow, smaxcol); Py_END_ALLOW_THREADS return PyCursesCheckERR(rtn, "pnoutrefresh"); default: PyErr_SetString(PyCursesError, - "noutrefresh() called for a pad " - "requires 6 arguments"); + "noutrefresh() called for a pad " + "requires 6 arguments"); return NULL; } } else { @@ -1216,31 +1267,31 @@ switch (PyTuple_Size(args)) { case 1: - if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; - break; + if (!PyArg_ParseTuple(args, "O!;window object", + &PyCursesWindow_Type, &temp)) + return NULL; + break; case 7: - if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", - &PyCursesWindow_Type, &temp, &sminrow, &smincol, - &dminrow, &dmincol, &dmaxrow, &dmaxcol)) - return NULL; - use_copywin = TRUE; - break; + if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", + &PyCursesWindow_Type, &temp, &sminrow, &smincol, + &dminrow, &dmincol, &dmaxrow, &dmaxcol)) + return NULL; + use_copywin = TRUE; + break; default: - PyErr_SetString(PyExc_TypeError, - "overlay requires one or seven arguments"); - return NULL; + PyErr_SetString(PyExc_TypeError, + "overlay requires one or seven arguments"); + return NULL; } if (use_copywin == TRUE) { - rtn = copywin(self->win, temp->win, sminrow, smincol, - dminrow, dmincol, dmaxrow, dmaxcol, TRUE); - return PyCursesCheckERR(rtn, "copywin"); + rtn = copywin(self->win, temp->win, sminrow, smincol, + dminrow, dmincol, dmaxrow, dmaxcol, TRUE); + return PyCursesCheckERR(rtn, "copywin"); } else { - rtn = overlay(self->win, temp->win); - return PyCursesCheckERR(rtn, "overlay"); + rtn = overlay(self->win, temp->win); + return PyCursesCheckERR(rtn, "overlay"); } } @@ -1254,31 +1305,31 @@ switch (PyTuple_Size(args)) { case 1: - if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; - break; + if (!PyArg_ParseTuple(args, "O!;window object", + &PyCursesWindow_Type, &temp)) + return NULL; + break; case 7: - if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", - &PyCursesWindow_Type, &temp, &sminrow, &smincol, - &dminrow, &dmincol, &dmaxrow, &dmaxcol)) - return NULL; - use_copywin = TRUE; - break; + if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", + &PyCursesWindow_Type, &temp, &sminrow, &smincol, + &dminrow, &dmincol, &dmaxrow, &dmaxcol)) + return NULL; + use_copywin = TRUE; + break; default: - PyErr_SetString(PyExc_TypeError, - "overwrite requires one or seven arguments"); - return NULL; + PyErr_SetString(PyExc_TypeError, + "overwrite requires one or seven arguments"); + return NULL; } if (use_copywin == TRUE) { - rtn = copywin(self->win, temp->win, sminrow, smincol, - dminrow, dmincol, dmaxrow, dmaxcol, FALSE); + rtn = copywin(self->win, temp->win, sminrow, smincol, + dminrow, dmincol, dmaxrow, dmaxcol, FALSE); return PyCursesCheckERR(rtn, "copywin"); } else { - rtn = overwrite(self->win, temp->win); - return PyCursesCheckERR(rtn, "overwrite"); + rtn = overwrite(self->win, temp->win); + return PyCursesCheckERR(rtn, "overwrite"); } } @@ -1345,21 +1396,21 @@ switch(PyTuple_Size(args)) { case 6: if (!PyArg_ParseTuple(args, - "iiiiii;" \ - "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", - &pminrow, &pmincol, &sminrow, - &smincol, &smaxrow, &smaxcol)) - return NULL; + "iiiiii;" \ + "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", + &pminrow, &pmincol, &sminrow, + &smincol, &smaxrow, &smaxcol)) + return NULL; Py_BEGIN_ALLOW_THREADS rtn = prefresh(self->win, - pminrow, pmincol, sminrow, - smincol, smaxrow, smaxcol); + pminrow, pmincol, sminrow, + smincol, smaxrow, smaxcol); Py_END_ALLOW_THREADS return PyCursesCheckERR(rtn, "prefresh"); default: PyErr_SetString(PyCursesError, - "refresh() for a pad requires 6 arguments"); + "refresh() for a pad requires 6 arguments"); return NULL; } } else { @@ -1396,7 +1447,7 @@ break; case 4: if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) + &nlines,&ncols,&begin_y,&begin_x)) return NULL; break; default: @@ -1480,7 +1531,7 @@ break; case 5: if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", - &y, &x, &temp, &n, &attr)) + &y, &x, &temp, &n, &attr)) return NULL; code = wmove(self->win, y, x); break; @@ -1492,7 +1543,7 @@ if (code != ERR) { if (!PyCurses_ConvertToChtype(temp, &ch)) { PyErr_SetString(PyExc_TypeError, - "argument 1 or 3 must be a ch or an int"); + "argument 1 or 3 must be a ch or an int"); return NULL; } return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); @@ -1501,87 +1552,87 @@ } static PyMethodDef PyCursesWindow_Methods[] = { - {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, - {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, - {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, - {"attroff", (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS}, - {"attron", (PyCFunction)PyCursesWindow_wattron, METH_VARARGS}, - {"attrset", (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS}, - {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, - {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, - {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, - {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, - {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, - {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, - {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, - {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, - {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, - {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, - {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, - {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, - {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, - {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, + {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, + {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, + {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, + {"attroff", (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS}, + {"attron", (PyCFunction)PyCursesWindow_wattron, METH_VARARGS}, + {"attrset", (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS}, + {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, + {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, + {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, + {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, + {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, + {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, + {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, + {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, + {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, + {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, + {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, + {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, + {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, + {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, #ifdef NCURSES_MOUSE_VERSION - {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, + {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, #endif - {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, - {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, - {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, - {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, - {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, - {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, - {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, - {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, - {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, - {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, - {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, - {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, - {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, - {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, - {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, - {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, - {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, - {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, - {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, - {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, - {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, - {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, - {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, - {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, - {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, - {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, - {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, - {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, - {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, - {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, + {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, + {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, + {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, + {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, + {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, + {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, + {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, + {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, + {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, + {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, + {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, + {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, + {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, + {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, + {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, + {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, + {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, + {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, + {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, + {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, + {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, + {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, + {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, + {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, + {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, + {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, + {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, + {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, + {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, + {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, /* Backward compatibility alias -- remove in Python 2.3 */ - {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, - {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, - {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, + {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, + {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, + {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, METH_VARARGS}, - {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, - {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, - {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, - {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, + {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, + {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, + {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, + {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, #ifndef STRICT_SYSV_CURSES - {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, + {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, #endif - {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, - {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, - {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, - {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, - {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, - {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, - {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, - {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, - {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, - {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, - {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, - {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, - {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, - {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, - {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, - {NULL, NULL} /* sentinel */ + {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, + {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, + {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, + {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, + {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, + {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, + {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, + {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, + {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, + {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, + {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, + {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, + {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, + {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, + {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, + {NULL, NULL} /* sentinel */ }; static PyObject * @@ -1593,21 +1644,21 @@ /* -------------------------------------------------------*/ PyTypeObject PyCursesWindow_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_curses.curses window", /*tp_name*/ - sizeof(PyCursesWindowObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ + PyVarObject_HEAD_INIT(NULL, 0) + "_curses.curses window", /*tp_name*/ + sizeof(PyCursesWindowObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ }; /********************************************************************* @@ -1654,8 +1705,8 @@ { short color,r,g,b; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; @@ -1663,7 +1714,7 @@ return Py_BuildValue("(iii)", r, g, b); else { PyErr_SetString(PyCursesError, - "Argument 1 was out of range. Check value of COLORS."); + "Argument 1 was out of range. Check value of COLORS."); return NULL; } } @@ -1673,8 +1724,8 @@ { int n; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; return PyInt_FromLong((long) (n << 8)); @@ -1685,7 +1736,7 @@ { int vis,erg; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; @@ -1700,7 +1751,7 @@ { int ms; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; @@ -1712,7 +1763,7 @@ { char ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); ch = erasechar(); @@ -1724,7 +1775,7 @@ { int x,y; - PyCursesInitialised + PyCurses_IS_INITIALISED(); getsyx(y, x); @@ -1735,35 +1786,35 @@ static PyObject * PyCurses_GetMouse(PyObject *self) { - int rtn; - MEVENT event; + int rtn; + MEVENT event; - PyCursesInitialised + PyCurses_IS_INITIALISED(); - rtn = getmouse( &event ); - if (rtn == ERR) { - PyErr_SetString(PyCursesError, "getmouse() returned ERR"); - return NULL; - } - return Py_BuildValue("(hiiil)", - (short)event.id, - event.x, event.y, event.z, - (long) event.bstate); + rtn = getmouse( &event ); + if (rtn == ERR) { + PyErr_SetString(PyCursesError, "getmouse() returned ERR"); + return NULL; + } + return Py_BuildValue("(hiiil)", + (short)event.id, + event.x, event.y, event.z, + (long) event.bstate); } static PyObject * PyCurses_UngetMouse(PyObject *self, PyObject *args) { - MEVENT event; + MEVENT event; - PyCursesInitialised - if (!PyArg_ParseTuple(args, "hiiil", - &event.id, - &event.x, &event.y, &event.z, - (int *) &event.bstate)) - return NULL; + PyCurses_IS_INITIALISED(); + if (!PyArg_ParseTuple(args, "hiiil", + &event.id, + &event.x, &event.y, &event.z, + (int *) &event.bstate)) + return NULL; - return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); + return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); } #endif @@ -1776,7 +1827,7 @@ PyObject *data; WINDOW *win; - PyCursesInitialised + PyCurses_IS_INITIALISED(); strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); fd = mkstemp(fn); @@ -1817,7 +1868,7 @@ { unsigned char tenths; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; @@ -1830,7 +1881,7 @@ { int ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; @@ -1848,8 +1899,8 @@ { short color, r, g, b; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 4: @@ -1868,8 +1919,8 @@ { short pair, f, b; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); if (PyTuple_Size(args) != 3) { PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); @@ -1900,83 +1951,83 @@ return NULL; } - initialised = initialised_setupterm = TRUE; + initialised = initialised_setupterm = TRUE; /* This was moved from initcurses() because it core dumped on SGI, where they're not defined until you've called initscr() */ #define SetDictInt(string,ch) \ - do { \ - PyObject *o = PyInt_FromLong((long) (ch)); \ - if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ - Py_DECREF(o); \ - } \ + do { \ + PyObject *o = PyInt_FromLong((long) (ch)); \ + if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ + Py_DECREF(o); \ + } \ } while (0) - /* Here are some graphic symbols you can use */ + /* Here are some graphic symbols you can use */ SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); - SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); - SetDictInt("ACS_URCORNER", (ACS_URCORNER)); - SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); - SetDictInt("ACS_LTEE", (ACS_LTEE)); - SetDictInt("ACS_RTEE", (ACS_RTEE)); - SetDictInt("ACS_BTEE", (ACS_BTEE)); - SetDictInt("ACS_TTEE", (ACS_TTEE)); - SetDictInt("ACS_HLINE", (ACS_HLINE)); - SetDictInt("ACS_VLINE", (ACS_VLINE)); - SetDictInt("ACS_PLUS", (ACS_PLUS)); + SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); + SetDictInt("ACS_URCORNER", (ACS_URCORNER)); + SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); + SetDictInt("ACS_LTEE", (ACS_LTEE)); + SetDictInt("ACS_RTEE", (ACS_RTEE)); + SetDictInt("ACS_BTEE", (ACS_BTEE)); + SetDictInt("ACS_TTEE", (ACS_TTEE)); + SetDictInt("ACS_HLINE", (ACS_HLINE)); + SetDictInt("ACS_VLINE", (ACS_VLINE)); + SetDictInt("ACS_PLUS", (ACS_PLUS)); #if !defined(__hpux) || defined(HAVE_NCURSES_H) /* On HP/UX 11, these are of type cchar_t, which is not an integral type. If this is a problem on more platforms, a configure test should be added to determine whether ACS_S1 is of integral type. */ - SetDictInt("ACS_S1", (ACS_S1)); - SetDictInt("ACS_S9", (ACS_S9)); - SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); - SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); - SetDictInt("ACS_DEGREE", (ACS_DEGREE)); - SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); - SetDictInt("ACS_BULLET", (ACS_BULLET)); - SetDictInt("ACS_LARROW", (ACS_LARROW)); - SetDictInt("ACS_RARROW", (ACS_RARROW)); - SetDictInt("ACS_DARROW", (ACS_DARROW)); - SetDictInt("ACS_UARROW", (ACS_UARROW)); - SetDictInt("ACS_BOARD", (ACS_BOARD)); - SetDictInt("ACS_LANTERN", (ACS_LANTERN)); - SetDictInt("ACS_BLOCK", (ACS_BLOCK)); + SetDictInt("ACS_S1", (ACS_S1)); + SetDictInt("ACS_S9", (ACS_S9)); + SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); + SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); + SetDictInt("ACS_DEGREE", (ACS_DEGREE)); + SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); + SetDictInt("ACS_BULLET", (ACS_BULLET)); + SetDictInt("ACS_LARROW", (ACS_LARROW)); + SetDictInt("ACS_RARROW", (ACS_RARROW)); + SetDictInt("ACS_DARROW", (ACS_DARROW)); + SetDictInt("ACS_UARROW", (ACS_UARROW)); + SetDictInt("ACS_BOARD", (ACS_BOARD)); + SetDictInt("ACS_LANTERN", (ACS_LANTERN)); + SetDictInt("ACS_BLOCK", (ACS_BLOCK)); #endif - SetDictInt("ACS_BSSB", (ACS_ULCORNER)); - SetDictInt("ACS_SSBB", (ACS_LLCORNER)); - SetDictInt("ACS_BBSS", (ACS_URCORNER)); - SetDictInt("ACS_SBBS", (ACS_LRCORNER)); - SetDictInt("ACS_SBSS", (ACS_RTEE)); - SetDictInt("ACS_SSSB", (ACS_LTEE)); - SetDictInt("ACS_SSBS", (ACS_BTEE)); - SetDictInt("ACS_BSSS", (ACS_TTEE)); - SetDictInt("ACS_BSBS", (ACS_HLINE)); - SetDictInt("ACS_SBSB", (ACS_VLINE)); - SetDictInt("ACS_SSSS", (ACS_PLUS)); + SetDictInt("ACS_BSSB", (ACS_ULCORNER)); + SetDictInt("ACS_SSBB", (ACS_LLCORNER)); + SetDictInt("ACS_BBSS", (ACS_URCORNER)); + SetDictInt("ACS_SBBS", (ACS_LRCORNER)); + SetDictInt("ACS_SBSS", (ACS_RTEE)); + SetDictInt("ACS_SSSB", (ACS_LTEE)); + SetDictInt("ACS_SSBS", (ACS_BTEE)); + SetDictInt("ACS_BSSS", (ACS_TTEE)); + SetDictInt("ACS_BSBS", (ACS_HLINE)); + SetDictInt("ACS_SBSB", (ACS_VLINE)); + SetDictInt("ACS_SSSS", (ACS_PLUS)); - /* The following are never available with strict SYSV curses */ + /* The following are never available with strict SYSV curses */ #ifdef ACS_S3 - SetDictInt("ACS_S3", (ACS_S3)); + SetDictInt("ACS_S3", (ACS_S3)); #endif #ifdef ACS_S7 - SetDictInt("ACS_S7", (ACS_S7)); + SetDictInt("ACS_S7", (ACS_S7)); #endif #ifdef ACS_LEQUAL - SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); + SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); #endif #ifdef ACS_GEQUAL - SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); + SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); #endif #ifdef ACS_PI - SetDictInt("ACS_PI", (ACS_PI)); + SetDictInt("ACS_PI", (ACS_PI)); #endif #ifdef ACS_NEQUAL - SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); + SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); #endif #ifdef ACS_STERLING - SetDictInt("ACS_STERLING", (ACS_STERLING)); + SetDictInt("ACS_STERLING", (ACS_STERLING)); #endif SetDictInt("LINES", LINES); @@ -1988,53 +2039,53 @@ static PyObject * PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) { - int fd = -1; - int err; - char* termstr = NULL; + int fd = -1; + int err; + char* termstr = NULL; - static char *kwlist[] = {"term", "fd", NULL}; + static char *kwlist[] = {"term", "fd", NULL}; - if (!PyArg_ParseTupleAndKeywords( - args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { - return NULL; - } - - if (fd == -1) { - PyObject* sys_stdout; + if (!PyArg_ParseTupleAndKeywords( + args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { + return NULL; + } + + if (fd == -1) { + PyObject* sys_stdout; - sys_stdout = PySys_GetObject("stdout"); + sys_stdout = PySys_GetObject("stdout"); - if (sys_stdout == NULL) { - PyErr_SetString( - PyCursesError, - "lost sys.stdout"); - return NULL; - } + if (sys_stdout == NULL) { + PyErr_SetString( + PyCursesError, + "lost sys.stdout"); + return NULL; + } - fd = PyObject_AsFileDescriptor(sys_stdout); + fd = PyObject_AsFileDescriptor(sys_stdout); - if (fd == -1) { - return NULL; - } - } + if (fd == -1) { + return NULL; + } + } - if (setupterm(termstr,fd,&err) == ERR) { - char* s = "setupterm: unknown error"; - - if (err == 0) { - s = "setupterm: could not find terminal"; - } else if (err == -1) { - s = "setupterm: could not find terminfo database"; - } + if (setupterm(termstr,fd,&err) == ERR) { + char* s = "setupterm: unknown error"; + + if (err == 0) { + s = "setupterm: could not find terminal"; + } else if (err == -1) { + s = "setupterm: could not find terminfo database"; + } - PyErr_SetString(PyCursesError,s); - return NULL; - } + PyErr_SetString(PyCursesError,s); + return NULL; + } - initialised_setupterm = TRUE; + initialised_setupterm = TRUE; - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } static PyObject * @@ -2042,7 +2093,7 @@ { int ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 1: @@ -2064,7 +2115,7 @@ int columns; int result; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) return NULL; @@ -2086,7 +2137,7 @@ const char *knp; int ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; @@ -2115,7 +2166,7 @@ { int ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 1: @@ -2133,25 +2184,25 @@ static PyObject * PyCurses_MouseInterval(PyObject *self, PyObject *args) { - int interval; - PyCursesInitialised + int interval; + PyCurses_IS_INITIALISED(); - if (!PyArg_ParseTuple(args,"i;interval",&interval)) - return NULL; - return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); + if (!PyArg_ParseTuple(args,"i;interval",&interval)) + return NULL; + return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); } static PyObject * PyCurses_MouseMask(PyObject *self, PyObject *args) { - int newmask; - mmask_t oldmask, availmask; + int newmask; + mmask_t oldmask, availmask; - PyCursesInitialised - if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) - return NULL; - availmask = mousemask(newmask, &oldmask); - return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); + PyCurses_IS_INITIALISED(); + if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) + return NULL; + availmask = mousemask(newmask, &oldmask); + return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); } #endif @@ -2160,7 +2211,7 @@ { int ms; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; return Py_BuildValue("i", napms(ms)); @@ -2173,7 +2224,7 @@ WINDOW *win; int nlines, ncols; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; @@ -2193,7 +2244,7 @@ WINDOW *win; int nlines, ncols, begin_y=0, begin_x=0; - PyCursesInitialised + PyCurses_IS_INITIALISED(); switch (PyTuple_Size(args)) { case 2: @@ -2202,7 +2253,7 @@ break; case 4: if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) + &nlines,&ncols,&begin_y,&begin_x)) return NULL; break; default: @@ -2224,8 +2275,8 @@ { short pair,f,b; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 1: @@ -2238,7 +2289,7 @@ if (pair_content(pair, &f, &b)==ERR) { PyErr_SetString(PyCursesError, - "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); + "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); return NULL; } @@ -2250,8 +2301,8 @@ { int n; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 1: @@ -2280,7 +2331,7 @@ { int flag = 0; - PyCursesInitialised + PyCurses_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 0: @@ -2354,7 +2405,7 @@ int columns; PyObject *result; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) return NULL; @@ -2378,7 +2429,7 @@ PyObject *result; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) return NULL; @@ -2397,7 +2448,7 @@ { int y,x; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (PyTuple_Size(args)!=2) { PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); @@ -2418,7 +2469,7 @@ int code; PyObject *c, *cp; - PyCursesInitialised + PyCurses_IS_INITIALISED(); code = start_color(); if (code != ERR) { @@ -2440,69 +2491,69 @@ static PyObject * PyCurses_tigetflag(PyObject *self, PyObject *args) { - char *capname; + char *capname; - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "z", &capname)) - return NULL; + PyCurses_SETUP_TERM_WAS_CALLED(); + + if (!PyArg_ParseTuple(args, "z", &capname)) + return NULL; - return PyInt_FromLong( (long) tigetflag( capname ) ); + return PyInt_FromLong( (long) tigetflag( capname ) ); } static PyObject * PyCurses_tigetnum(PyObject *self, PyObject *args) { - char *capname; + char *capname; - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "z", &capname)) - return NULL; + PyCurses_SETUP_TERM_WAS_CALLED(); + + if (!PyArg_ParseTuple(args, "z", &capname)) + return NULL; - return PyInt_FromLong( (long) tigetnum( capname ) ); + return PyInt_FromLong( (long) tigetnum( capname ) ); } static PyObject * PyCurses_tigetstr(PyObject *self, PyObject *args) { - char *capname; + char *capname; - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "z", &capname)) - return NULL; + PyCurses_SETUP_TERM_WAS_CALLED(); + + if (!PyArg_ParseTuple(args, "z", &capname)) + return NULL; - capname = tigetstr( capname ); - if (capname == 0 || capname == (char*) -1) { - Py_INCREF(Py_None); - return Py_None; - } - return PyString_FromString( capname ); + capname = tigetstr( capname ); + if (capname == 0 || capname == (char*) -1) { + Py_INCREF(Py_None); + return Py_None; + } + return PyString_FromString( capname ); } static PyObject * PyCurses_tparm(PyObject *self, PyObject *args) { - char* fmt; - char* result = NULL; - int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; + char* fmt; + char* result = NULL; + int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; - PyCursesSetupTermCalled; + PyCurses_SETUP_TERM_WAS_CALLED(); - if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm", - &fmt, &i1, &i2, &i3, &i4, - &i5, &i6, &i7, &i8, &i9)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm", + &fmt, &i1, &i2, &i3, &i4, + &i5, &i6, &i7, &i8, &i9)) { + return NULL; + } - result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); - if (!result) { - PyErr_SetString(PyCursesError, "tparm() returned NULL"); - return NULL; - } + result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); + if (!result) { + PyErr_SetString(PyCursesError, "tparm() returned NULL"); + return NULL; + } - return PyString_FromString(result); + return PyString_FromString(result); } static PyObject * @@ -2510,7 +2561,7 @@ { int fd; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; @@ -2523,7 +2574,7 @@ PyObject *temp; chtype ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; @@ -2541,7 +2592,7 @@ PyObject *temp; chtype ch; - PyCursesInitialised + PyCurses_IS_INITIALISED(); if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; @@ -2558,7 +2609,7 @@ { int flag; - PyCursesInitialised + PyCurses_IS_INITIALISED(); switch(PyTuple_Size(args)) { case 1: @@ -2580,8 +2631,8 @@ { int code; - PyCursesInitialised - PyCursesInitialisedColor + PyCurses_IS_INITIALISED(); + PyCurses_COLOR_IS_INITIALISED(); code = use_default_colors(); if (code != ERR) { @@ -2675,9 +2726,9 @@ {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, - {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, - {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, - {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, + {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, + {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, + {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, @@ -2686,7 +2737,7 @@ #ifndef STRICT_SYSV_CURSES {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, #endif - {NULL, NULL} /* sentinel */ + {NULL, NULL} /* sentinel */ }; /* Initialization function for the module */ @@ -2694,162 +2745,159 @@ PyMODINIT_FUNC init_curses(void) { - PyObject *m, *d, *v, *c_api_object; - static void *PyCurses_API[PyCurses_API_pointers]; + PyObject *m; + PyObject *d; + PyObject *v; + PyObject *_initialised; - /* Initialize object type */ - Py_Type(&PyCursesWindow_Type) = &PyType_Type; + /* Initialize object type */ + Py_Type(&PyCursesWindow_Type) = &PyType_Type; + PyType_Ready(&PyCursesWindow_Type); - /* Initialize the C API pointer array */ - PyCurses_API[0] = (void *)&PyCursesWindow_Type; - PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; - PyCurses_API[2] = (void *)func_PyCursesInitialised; - PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; + /* Create the module and add the functions */ + m = Py_InitModule("_curses", PyCurses_methods); + if (m == NULL) + return; - /* Create the module and add the functions */ - m = Py_InitModule("_curses", PyCurses_methods); - if (m == NULL) - return; + /* Add some symbolic constants to the module */ + d = PyModule_GetDict(m); + if (d == NULL) + return; + ModDict = d; /* For PyCurses_InitScr to use later */ - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - if (d == NULL) - return; - ModDict = d; /* For PyCurses_InitScr to use later */ + PyDict_SetItemString(d, "__window_type", (PyObject *)&PyCursesWindow_Type); + _initialised = PyCObject_FromVoidPtr((void *)&initialised, NULL); + PyDict_SetItemString(d, "__initialised", _initialised); + Py_DECREF(_initialised); - /* Add a CObject for the C API */ - c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL); - PyDict_SetItemString(d, "_C_API", c_api_object); - Py_DECREF(c_api_object); + /* For exception curses.error */ + PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); + PyDict_SetItemString(d, "error", PyCursesError); - /* For exception curses.error */ - PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); - PyDict_SetItemString(d, "error", PyCursesError); + /* Make the version available */ + v = PyString_FromString(PyCursesVersion); + PyDict_SetItemString(d, "version", v); + PyDict_SetItemString(d, "__version__", v); + Py_DECREF(v); - /* Make the version available */ - v = PyString_FromString(PyCursesVersion); - PyDict_SetItemString(d, "version", v); - PyDict_SetItemString(d, "__version__", v); - Py_DECREF(v); + SetDictInt("ERR", ERR); + SetDictInt("OK", OK); - SetDictInt("ERR", ERR); - SetDictInt("OK", OK); - - /* Here are some attributes you can add to chars to print */ - - SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); - SetDictInt("A_NORMAL", A_NORMAL); - SetDictInt("A_STANDOUT", A_STANDOUT); - SetDictInt("A_UNDERLINE", A_UNDERLINE); - SetDictInt("A_REVERSE", A_REVERSE); - SetDictInt("A_BLINK", A_BLINK); - SetDictInt("A_DIM", A_DIM); - SetDictInt("A_BOLD", A_BOLD); - SetDictInt("A_ALTCHARSET", A_ALTCHARSET); + /* Here are some attributes you can add to chars to print */ + + SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); + SetDictInt("A_NORMAL", A_NORMAL); + SetDictInt("A_STANDOUT", A_STANDOUT); + SetDictInt("A_UNDERLINE", A_UNDERLINE); + SetDictInt("A_REVERSE", A_REVERSE); + SetDictInt("A_BLINK", A_BLINK); + SetDictInt("A_DIM", A_DIM); + SetDictInt("A_BOLD", A_BOLD); + SetDictInt("A_ALTCHARSET", A_ALTCHARSET); #if !defined(__NetBSD__) - SetDictInt("A_INVIS", A_INVIS); + SetDictInt("A_INVIS", A_INVIS); #endif - SetDictInt("A_PROTECT", A_PROTECT); - SetDictInt("A_CHARTEXT", A_CHARTEXT); - SetDictInt("A_COLOR", A_COLOR); + SetDictInt("A_PROTECT", A_PROTECT); + SetDictInt("A_CHARTEXT", A_CHARTEXT); + SetDictInt("A_COLOR", A_COLOR); - /* The following are never available with strict SYSV curses */ + /* The following are never available with strict SYSV curses */ #ifdef A_HORIZONTAL - SetDictInt("A_HORIZONTAL", A_HORIZONTAL); + SetDictInt("A_HORIZONTAL", A_HORIZONTAL); #endif #ifdef A_LEFT - SetDictInt("A_LEFT", A_LEFT); + SetDictInt("A_LEFT", A_LEFT); #endif #ifdef A_LOW - SetDictInt("A_LOW", A_LOW); + SetDictInt("A_LOW", A_LOW); #endif #ifdef A_RIGHT - SetDictInt("A_RIGHT", A_RIGHT); + SetDictInt("A_RIGHT", A_RIGHT); #endif #ifdef A_TOP - SetDictInt("A_TOP", A_TOP); + SetDictInt("A_TOP", A_TOP); #endif #ifdef A_VERTICAL - SetDictInt("A_VERTICAL", A_VERTICAL); + SetDictInt("A_VERTICAL", A_VERTICAL); #endif - SetDictInt("COLOR_BLACK", COLOR_BLACK); - SetDictInt("COLOR_RED", COLOR_RED); - SetDictInt("COLOR_GREEN", COLOR_GREEN); - SetDictInt("COLOR_YELLOW", COLOR_YELLOW); - SetDictInt("COLOR_BLUE", COLOR_BLUE); - SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); - SetDictInt("COLOR_CYAN", COLOR_CYAN); - SetDictInt("COLOR_WHITE", COLOR_WHITE); + SetDictInt("COLOR_BLACK", COLOR_BLACK); + SetDictInt("COLOR_RED", COLOR_RED); + SetDictInt("COLOR_GREEN", COLOR_GREEN); + SetDictInt("COLOR_YELLOW", COLOR_YELLOW); + SetDictInt("COLOR_BLUE", COLOR_BLUE); + SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); + SetDictInt("COLOR_CYAN", COLOR_CYAN); + SetDictInt("COLOR_WHITE", COLOR_WHITE); #ifdef NCURSES_MOUSE_VERSION - /* Mouse-related constants */ - SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); - SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); - SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); - SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); - SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); + /* Mouse-related constants */ + SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); + SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); + SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); + SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); + SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); - SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); - SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); - SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); - SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); - SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); + SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); + SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); + SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); + SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); + SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); - SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); - SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); - SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); - SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); - SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); + SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); + SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); + SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); + SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); + SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); - SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); - SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); - SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); - SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); - SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); + SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); + SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); + SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); + SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); + SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); - SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); - SetDictInt("BUTTON_CTRL", BUTTON_CTRL); - SetDictInt("BUTTON_ALT", BUTTON_ALT); + SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); + SetDictInt("BUTTON_CTRL", BUTTON_CTRL); + SetDictInt("BUTTON_ALT", BUTTON_ALT); - SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); - SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); + SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); + SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); #endif - /* Now set everything up for KEY_ variables */ - { - int key; - char *key_n; - char *key_n2; + /* Now set everything up for KEY_ variables */ + { + int key; + char *key_n; + char *key_n2; #if !defined(__NetBSD__) - for (key=KEY_MIN;key < KEY_MAX; key++) { - key_n = (char *)keyname(key); - if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) - continue; - if (strncmp(key_n,"KEY_F(",6)==0) { - char *p1, *p2; - key_n2 = malloc(strlen(key_n)+1); - if (!key_n2) { - PyErr_NoMemory(); - break; + for (key=KEY_MIN;key < KEY_MAX; key++) { + key_n = (char *)keyname(key); + if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) + continue; + if (strncmp(key_n,"KEY_F(",6)==0) { + char *p1, *p2; + key_n2 = malloc(strlen(key_n)+1); + if (!key_n2) { + PyErr_NoMemory(); + break; } - p1 = key_n; - p2 = key_n2; - while (*p1) { - if (*p1 != '(' && *p1 != ')') { - *p2 = *p1; - p2++; - } - p1++; - } - *p2 = (char)0; - } else - key_n2 = key_n; - SetDictInt(key_n2,key); - if (key_n2 != key_n) - free(key_n2); - } + p1 = key_n; + p2 = key_n2; + while (*p1) { + if (*p1 != '(' && *p1 != ')') { + *p2 = *p1; + p2++; + } + p1++; + } + *p2 = (char)0; + } else + key_n2 = key_n; + SetDictInt(key_n2,key); + if (key_n2 != key_n) + free(key_n2); + } #endif - SetDictInt("KEY_MIN", KEY_MIN); - SetDictInt("KEY_MAX", KEY_MAX); - } + SetDictInt("KEY_MIN", KEY_MIN); + SetDictInt("KEY_MAX", KEY_MAX); + } }