Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/_cursesmodule.c

    r2 r391  
    3232 */
    3333
    34 /* CVS: $Id: _cursesmodule.c 78324 2010-02-22 17:06:22Z andrew.kuchling $ */
    35 
    3634/*
    3735
    38 A number of SysV or ncurses functions don't have wrappers yet; if you
    39 need a given function, add it and send a patch.  See
    40 http://www.python.org/dev/patches/ for instructions on how to submit
    41 patches to Python.
    42 
    43 Here's a list of currently unsupported functions:
    44 
    45         addchnstr addchstr color_set define_key
    46         del_curterm delscreen dupwin inchnstr inchstr innstr keyok
    47         mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
    48         mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
    49         mvwinchnstr mvwinchstr mvwinnstr newterm
    50         restartterm ripoffline scr_dump
    51         scr_init scr_restore scr_set scrl set_curterm set_term setterm
    52         tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
    53         vidattr vidputs waddchnstr waddchstr
    54         wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
    55 
    56 Low-priority:
    57         slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
    58         slk_attron slk_attrset slk_clear slk_color slk_init slk_label
    59         slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
    60 
    61 Menu extension (ncurses and probably SYSV):
    62         current_item free_item free_menu item_count item_description
    63         item_index item_init item_name item_opts item_opts_off
    64         item_opts_on item_term item_userptr item_value item_visible
    65         menu_back menu_driver menu_fore menu_format menu_grey
    66         menu_init menu_items menu_mark menu_opts menu_opts_off
    67         menu_opts_on menu_pad menu_pattern menu_request_by_name
    68         menu_request_name menu_spacing menu_sub menu_term menu_userptr
    69         menu_win new_item new_menu pos_menu_cursor post_menu
    70         scale_menu set_current_item set_item_init set_item_opts
    71         set_item_term set_item_userptr set_item_value set_menu_back
    72         set_menu_fore set_menu_format set_menu_grey set_menu_init
    73         set_menu_items set_menu_mark set_menu_opts set_menu_pad
    74         set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
    75         set_menu_userptr set_menu_win set_top_row top_row unpost_menu
    76 
    77 Form extension (ncurses and probably SYSV):
    78         current_field data_ahead data_behind dup_field
    79         dynamic_fieldinfo field_arg field_back field_buffer
    80         field_count field_fore field_index field_info field_init
    81         field_just field_opts field_opts_off field_opts_on field_pad
    82         field_status field_term field_type field_userptr form_driver
    83         form_fields form_init form_opts form_opts_off form_opts_on
    84         form_page form_request_by_name form_request_name form_sub
    85         form_term form_userptr form_win free_field free_form
    86         link_field link_fieldtype move_field new_field new_form
    87         new_page pos_form_cursor post_form scale_form
    88         set_current_field set_field_back set_field_buffer
    89         set_field_fore set_field_init set_field_just set_field_opts
    90         set_field_pad set_field_status set_field_term set_field_type
    91         set_field_userptr set_fieldtype_arg set_fieldtype_choice
    92         set_form_fields set_form_init set_form_opts set_form_page
    93         set_form_sub set_form_term set_form_userptr set_form_win
    94         set_max_field set_new_page unpost_form
    95 
    96 
    97  */
     36  A number of SysV or ncurses functions don't have wrappers yet; if you
     37  need a given function, add it and send a patch.  See
     38  http://www.python.org/dev/patches/ for instructions on how to submit
     39  patches to Python.
     40
     41  Here's a list of currently unsupported functions:
     42
     43  addchnstr addchstr color_set define_key
     44  del_curterm delscreen dupwin inchnstr inchstr innstr keyok
     45  mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
     46  mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
     47  mvwinchnstr mvwinchstr mvwinnstr newterm
     48  restartterm ripoffline scr_dump
     49  scr_init scr_restore scr_set scrl set_curterm set_term setterm
     50  tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
     51  vidattr vidputs waddchnstr waddchstr
     52  wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
     53
     54  Low-priority:
     55  slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
     56  slk_attron slk_attrset slk_clear slk_color slk_init slk_label
     57  slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
     58
     59  Menu extension (ncurses and probably SYSV):
     60  current_item free_item free_menu item_count item_description
     61  item_index item_init item_name item_opts item_opts_off
     62  item_opts_on item_term item_userptr item_value item_visible
     63  menu_back menu_driver menu_fore menu_format menu_grey
     64  menu_init menu_items menu_mark menu_opts menu_opts_off
     65  menu_opts_on menu_pad menu_pattern menu_request_by_name
     66  menu_request_name menu_spacing menu_sub menu_term menu_userptr
     67  menu_win new_item new_menu pos_menu_cursor post_menu
     68  scale_menu set_current_item set_item_init set_item_opts
     69  set_item_term set_item_userptr set_item_value set_menu_back
     70  set_menu_fore set_menu_format set_menu_grey set_menu_init
     71  set_menu_items set_menu_mark set_menu_opts set_menu_pad
     72  set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
     73  set_menu_userptr set_menu_win set_top_row top_row unpost_menu
     74
     75  Form extension (ncurses and probably SYSV):
     76  current_field data_ahead data_behind dup_field
     77  dynamic_fieldinfo field_arg field_back field_buffer
     78  field_count field_fore field_index field_info field_init
     79  field_just field_opts field_opts_off field_opts_on field_pad
     80  field_status field_term field_type field_userptr form_driver
     81  form_fields form_init form_opts form_opts_off form_opts_on
     82  form_page form_request_by_name form_request_name form_sub
     83  form_term form_userptr form_win free_field free_form
     84  link_field link_fieldtype move_field new_field new_form
     85  new_page pos_form_cursor post_form scale_form
     86  set_current_field set_field_back set_field_buffer
     87  set_field_fore set_field_init set_field_just set_field_opts
     88  set_field_pad set_field_status set_field_term set_field_type
     89  set_field_userptr set_fieldtype_arg set_fieldtype_choice
     90  set_form_fields set_form_init set_form_opts set_form_page
     91  set_form_sub set_form_term set_form_userptr set_form_win
     92  set_max_field set_new_page unpost_form
     93
     94
     95*/
    9896
    9997/* Release Number */
     
    116114#include "py_curses.h"
    117115
    118 /*  These prototypes are in <term.h>, but including this header 
    119     #defines many common symbols (such as "lines") which breaks the 
    120     curses module in other ways.  So the code will just specify 
     116/*  These prototypes are in <term.h>, but including this header
     117    #defines many common symbols (such as "lines") which breaks the
     118    curses module in other ways.  So the code will just specify
    121119    explicit prototypes here. */
    122120extern int setupterm(char *,int,int *);
     
    148146
    149147/* Utility Macros */
    150 #define PyCursesSetupTermCalled \
    151   if (initialised_setupterm != TRUE) { \
    152                   PyErr_SetString(PyCursesError, \
    153                                   "must call (at least) setupterm() first"); \
    154                   return 0; }
    155 
    156 #define PyCursesInitialised \
    157   if (initialised != TRUE) { \
    158                   PyErr_SetString(PyCursesError, \
    159                                   "must call initscr() first"); \
    160                   return 0; }
    161 
    162 #define PyCursesInitialisedColor \
    163   if (initialisedcolors != TRUE) { \
    164                   PyErr_SetString(PyCursesError, \
    165                                   "must call start_color() first"); \
    166                   return 0; }
     148#define PyCursesSetupTermCalled                                         \
     149    if (initialised_setupterm != TRUE) {                                \
     150        PyErr_SetString(PyCursesError,                                  \
     151                        "must call (at least) setupterm() first");      \
     152        return 0; }
     153
     154#define PyCursesInitialised                             \
     155    if (initialised != TRUE) {                          \
     156        PyErr_SetString(PyCursesError,                  \
     157                        "must call initscr() first");  \
     158        return 0; }
     159
     160#define PyCursesInitialisedColor                                \
     161    if (initialisedcolors != TRUE) {                            \
     162        PyErr_SetString(PyCursesError,                          \
     163                        "must call start_color() first");      \
     164        return 0; }
    167165
    168166#ifndef MIN
     
    173171
    174172/*
    175  * Check the return code from a curses function and return None 
     173 * Check the return code from a curses function and return None
    176174 * or raise an exception as appropriate.  These are exported using the
    177  * CObject API.
     175 * capsule API.
    178176 */
    179177
     
    181179PyCursesCheckERR(int code, char *fname)
    182180{
    183   if (code != ERR) {
    184     Py_INCREF(Py_None);
    185     return Py_None;
    186   } else {
    187     if (fname == NULL) {
    188       PyErr_SetString(PyCursesError, catchall_ERR);
     181    if (code != ERR) {
     182        Py_INCREF(Py_None);
     183        return Py_None;
    189184    } else {
    190       PyErr_Format(PyCursesError, "%s() returned ERR", fname);
    191     }
    192     return NULL;
    193   }
    194 }
    195 
    196 static int
     185        if (fname == NULL) {
     186            PyErr_SetString(PyCursesError, catchall_ERR);
     187        } else {
     188            PyErr_Format(PyCursesError, "%s() returned ERR", fname);
     189        }
     190        return NULL;
     191    }
     192}
     193
     194static int
    197195PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
    198196{
    199   if (PyInt_Check(obj)) {
    200     *ch = (chtype) PyInt_AsLong(obj);
    201   } else if(PyString_Check(obj)
    202             && (PyString_Size(obj) == 1)) {
    203     *ch = (chtype) *PyString_AsString(obj);
    204   } else {
    205     return 0;
    206   }
    207   return 1;
    208 }
    209 
    210 /* Function versions of the 3 functions for tested whether curses has been
     197    if (PyInt_Check(obj)) {
     198        *ch = (chtype) PyInt_AsLong(obj);
     199    } else if(PyString_Check(obj)
     200              && (PyString_Size(obj) == 1)) {
     201        *ch = (chtype) *PyString_AsString(obj);
     202    } else {
     203        return 0;
     204    }
     205    return 1;
     206}
     207
     208/* Function versions of the 3 functions for testing whether curses has been
    211209   initialised or not. */
    212    
     210
    213211static int func_PyCursesSetupTermCalled(void)
    214212{
     
    243241   ERGSTR - format string for construction of the return value
    244242   PARSESTR - format string for argument parsing
    245    */
    246 
    247 #define Window_NoArgNoReturnFunction(X) \
    248 static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
    249 { return PyCursesCheckERR(X(self->win), # X); }
    250 
    251 #define Window_NoArgTrueFalseFunction(X) \
    252 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
    253 { \
    254   if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
    255   else { Py_INCREF(Py_True); return Py_True; } }
    256 
    257 #define Window_NoArgNoReturnVoidFunction(X) \
    258 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
    259 { \
    260   X(self->win); Py_INCREF(Py_None); return Py_None; }
    261 
    262 #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
    263 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
    264 { \
    265   TYPE arg1, arg2; \
    266   X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
    267 
    268 #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
    269 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
    270 { \
    271   TYPE arg1; \
    272   if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
    273   X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
    274 
    275 #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
    276 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
    277 { \
    278   TYPE arg1; \
    279   if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
    280   return PyCursesCheckERR(X(self->win, arg1), # X); }
    281 
    282 #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
    283 static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
    284 { \
    285   TYPE arg1, arg2; \
    286   if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
    287   return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
     243*/
     244
     245#define Window_NoArgNoReturnFunction(X)                 \
     246    static PyObject *PyCursesWindow_ ## X               \
     247    (PyCursesWindowObject *self, PyObject *args)        \
     248    { return PyCursesCheckERR(X(self->win), # X); }
     249
     250#define Window_NoArgTrueFalseFunction(X)                                \
     251    static PyObject * PyCursesWindow_ ## X                              \
     252    (PyCursesWindowObject *self)                                        \
     253    {                                                                   \
     254        if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
     255        else { Py_INCREF(Py_True); return Py_True; } }
     256
     257#define Window_NoArgNoReturnVoidFunction(X)                     \
     258    static PyObject * PyCursesWindow_ ## X                      \
     259    (PyCursesWindowObject *self)                                \
     260    {                                                           \
     261        X(self->win); Py_INCREF(Py_None); return Py_None; }
     262
     263#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR)               \
     264    static PyObject * PyCursesWindow_ ## X                              \
     265    (PyCursesWindowObject *self)                                        \
     266    {                                                                   \
     267        TYPE arg1, arg2;                                                \
     268        X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
     269
     270#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR)            \
     271    static PyObject * PyCursesWindow_ ## X                              \
     272    (PyCursesWindowObject *self, PyObject *args)                        \
     273    {                                                                   \
     274        TYPE arg1;                                                      \
     275        if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL;      \
     276        X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
     277
     278#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR)                \
     279    static PyObject * PyCursesWindow_ ## X                              \
     280    (PyCursesWindowObject *self, PyObject *args)                        \
     281    {                                                                   \
     282        TYPE arg1;                                                      \
     283        if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL;       \
     284        return PyCursesCheckERR(X(self->win, arg1), # X); }
     285
     286#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR)                \
     287    static PyObject * PyCursesWindow_ ## X                              \
     288    (PyCursesWindowObject *self, PyObject *args)                        \
     289    {                                                                   \
     290        TYPE arg1, arg2;                                                \
     291        if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
     292        return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
    288293
    289294/* ------------- WINDOW routines --------------- */
     
    346351PyCursesWindow_New(WINDOW *win)
    347352{
    348         PyCursesWindowObject *wo;
    349 
    350         wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
    351         if (wo == NULL) return NULL;
    352         wo->win = win;
    353         return (PyObject *)wo;
     353    PyCursesWindowObject *wo;
     354
     355    wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
     356    if (wo == NULL) return NULL;
     357    wo->win = win;
     358    return (PyObject *)wo;
    354359}
    355360
     
    357362PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
    358363{
    359   if (wo->win != stdscr) delwin(wo->win);
    360   PyObject_DEL(wo);
     364    if (wo->win != stdscr) delwin(wo->win);
     365    PyObject_DEL(wo);
    361366}
    362367
     
    366371PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
    367372{
    368   int rtn, x, y, use_xy = FALSE;
    369   PyObject *temp;
    370   chtype ch = 0;
    371   attr_t attr = A_NORMAL;
    372   long lattr;
    373  
    374   switch (PyTuple_Size(args)) {
    375   case 1:
    376     if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
    377           return NULL;
    378     break;
    379   case 2:
    380     if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
    381       return NULL;
    382     attr = lattr;
    383     break;
    384   case 3:
    385     if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
    386       return NULL;
    387     use_xy = TRUE;
    388     break;
    389   case 4:
    390     if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
    391                      &y, &x, &temp, &lattr))
    392       return NULL;
    393     attr = lattr;
    394     use_xy = TRUE;
    395     break;
    396   default:
    397     PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
    398     return NULL;
    399   }
    400 
    401   if (!PyCurses_ConvertToChtype(temp, &ch)) {
    402     PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
    403     return NULL;
    404   }
    405  
    406   if (use_xy == TRUE)
    407     rtn = mvwaddch(self->win,y,x, ch | attr);
    408   else {
    409     rtn = waddch(self->win, ch | attr);
    410   }
    411   return PyCursesCheckERR(rtn, "addch");
     373    int rtn, x, y, use_xy = FALSE;
     374    PyObject *temp;
     375    chtype ch = 0;
     376    attr_t attr = A_NORMAL;
     377    long lattr;
     378
     379    switch (PyTuple_Size(args)) {
     380    case 1:
     381        if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
     382            return NULL;
     383        break;
     384    case 2:
     385        if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
     386            return NULL;
     387        attr = lattr;
     388        break;
     389    case 3:
     390        if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
     391            return NULL;
     392        use_xy = TRUE;
     393        break;
     394    case 4:
     395        if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
     396                              &y, &x, &temp, &lattr))
     397            return NULL;
     398        attr = lattr;
     399        use_xy = TRUE;
     400        break;
     401    default:
     402        PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
     403        return NULL;
     404    }
     405
     406    if (!PyCurses_ConvertToChtype(temp, &ch)) {
     407        PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
     408        return NULL;
     409    }
     410
     411    if (use_xy == TRUE)
     412        rtn = mvwaddch(self->win,y,x, ch | attr);
     413    else {
     414        rtn = waddch(self->win, ch | attr);
     415    }
     416    return PyCursesCheckERR(rtn, "addch");
    412417}
    413418
     
    415420PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
    416421{
    417   int rtn;
    418   int x, y;
    419   char *str;
    420   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
    421   long lattr;
    422   int use_xy = FALSE, use_attr = FALSE;
    423 
    424   switch (PyTuple_Size(args)) {
    425   case 1:
    426     if (!PyArg_ParseTuple(args,"s;str", &str))
    427       return NULL;
    428     break;
    429   case 2:
    430     if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
    431       return NULL;
    432     attr = lattr;
    433     use_attr = TRUE;
    434     break;
    435   case 3:
    436     if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
    437       return NULL;
    438     use_xy = TRUE;
    439     break;
    440   case 4:
    441     if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
    442       return NULL;
    443     attr = lattr;
    444     use_xy = use_attr = TRUE;
    445     break;
    446   default:
    447     PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
    448     return NULL;
    449   }
    450 
    451   if (use_attr == TRUE) {
    452     attr_old = getattrs(self->win);
    453     wattrset(self->win,attr);
    454   }
    455   if (use_xy == TRUE)
    456     rtn = mvwaddstr(self->win,y,x,str);
    457   else
    458     rtn = waddstr(self->win,str);
    459   if (use_attr == TRUE)
    460     wattrset(self->win,attr_old);
    461   return PyCursesCheckERR(rtn, "addstr");
     422    int rtn;
     423    int x, y;
     424    char *str;
     425    attr_t attr = A_NORMAL , attr_old = A_NORMAL;
     426    long lattr;
     427    int use_xy = FALSE, use_attr = FALSE;
     428
     429    switch (PyTuple_Size(args)) {
     430    case 1:
     431        if (!PyArg_ParseTuple(args,"s;str", &str))
     432            return NULL;
     433        break;
     434    case 2:
     435        if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
     436            return NULL;
     437        attr = lattr;
     438        use_attr = TRUE;
     439        break;
     440    case 3:
     441        if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
     442            return NULL;
     443        use_xy = TRUE;
     444        break;
     445    case 4:
     446        if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr))
     447            return NULL;
     448        attr = lattr;
     449        use_xy = use_attr = TRUE;
     450        break;
     451    default:
     452        PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
     453        return NULL;
     454    }
     455
     456    if (use_attr == TRUE) {
     457        attr_old = getattrs(self->win);
     458        (void)wattrset(self->win,attr);
     459    }
     460    if (use_xy == TRUE)
     461        rtn = mvwaddstr(self->win,y,x,str);
     462    else
     463        rtn = waddstr(self->win,str);
     464    if (use_attr == TRUE)
     465        (void)wattrset(self->win,attr_old);
     466    return PyCursesCheckERR(rtn, "addstr");
    462467}
    463468
     
    465470PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
    466471{
    467   int rtn, x, y, n;
    468   char *str;
    469   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
    470   long lattr;
    471   int use_xy = FALSE, use_attr = FALSE;
    472 
    473   switch (PyTuple_Size(args)) {
    474   case 2:
    475     if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
    476       return NULL;
    477     break;
    478   case 3:
    479     if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
    480       return NULL;
    481     attr = lattr;
    482     use_attr = TRUE;
    483     break;
    484   case 4:
    485     if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
    486       return NULL;
    487     use_xy = TRUE;
    488     break;
    489   case 5:
    490     if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
    491       return NULL;
    492     attr = lattr;
    493     use_xy = use_attr = TRUE;
    494     break;
    495   default:
    496     PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
    497     return NULL;
    498   }
    499 
    500   if (use_attr == TRUE) {
    501     attr_old = getattrs(self->win);
    502     wattrset(self->win,attr);
    503   }
    504   if (use_xy == TRUE)
    505     rtn = mvwaddnstr(self->win,y,x,str,n);
    506   else
    507     rtn = waddnstr(self->win,str,n);
    508   if (use_attr == TRUE)
    509     wattrset(self->win,attr_old);
    510   return PyCursesCheckERR(rtn, "addnstr");
     472    int rtn, x, y, n;
     473    char *str;
     474    attr_t attr = A_NORMAL , attr_old = A_NORMAL;
     475    long lattr;
     476    int use_xy = FALSE, use_attr = FALSE;
     477
     478    switch (PyTuple_Size(args)) {
     479    case 2:
     480        if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
     481            return NULL;
     482        break;
     483    case 3:
     484        if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
     485            return NULL;
     486        attr = lattr;
     487        use_attr = TRUE;
     488        break;
     489    case 4:
     490        if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
     491            return NULL;
     492        use_xy = TRUE;
     493        break;
     494    case 5:
     495        if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
     496            return NULL;
     497        attr = lattr;
     498        use_xy = use_attr = TRUE;
     499        break;
     500    default:
     501        PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
     502        return NULL;
     503    }
     504
     505    if (use_attr == TRUE) {
     506        attr_old = getattrs(self->win);
     507        (void)wattrset(self->win,attr);
     508    }
     509    if (use_xy == TRUE)
     510        rtn = mvwaddnstr(self->win,y,x,str,n);
     511    else
     512        rtn = waddnstr(self->win,str,n);
     513    if (use_attr == TRUE)
     514        (void)wattrset(self->win,attr_old);
     515    return PyCursesCheckERR(rtn, "addnstr");
    511516}
    512517
     
    514519PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
    515520{
    516   PyObject *temp;
    517   chtype bkgd;
    518   attr_t attr = A_NORMAL;
    519   long lattr;
    520 
    521   switch (PyTuple_Size(args)) {
     521    PyObject *temp;
     522    chtype bkgd;
     523    attr_t attr = A_NORMAL;
     524    long lattr;
     525
     526    switch (PyTuple_Size(args)) {
    522527    case 1:
    523       if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
    524         return NULL;
    525       break;
     528        if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
     529            return NULL;
     530        break;
    526531    case 2:
    527       if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
    528         return NULL;
    529       attr = lattr;
    530       break;
    531     default:
    532       PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
    533       return NULL;
    534   }
    535 
    536   if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
    537     PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
    538     return NULL;
    539   }
    540 
    541   return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
     532        if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
     533            return NULL;
     534        attr = lattr;
     535        break;
     536    default:
     537        PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
     538        return NULL;
     539    }
     540
     541    if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
     542        PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
     543        return NULL;
     544    }
     545
     546    return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
    542547}
    543548
     
    545550PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args)
    546551{
    547   long lattr;
    548   if (!PyArg_ParseTuple(args,"l;attr", &lattr))
    549     return NULL;
    550   return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
     552    long lattr;
     553    if (!PyArg_ParseTuple(args,"l;attr", &lattr))
     554        return NULL;
     555    return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
    551556}
    552557
     
    554559PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args)
    555560{
    556   long lattr;
    557   if (!PyArg_ParseTuple(args,"l;attr", &lattr))
    558     return NULL;
    559   return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
     561    long lattr;
     562    if (!PyArg_ParseTuple(args,"l;attr", &lattr))
     563        return NULL;
     564    return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
    560565}
    561566
     
    563568PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args)
    564569{
    565   long lattr;
    566   if (!PyArg_ParseTuple(args,"l;attr", &lattr))
    567     return NULL;
    568   return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
     570    long lattr;
     571    if (!PyArg_ParseTuple(args,"l;attr", &lattr))
     572        return NULL;
     573    return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
    569574}
    570575
     
    572577PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
    573578{
    574   PyObject *temp;
    575   chtype bkgd;
    576   attr_t attr = A_NORMAL;
    577   long lattr;
    578 
    579   switch (PyTuple_Size(args)) {
     579    PyObject *temp;
     580    chtype bkgd;
     581    attr_t attr = A_NORMAL;
     582    long lattr;
     583
     584    switch (PyTuple_Size(args)) {
    580585    case 1:
    581       if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
    582         return NULL;
    583       break;
     586        if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
     587            return NULL;
     588        break;
    584589    case 2:
    585       if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
    586         return NULL;
    587       attr = lattr;
    588       break;
    589     default:
    590       PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
    591       return NULL;
    592   }
    593 
    594   if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
    595     PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
    596     return NULL;
    597   }
    598 
    599   wbkgdset(self->win, bkgd | attr);
    600   return PyCursesCheckERR(0, "bkgdset");
     590        if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
     591            return NULL;
     592        attr = lattr;
     593        break;
     594    default:
     595        PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
     596        return NULL;
     597    }
     598
     599    if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
     600        PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
     601        return NULL;
     602    }
     603
     604    wbkgdset(self->win, bkgd | attr);
     605    return PyCursesCheckERR(0, "bkgdset");
    601606}
    602607
     
    604609PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
    605610{
    606   PyObject *temp[8];
    607   chtype ch[8];
    608   int i;
    609 
    610   /* Clear the array of parameters */
    611   for(i=0; i<8; i++) {
    612        temp[i] = NULL;
    613        ch[i] = 0;
    614   }   
    615  
    616   if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
    617                         &temp[0], &temp[1], &temp[2], &temp[3],
    618                         &temp[4], &temp[5], &temp[6], &temp[7]))
    619     return NULL;
    620 
    621   for(i=0; i<8; i++) {
    622       if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
    623           PyErr_Format(PyExc_TypeError,
    624                        "argument %i must be a ch or an int", i+1);
    625           return NULL;
    626       }
    627   }
    628  
    629   wborder(self->win,
    630           ch[0], ch[1], ch[2], ch[3],
    631           ch[4], ch[5], ch[6], ch[7]);
    632   Py_INCREF(Py_None);
    633   return Py_None;
     611    PyObject *temp[8];
     612    chtype ch[8];
     613    int i;
     614
     615    /* Clear the array of parameters */
     616    for(i=0; i<8; i++) {
     617        temp[i] = NULL;
     618        ch[i] = 0;
     619    }
     620
     621    if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
     622                          &temp[0], &temp[1], &temp[2], &temp[3],
     623                          &temp[4], &temp[5], &temp[6], &temp[7]))
     624        return NULL;
     625
     626    for(i=0; i<8; i++) {
     627        if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
     628            PyErr_Format(PyExc_TypeError,
     629                         "argument %i must be a ch or an int", i+1);
     630            return NULL;
     631        }
     632    }
     633
     634    wborder(self->win,
     635            ch[0], ch[1], ch[2], ch[3],
     636            ch[4], ch[5], ch[6], ch[7]);
     637    Py_INCREF(Py_None);
     638    return Py_None;
    634639}
    635640
     
    637642PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
    638643{
    639   chtype ch1=0,ch2=0;
    640   switch(PyTuple_Size(args)){
    641   case 0: break;
    642   default:
    643     if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
    644       return NULL;
    645   }
    646   box(self->win,ch1,ch2);
    647   Py_INCREF(Py_None);
    648   return Py_None;
     644    chtype ch1=0,ch2=0;
     645    switch(PyTuple_Size(args)){
     646    case 0: break;
     647    default:
     648        if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
     649            return NULL;
     650    }
     651    box(self->win,ch1,ch2);
     652    Py_INCREF(Py_None);
     653    return Py_None;
    649654}
    650655
     
    654659int py_mvwdelch(WINDOW *w, int y, int x)
    655660{
    656   mvwdelch(w,y,x);
    657   /* On HP/UX, mvwdelch already returns. On other systems,
    658      we may well run into this return statement. */
    659   return 0;
     661    mvwdelch(w,y,x);
     662    /* On HP/UX, mvwdelch already returns. On other systems,
     663       we may well run into this return statement. */
     664    return 0;
    660665}
    661666#endif
     
    666671PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
    667672{
    668   int rtn;
    669   int x, y;
    670   int num = -1;
    671   short color;
    672   attr_t attr = A_NORMAL;
    673   long lattr;
    674   int use_xy = FALSE;
    675 
    676   switch (PyTuple_Size(args)) {
    677   case 1:
    678     if (!PyArg_ParseTuple(args,"l;attr", &lattr))
    679       return NULL;
    680     attr = lattr;
    681     break;
    682   case 2:
    683     if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
    684       return NULL;
    685     attr = lattr;
    686     break;
    687   case 3:
    688     if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
    689       return NULL;
    690     attr = lattr;
    691     use_xy = TRUE;
    692     break;
    693   case 4:
    694     if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
    695       return NULL;
    696     attr = lattr;
    697     use_xy = TRUE;
    698     break;
    699   default:
    700     PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
    701     return NULL;
    702   }
    703 
    704   color = (short)((attr >> 8) & 0xff);
    705   attr = attr - (color << 8);
    706 
    707   if (use_xy == TRUE) {
    708     rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
    709     touchline(self->win,y,1);
    710   } else {
    711     getyx(self->win,y,x);
    712     rtn = wchgat(self->win,num,attr,color,NULL);
    713     touchline(self->win,y,1);
    714   }
    715   return PyCursesCheckERR(rtn, "chgat");
     673    int rtn;
     674    int x, y;
     675    int num = -1;
     676    short color;
     677    attr_t attr = A_NORMAL;
     678    long lattr;
     679    int use_xy = FALSE;
     680
     681    switch (PyTuple_Size(args)) {
     682    case 1:
     683        if (!PyArg_ParseTuple(args,"l;attr", &lattr))
     684            return NULL;
     685        attr = lattr;
     686        break;
     687    case 2:
     688        if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
     689            return NULL;
     690        attr = lattr;
     691        break;
     692    case 3:
     693        if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
     694            return NULL;
     695        attr = lattr;
     696        use_xy = TRUE;
     697        break;
     698    case 4:
     699        if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
     700            return NULL;
     701        attr = lattr;
     702        use_xy = TRUE;
     703        break;
     704    default:
     705        PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
     706        return NULL;
     707    }
     708
     709    color = (short)((attr >> 8) & 0xff);
     710    attr = attr - (color << 8);
     711
     712    if (use_xy == TRUE) {
     713        rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
     714        touchline(self->win,y,1);
     715    } else {
     716        getyx(self->win,y,x);
     717        rtn = wchgat(self->win,num,attr,color,NULL);
     718        touchline(self->win,y,1);
     719    }
     720    return PyCursesCheckERR(rtn, "chgat");
    716721}
    717722
     
    720725PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
    721726{
    722   int rtn;
    723   int x, y;
    724 
    725   switch (PyTuple_Size(args)) {
    726   case 0:
    727     rtn = wdelch(self->win);
    728     break;
    729   case 2:
     727    int rtn;
     728    int x, y;
     729
     730    switch (PyTuple_Size(args)) {
     731    case 0:
     732        rtn = wdelch(self->win);
     733        break;
     734    case 2:
     735        if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
     736            return NULL;
     737        rtn = py_mvwdelch(self->win,y,x);
     738        break;
     739    default:
     740        PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
     741        return NULL;
     742    }
     743    return PyCursesCheckERR(rtn, "[mv]wdelch");
     744}
     745
     746static PyObject *
     747PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
     748{
     749    WINDOW *win;
     750    int nlines, ncols, begin_y, begin_x;
     751
     752    nlines = 0;
     753    ncols  = 0;
     754    switch (PyTuple_Size(args)) {
     755    case 2:
     756        if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
     757            return NULL;
     758        break;
     759    case 4:
     760        if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
     761                              &nlines,&ncols,&begin_y,&begin_x))
     762            return NULL;
     763        break;
     764    default:
     765        PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
     766        return NULL;
     767    }
     768
     769    win = derwin(self->win,nlines,ncols,begin_y,begin_x);
     770
     771    if (win == NULL) {
     772        PyErr_SetString(PyCursesError, catchall_NULL);
     773        return NULL;
     774    }
     775
     776    return (PyObject *)PyCursesWindow_New(win);
     777}
     778
     779static PyObject *
     780PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
     781{
     782    PyObject *temp;
     783    chtype ch;
     784    attr_t attr = A_NORMAL;
     785    long lattr;
     786
     787    switch (PyTuple_Size(args)) {
     788    case 1:
     789        if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
     790            return NULL;
     791        break;
     792    case 2:
     793        if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
     794            return NULL;
     795        attr = lattr;
     796        break;
     797    default:
     798        PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
     799
     800
     801        return NULL;
     802    }
     803
     804    if (!PyCurses_ConvertToChtype(temp, &ch)) {
     805        PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
     806        return NULL;
     807    }
     808
     809#ifdef WINDOW_HAS_FLAGS
     810    if (self->win->_flags & _ISPAD)
     811        return PyCursesCheckERR(pechochar(self->win, ch | attr),
     812                                "echochar");
     813    else
     814#endif
     815        return PyCursesCheckERR(wechochar(self->win, ch | attr),
     816                                "echochar");
     817}
     818
     819#ifdef NCURSES_MOUSE_VERSION
     820static PyObject *
     821PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
     822{
     823    int x, y;
    730824    if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
    731       return NULL;
    732     rtn = py_mvwdelch(self->win,y,x);
    733     break;
    734   default:
    735     PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
    736     return NULL;
    737   }
    738   return PyCursesCheckERR(rtn, "[mv]wdelch");
    739 }
    740 
    741 static PyObject *
    742 PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
    743 {
    744   WINDOW *win;
    745   int nlines, ncols, begin_y, begin_x;
    746 
    747   nlines = 0;
    748   ncols  = 0;
    749   switch (PyTuple_Size(args)) {
    750   case 2:
    751     if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
    752       return NULL;
    753     break;
    754   case 4:
    755     if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
    756                    &nlines,&ncols,&begin_y,&begin_x))
    757       return NULL;
    758     break;
    759   default:
    760     PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
    761     return NULL;
    762   }
    763 
    764   win = derwin(self->win,nlines,ncols,begin_y,begin_x);
    765 
    766   if (win == NULL) {
    767     PyErr_SetString(PyCursesError, catchall_NULL);
    768     return NULL;
    769   }
    770 
    771   return (PyObject *)PyCursesWindow_New(win);
    772 }
    773 
    774 static PyObject *
    775 PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
    776 {
    777   PyObject *temp;
    778   chtype ch;
    779   attr_t attr = A_NORMAL;
    780   long lattr;
    781 
    782   switch (PyTuple_Size(args)) {
    783   case 1:
    784     if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
    785       return NULL;
    786     break;
    787   case 2:
    788     if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
    789       return NULL;
    790     attr = lattr;
    791     break;
    792   default:
    793     PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
    794 
    795 
    796     return NULL;
    797   }
    798 
    799   if (!PyCurses_ConvertToChtype(temp, &ch)) {
    800     PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
    801     return NULL;
    802   }
    803  
    804 #ifdef WINDOW_HAS_FLAGS
    805   if (self->win->_flags & _ISPAD)
    806     return PyCursesCheckERR(pechochar(self->win, ch | attr),
    807                             "echochar");
    808   else
    809 #endif
    810     return PyCursesCheckERR(wechochar(self->win, ch | attr),
    811                             "echochar");
    812 }
    813 
    814 #ifdef NCURSES_MOUSE_VERSION
    815 static PyObject *
    816 PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
    817 {
    818         int x, y;
    819         if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
    820                 return NULL;
    821 
    822         return PyInt_FromLong( wenclose(self->win,y,x) );
     825        return NULL;
     826
     827    return PyInt_FromLong( wenclose(self->win,y,x) );
    823828}
    824829#endif
     
    827832PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
    828833{
    829   return PyInt_FromLong((long) getbkgd(self->win));
     834    return PyInt_FromLong((long) getbkgd(self->win));
    830835}
    831836
     
    833838PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
    834839{
    835   int x, y;
    836   int rtn;
    837 
    838   switch (PyTuple_Size(args)) {
    839   case 0:
    840     Py_BEGIN_ALLOW_THREADS
    841     rtn = wgetch(self->win);
    842     Py_END_ALLOW_THREADS
    843     break;
    844   case 2:
    845     if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    846       return NULL;
    847     Py_BEGIN_ALLOW_THREADS
    848     rtn = mvwgetch(self->win,y,x);
    849     Py_END_ALLOW_THREADS
    850     break;
    851   default:
    852     PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
    853     return NULL;
    854   }
    855   return PyInt_FromLong((long)rtn);
     840    int x, y;
     841    int rtn;
     842
     843    switch (PyTuple_Size(args)) {
     844    case 0:
     845        Py_BEGIN_ALLOW_THREADS
     846        rtn = wgetch(self->win);
     847        Py_END_ALLOW_THREADS
     848        break;
     849    case 2:
     850        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
     851            return NULL;
     852        Py_BEGIN_ALLOW_THREADS
     853        rtn = mvwgetch(self->win,y,x);
     854        Py_END_ALLOW_THREADS
     855        break;
     856    default:
     857        PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
     858        return NULL;
     859    }
     860    return PyInt_FromLong((long)rtn);
    856861}
    857862
     
    859864PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
    860865{
    861   int x, y;
    862   int rtn;
    863 
    864   switch (PyTuple_Size(args)) {
    865   case 0:
    866     Py_BEGIN_ALLOW_THREADS
    867     rtn = wgetch(self->win);
    868     Py_END_ALLOW_THREADS
    869     break;
    870   case 2:
    871     if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    872       return NULL;
    873     Py_BEGIN_ALLOW_THREADS
    874     rtn = mvwgetch(self->win,y,x);
    875     Py_END_ALLOW_THREADS
    876     break;
    877   default:
    878     PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
    879     return NULL;
    880   }
    881   if (rtn == ERR) {
    882     /* getch() returns ERR in nodelay mode */
    883     PyErr_SetString(PyCursesError, "no input");
    884     return NULL;
    885   } else if (rtn<=255) {
    886     return Py_BuildValue("c", rtn);
    887   } else {
    888     const char *knp;
     866    int x, y;
     867    int rtn;
     868
     869    switch (PyTuple_Size(args)) {
     870    case 0:
     871        Py_BEGIN_ALLOW_THREADS
     872        rtn = wgetch(self->win);
     873        Py_END_ALLOW_THREADS
     874        break;
     875    case 2:
     876        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
     877            return NULL;
     878        Py_BEGIN_ALLOW_THREADS
     879        rtn = mvwgetch(self->win,y,x);
     880        Py_END_ALLOW_THREADS
     881        break;
     882    default:
     883        PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
     884        return NULL;
     885    }
     886    if (rtn == ERR) {
     887        /* getch() returns ERR in nodelay mode */
     888        PyErr_CheckSignals();
     889        if (!PyErr_Occurred())
     890            PyErr_SetString(PyCursesError, "no input");
     891        return NULL;
     892    } else if (rtn<=255) {
     893        return Py_BuildValue("c", rtn);
     894    } else {
     895        const char *knp;
    889896#if defined(__NetBSD__)
    890     knp = unctrl(rtn);
     897        knp = unctrl(rtn);
    891898#else
    892     knp = keyname(rtn);
    893 #endif
    894     return PyString_FromString((knp == NULL) ? "" : knp);
    895   }
     899        knp = keyname(rtn);
     900#endif
     901        return PyString_FromString((knp == NULL) ? "" : knp);
     902    }
    896903}
    897904
     
    899906PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
    900907{
    901   int x, y, n;
    902   char rtn[1024]; /* This should be big enough.. I hope */
    903   int rtn2;
    904 
    905   switch (PyTuple_Size(args)) {
    906   case 0:
    907     Py_BEGIN_ALLOW_THREADS
    908     rtn2 = wgetnstr(self->win,rtn, 1023);
    909     Py_END_ALLOW_THREADS
    910     break;
    911   case 1:
    912     if (!PyArg_ParseTuple(args,"i;n", &n))
    913       return NULL;
    914     Py_BEGIN_ALLOW_THREADS
    915     rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
    916     Py_END_ALLOW_THREADS
    917     break;
    918   case 2:
    919     if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    920       return NULL;
    921     Py_BEGIN_ALLOW_THREADS
     908    int x, y, n;
     909    char rtn[1024]; /* This should be big enough.. I hope */
     910    int rtn2;
     911
     912    switch (PyTuple_Size(args)) {
     913    case 0:
     914        Py_BEGIN_ALLOW_THREADS
     915        rtn2 = wgetnstr(self->win,rtn, 1023);
     916        Py_END_ALLOW_THREADS
     917        break;
     918    case 1:
     919        if (!PyArg_ParseTuple(args,"i;n", &n))
     920            return NULL;
     921        Py_BEGIN_ALLOW_THREADS
     922        rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
     923        Py_END_ALLOW_THREADS
     924        break;
     925    case 2:
     926        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
     927            return NULL;
     928        Py_BEGIN_ALLOW_THREADS
    922929#ifdef STRICT_SYSV_CURSES
    923     rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
     930        rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
    924931#else
    925     rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
    926 #endif
    927     Py_END_ALLOW_THREADS
    928     break;
    929   case 3:
    930     if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
    931       return NULL;
     932        rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
     933#endif
     934        Py_END_ALLOW_THREADS
     935        break;
     936    case 3:
     937        if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
     938            return NULL;
    932939#ifdef STRICT_SYSV_CURSES
    933     Py_BEGIN_ALLOW_THREADS
    934     rtn2 = wmove(self->win,y,x)==ERR ? ERR :
    935       wgetnstr(self->win, rtn, MIN(n, 1023));
    936     Py_END_ALLOW_THREADS
     940        Py_BEGIN_ALLOW_THREADS
     941        rtn2 = wmove(self->win,y,x)==ERR ? ERR :
     942        wgetnstr(self->win, rtn, MIN(n, 1023));
     943        Py_END_ALLOW_THREADS
    937944#else
    938     Py_BEGIN_ALLOW_THREADS
    939     rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
    940     Py_END_ALLOW_THREADS
    941 #endif
    942     break;
    943   default:
    944     PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
    945     return NULL;
    946   }
    947   if (rtn2 == ERR)
    948     rtn[0] = 0;
    949   return PyString_FromString(rtn);
     945        Py_BEGIN_ALLOW_THREADS
     946        rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
     947        Py_END_ALLOW_THREADS
     948#endif
     949        break;
     950    default:
     951        PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
     952        return NULL;
     953    }
     954    if (rtn2 == ERR)
     955        rtn[0] = 0;
     956    return PyString_FromString(rtn);
    950957}
    951958
     
    953960PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
    954961{
    955   PyObject *temp;
    956   chtype ch;
    957   int n, x, y, code = OK;
    958   attr_t attr = A_NORMAL;
    959   long lattr;
    960 
    961   switch (PyTuple_Size(args)) {
    962   case 2:
    963     if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
    964       return NULL;
    965     break;
    966   case 3:
    967     if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
    968       return NULL;
    969     attr = lattr;
    970     break;
    971   case 4:
    972     if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
    973       return NULL;
    974     code = wmove(self->win, y, x);
    975     break;
    976   case 5:
    977     if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
    978                      &y, &x, &temp, &n, &lattr))
    979       return NULL;
    980     attr = lattr;
    981     code = wmove(self->win, y, x);
    982     break;
    983   default:
    984     PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
    985     return NULL;
    986   }
    987 
    988   if (code != ERR) {
     962    PyObject *temp;
     963    chtype ch;
     964    int n, x, y, code = OK;
     965    attr_t attr = A_NORMAL;
     966    long lattr;
     967
     968    switch (PyTuple_Size(args)) {
     969    case 2:
     970        if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
     971            return NULL;
     972        break;
     973    case 3:
     974        if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
     975            return NULL;
     976        attr = lattr;
     977        break;
     978    case 4:
     979        if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
     980            return NULL;
     981        code = wmove(self->win, y, x);
     982        break;
     983    case 5:
     984        if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
     985                              &y, &x, &temp, &n, &lattr))
     986            return NULL;
     987        attr = lattr;
     988        code = wmove(self->win, y, x);
     989        break;
     990    default:
     991        PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
     992        return NULL;
     993    }
     994
     995    if (code != ERR) {
     996        if (!PyCurses_ConvertToChtype(temp, &ch)) {
     997            PyErr_SetString(PyExc_TypeError,
     998                            "argument 1 or 3 must be a ch or an int");
     999            return NULL;
     1000        }
     1001        return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
     1002    } else
     1003        return PyCursesCheckERR(code, "wmove");
     1004}
     1005
     1006static PyObject *
     1007PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
     1008{
     1009    int rtn, x, y, use_xy = FALSE;
     1010    PyObject *temp;
     1011    chtype ch = 0;
     1012    attr_t attr = A_NORMAL;
     1013    long lattr;
     1014
     1015    switch (PyTuple_Size(args)) {
     1016    case 1:
     1017        if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
     1018            return NULL;
     1019        break;
     1020    case 2:
     1021        if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
     1022            return NULL;
     1023        attr = lattr;
     1024        break;
     1025    case 3:
     1026        if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
     1027            return NULL;
     1028        use_xy = TRUE;
     1029        break;
     1030    case 4:
     1031        if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
     1032            return NULL;
     1033        attr = lattr;
     1034        use_xy = TRUE;
     1035        break;
     1036    default:
     1037        PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
     1038        return NULL;
     1039    }
     1040
    9891041    if (!PyCurses_ConvertToChtype(temp, &ch)) {
    990       PyErr_SetString(PyExc_TypeError,
    991                       "argument 1 or 3 must be a ch or an int");
    992       return NULL;
    993     }
    994     return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
    995   } else
    996     return PyCursesCheckERR(code, "wmove");
    997 }
    998 
    999 static PyObject *
    1000 PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
    1001 {
    1002   int rtn, x, y, use_xy = FALSE;
    1003   PyObject *temp;
    1004   chtype ch = 0;
    1005   attr_t attr = A_NORMAL;
    1006   long lattr;
    1007  
    1008   switch (PyTuple_Size(args)) {
    1009   case 1:
    1010     if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
    1011       return NULL;
    1012     break;
    1013   case 2:
    1014     if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
    1015       return NULL;
    1016     attr = lattr;
    1017     break;
    1018   case 3:
    1019     if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
    1020       return NULL;
    1021     use_xy = TRUE;
    1022     break;
    1023   case 4:
    1024     if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
    1025       return NULL;
    1026     attr = lattr;
    1027     use_xy = TRUE;
    1028     break;
    1029   default:
    1030     PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
    1031     return NULL;
    1032   }
    1033 
    1034   if (!PyCurses_ConvertToChtype(temp, &ch)) {
    1035     PyErr_SetString(PyExc_TypeError,
    1036                     "argument 1 or 3 must be a ch or an int");
    1037     return NULL;
    1038   }
    1039  
    1040   if (use_xy == TRUE)
    1041     rtn = mvwinsch(self->win,y,x, ch | attr);
    1042   else {
    1043     rtn = winsch(self->win, ch | attr);
    1044   }
    1045   return PyCursesCheckERR(rtn, "insch");
     1042        PyErr_SetString(PyExc_TypeError,
     1043                        "argument 1 or 3 must be a ch or an int");
     1044        return NULL;
     1045    }
     1046
     1047    if (use_xy == TRUE)
     1048        rtn = mvwinsch(self->win,y,x, ch | attr);
     1049    else {
     1050        rtn = winsch(self->win, ch | attr);
     1051    }
     1052    return PyCursesCheckERR(rtn, "insch");
    10461053}
    10471054
     
    10491056PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
    10501057{
    1051   int x, y, rtn;
    1052 
    1053   switch (PyTuple_Size(args)) {
    1054   case 0:
    1055     rtn = winch(self->win);
    1056     break;
    1057   case 2:
    1058     if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    1059       return NULL;
    1060     rtn = mvwinch(self->win,y,x);
    1061     break;
    1062   default:
    1063     PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
    1064     return NULL;
    1065   }
    1066   return PyInt_FromLong((long) rtn);
     1058    int x, y, rtn;
     1059
     1060    switch (PyTuple_Size(args)) {
     1061    case 0:
     1062        rtn = winch(self->win);
     1063        break;
     1064    case 2:
     1065        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
     1066            return NULL;
     1067        rtn = mvwinch(self->win,y,x);
     1068        break;
     1069    default:
     1070        PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
     1071        return NULL;
     1072    }
     1073    return PyInt_FromLong((long) rtn);
    10671074}
    10681075
     
    10701077PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
    10711078{
    1072   int x, y, n;
    1073   char rtn[1024]; /* This should be big enough.. I hope */
    1074   int rtn2;
    1075 
    1076   switch (PyTuple_Size(args)) {
    1077   case 0:
    1078     rtn2 = winnstr(self->win,rtn, 1023);
    1079     break;
    1080   case 1:
    1081     if (!PyArg_ParseTuple(args,"i;n", &n))
    1082       return NULL;
    1083     rtn2 = winnstr(self->win,rtn,MIN(n,1023));
    1084     break;
    1085   case 2:
    1086     if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
    1087       return NULL;
    1088     rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
    1089     break;
    1090   case 3:
    1091     if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
    1092       return NULL;
    1093     rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
    1094     break;
    1095   default:
    1096     PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
    1097     return NULL;
    1098   }
    1099   if (rtn2 == ERR)
    1100     rtn[0] = 0;
    1101   return PyString_FromString(rtn);
     1079    int x, y, n;
     1080    char rtn[1024]; /* This should be big enough.. I hope */
     1081    int rtn2;
     1082
     1083    switch (PyTuple_Size(args)) {
     1084    case 0:
     1085        rtn2 = winnstr(self->win,rtn, 1023);
     1086        break;
     1087    case 1:
     1088        if (!PyArg_ParseTuple(args,"i;n", &n))
     1089            return NULL;
     1090        rtn2 = winnstr(self->win,rtn,MIN(n,1023));
     1091        break;
     1092    case 2:
     1093        if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
     1094            return NULL;
     1095        rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
     1096        break;
     1097    case 3:
     1098        if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
     1099            return NULL;
     1100        rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
     1101        break;
     1102    default:
     1103        PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
     1104        return NULL;
     1105    }
     1106    if (rtn2 == ERR)
     1107        rtn[0] = 0;
     1108    return PyString_FromString(rtn);
    11021109}
    11031110
     
    11051112PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
    11061113{
    1107   int rtn;
    1108   int x, y;
    1109   char *str;
    1110   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
    1111   long lattr;
    1112   int use_xy = FALSE, use_attr = FALSE;
    1113 
    1114   switch (PyTuple_Size(args)) {
    1115   case 1:
    1116     if (!PyArg_ParseTuple(args,"s;str", &str))
    1117       return NULL;
    1118     break;
    1119   case 2:
    1120     if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
    1121       return NULL;
    1122     attr = lattr;
    1123     use_attr = TRUE;
    1124     break;
    1125   case 3:
    1126     if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
    1127       return NULL;
    1128     use_xy = TRUE;
    1129     break;
    1130   case 4:
    1131     if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
    1132       return NULL;
    1133     attr = lattr;
    1134     use_xy = use_attr = TRUE;
    1135     break;
    1136   default:
    1137     PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
    1138     return NULL;
    1139   }
    1140 
    1141   if (use_attr == TRUE) {
    1142     attr_old = getattrs(self->win);
    1143     wattrset(self->win,attr);
    1144   }
    1145   if (use_xy == TRUE)
    1146     rtn = mvwinsstr(self->win,y,x,str);
    1147   else
    1148     rtn = winsstr(self->win,str);
    1149   if (use_attr == TRUE)
    1150     wattrset(self->win,attr_old);
    1151   return PyCursesCheckERR(rtn, "insstr");
     1114    int rtn;
     1115    int x, y;
     1116    char *str;
     1117    attr_t attr = A_NORMAL , attr_old = A_NORMAL;
     1118    long lattr;
     1119    int use_xy = FALSE, use_attr = FALSE;
     1120
     1121    switch (PyTuple_Size(args)) {
     1122    case 1:
     1123        if (!PyArg_ParseTuple(args,"s;str", &str))
     1124            return NULL;
     1125        break;
     1126    case 2:
     1127        if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr))
     1128            return NULL;
     1129        attr = lattr;
     1130        use_attr = TRUE;
     1131        break;
     1132    case 3:
     1133        if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
     1134            return NULL;
     1135        use_xy = TRUE;
     1136        break;
     1137    case 4:
     1138        if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr))
     1139            return NULL;
     1140        attr = lattr;
     1141        use_xy = use_attr = TRUE;
     1142        break;
     1143    default:
     1144        PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
     1145        return NULL;
     1146    }
     1147
     1148    if (use_attr == TRUE) {
     1149        attr_old = getattrs(self->win);
     1150        (void)wattrset(self->win,attr);
     1151    }
     1152    if (use_xy == TRUE)
     1153        rtn = mvwinsstr(self->win,y,x,str);
     1154    else
     1155        rtn = winsstr(self->win,str);
     1156    if (use_attr == TRUE)
     1157        (void)wattrset(self->win,attr_old);
     1158    return PyCursesCheckERR(rtn, "insstr");
    11521159}
    11531160
     
    11551162PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
    11561163{
    1157   int rtn, x, y, n;
    1158   char *str;
    1159   attr_t attr = A_NORMAL , attr_old = A_NORMAL;
    1160   long lattr;
    1161   int use_xy = FALSE, use_attr = FALSE;
    1162 
    1163   switch (PyTuple_Size(args)) {
    1164   case 2:
    1165     if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
    1166       return NULL;
    1167     break;
    1168   case 3:
    1169     if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
    1170       return NULL;
    1171     attr = lattr;
    1172     use_attr = TRUE;
    1173     break;
    1174   case 4:
    1175     if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
    1176       return NULL;
    1177     use_xy = TRUE;
    1178     break;
    1179   case 5:
    1180     if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
    1181       return NULL;
    1182     attr = lattr;
    1183     use_xy = use_attr = TRUE;
    1184     break;
    1185   default:
    1186     PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
    1187     return NULL;
    1188   }
    1189 
    1190   if (use_attr == TRUE) {
    1191     attr_old = getattrs(self->win);
    1192     wattrset(self->win,attr);
    1193   }
    1194   if (use_xy == TRUE)
    1195     rtn = mvwinsnstr(self->win,y,x,str,n);
    1196   else
    1197     rtn = winsnstr(self->win,str,n);
    1198   if (use_attr == TRUE)
    1199     wattrset(self->win,attr_old);
    1200   return PyCursesCheckERR(rtn, "insnstr");
     1164    int rtn, x, y, n;
     1165    char *str;
     1166    attr_t attr = A_NORMAL , attr_old = A_NORMAL;
     1167    long lattr;
     1168    int use_xy = FALSE, use_attr = FALSE;
     1169
     1170    switch (PyTuple_Size(args)) {
     1171    case 2:
     1172        if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
     1173            return NULL;
     1174        break;
     1175    case 3:
     1176        if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr))
     1177            return NULL;
     1178        attr = lattr;
     1179        use_attr = TRUE;
     1180        break;
     1181    case 4:
     1182        if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
     1183            return NULL;
     1184        use_xy = TRUE;
     1185        break;
     1186    case 5:
     1187        if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr))
     1188            return NULL;
     1189        attr = lattr;
     1190        use_xy = use_attr = TRUE;
     1191        break;
     1192    default:
     1193        PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
     1194        return NULL;
     1195    }
     1196
     1197    if (use_attr == TRUE) {
     1198        attr_old = getattrs(self->win);
     1199        (void)wattrset(self->win,attr);
     1200    }
     1201    if (use_xy == TRUE)
     1202        rtn = mvwinsnstr(self->win,y,x,str,n);
     1203    else
     1204        rtn = winsnstr(self->win,str,n);
     1205    if (use_attr == TRUE)
     1206        (void)wattrset(self->win,attr_old);
     1207    return PyCursesCheckERR(rtn, "insnstr");
    12011208}
    12021209
     
    12041211PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
    12051212{
    1206   int line, erg;
    1207   if (!PyArg_ParseTuple(args,"i;line", &line))
    1208     return NULL;
    1209   erg = is_linetouched(self->win, line);
    1210   if (erg == ERR) {
    1211     PyErr_SetString(PyExc_TypeError,
    1212                     "is_linetouched: line number outside of boundaries");
    1213     return NULL;
    1214   } else
    1215     if (erg == FALSE) {
    1216       Py_INCREF(Py_False);
    1217       return Py_False;
    1218     } else {
    1219       Py_INCREF(Py_True);
    1220       return Py_True;
    1221     }
     1213    int line, erg;
     1214    if (!PyArg_ParseTuple(args,"i;line", &line))
     1215        return NULL;
     1216    erg = is_linetouched(self->win, line);
     1217    if (erg == ERR) {
     1218        PyErr_SetString(PyExc_TypeError,
     1219                        "is_linetouched: line number outside of boundaries");
     1220        return NULL;
     1221    } else
     1222        if (erg == FALSE) {
     1223            Py_INCREF(Py_False);
     1224            return Py_False;
     1225        } else {
     1226            Py_INCREF(Py_True);
     1227            return Py_True;
     1228        }
    12221229}
    12231230
     
    12251232PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
    12261233{
    1227   int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
    1228   int rtn;
     1234    int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
     1235    int rtn;
    12291236
    12301237#ifndef WINDOW_HAS_FLAGS
    1231   if (0) {
     1238    if (0)
    12321239#else
    1233   if (self->win->_flags & _ISPAD) {
    1234 #endif
    1235     switch(PyTuple_Size(args)) {
    1236     case 6:
    1237       if (!PyArg_ParseTuple(args,
    1238                        "iiiiii;" \
    1239                        "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
    1240                        &pminrow, &pmincol, &sminrow,
    1241                        &smincol, &smaxrow, &smaxcol))
    1242         return NULL;
    1243       Py_BEGIN_ALLOW_THREADS
    1244       rtn = pnoutrefresh(self->win,
    1245                          pminrow, pmincol, sminrow,
    1246                          smincol, smaxrow, smaxcol);
    1247       Py_END_ALLOW_THREADS
    1248       return PyCursesCheckERR(rtn, "pnoutrefresh");
    1249     default:
    1250       PyErr_SetString(PyCursesError,
    1251                       "noutrefresh() called for a pad "
    1252                       "requires 6 arguments");
    1253       return NULL;
    1254     }
    1255   } else {
    1256     if (!PyArg_ParseTuple(args, ":noutrefresh"))
    1257       return NULL;   
    1258 
    1259     Py_BEGIN_ALLOW_THREADS
    1260     rtn = wnoutrefresh(self->win);
    1261     Py_END_ALLOW_THREADS
    1262     return PyCursesCheckERR(rtn, "wnoutrefresh");
    1263   }
     1240        if (self->win->_flags & _ISPAD)
     1241#endif
     1242        {
     1243            switch(PyTuple_Size(args)) {
     1244            case 6:
     1245                if (!PyArg_ParseTuple(args,
     1246                                      "iiiiii;" \
     1247                                      "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
     1248                                      &pminrow, &pmincol, &sminrow,
     1249                                      &smincol, &smaxrow, &smaxcol))
     1250                    return NULL;
     1251                Py_BEGIN_ALLOW_THREADS
     1252                rtn = pnoutrefresh(self->win,
     1253                                   pminrow, pmincol, sminrow,
     1254                                   smincol, smaxrow, smaxcol);
     1255                Py_END_ALLOW_THREADS
     1256                return PyCursesCheckERR(rtn, "pnoutrefresh");
     1257            default:
     1258                PyErr_SetString(PyCursesError,
     1259                                "noutrefresh() called for a pad "
     1260                                "requires 6 arguments");
     1261                return NULL;
     1262            }
     1263        } else {
     1264            if (!PyArg_ParseTuple(args, ":noutrefresh"))
     1265                return NULL;
     1266
     1267            Py_BEGIN_ALLOW_THREADS
     1268            rtn = wnoutrefresh(self->win);
     1269            Py_END_ALLOW_THREADS
     1270            return PyCursesCheckERR(rtn, "wnoutrefresh");
     1271        }
    12641272}
    12651273
     
    12711279    int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
    12721280    int rtn;
    1273    
     1281
    12741282    switch (PyTuple_Size(args)) {
    12751283    case 1:
    1276         if (!PyArg_ParseTuple(args, "O!;window object",
    1277                               &PyCursesWindow_Type, &temp))
    1278             return NULL;
    1279         break;
     1284        if (!PyArg_ParseTuple(args, "O!;window object",
     1285                              &PyCursesWindow_Type, &temp))
     1286            return NULL;
     1287        break;
    12801288    case 7:
    1281         if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
    1282                               &PyCursesWindow_Type, &temp, &sminrow, &smincol,
    1283                               &dminrow, &dmincol, &dmaxrow, &dmaxcol))
    1284             return NULL;
    1285         use_copywin = TRUE;
    1286         break;
    1287     default:
    1288         PyErr_SetString(PyExc_TypeError,
    1289                         "overlay requires one or seven arguments");
    1290         return NULL;
     1289        if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
     1290                              &PyCursesWindow_Type, &temp, &sminrow, &smincol,
     1291                              &dminrow, &dmincol, &dmaxrow, &dmaxcol))
     1292            return NULL;
     1293        use_copywin = TRUE;
     1294        break;
     1295    default:
     1296        PyErr_SetString(PyExc_TypeError,
     1297                        "overlay requires one or seven arguments");
     1298        return NULL;
    12911299    }
    12921300
    12931301    if (use_copywin == TRUE) {
    1294             rtn = copywin(self->win, temp->win, sminrow, smincol,
    1295                           dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
    1296             return PyCursesCheckERR(rtn, "copywin");
     1302        rtn = copywin(self->win, temp->win, sminrow, smincol,
     1303                      dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
     1304        return PyCursesCheckERR(rtn, "copywin");
    12971305    }
    12981306    else {
    1299             rtn = overlay(self->win, temp->win);
    1300             return PyCursesCheckERR(rtn, "overlay");
     1307        rtn = overlay(self->win, temp->win);
     1308        return PyCursesCheckERR(rtn, "overlay");
    13011309    }
    13021310}
     
    13091317    int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
    13101318    int rtn;
    1311    
     1319
    13121320    switch (PyTuple_Size(args)) {
    13131321    case 1:
    1314         if (!PyArg_ParseTuple(args, "O!;window object",
    1315                               &PyCursesWindow_Type, &temp))
    1316             return NULL;
    1317         break;
     1322        if (!PyArg_ParseTuple(args, "O!;window object",
     1323                              &PyCursesWindow_Type, &temp))
     1324            return NULL;
     1325        break;
    13181326    case 7:
    1319         if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
    1320                               &PyCursesWindow_Type, &temp, &sminrow, &smincol,
    1321                               &dminrow, &dmincol, &dmaxrow, &dmaxcol))
    1322             return NULL;
    1323         use_copywin = TRUE;
    1324         break;
    1325     default:
    1326         PyErr_SetString(PyExc_TypeError,
    1327                         "overwrite requires one or seven arguments");
    1328         return NULL;
     1327        if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
     1328                              &PyCursesWindow_Type, &temp, &sminrow, &smincol,
     1329                              &dminrow, &dmincol, &dmaxrow, &dmaxcol))
     1330            return NULL;
     1331        use_copywin = TRUE;
     1332        break;
     1333    default:
     1334        PyErr_SetString(PyExc_TypeError,
     1335                        "overwrite requires one or seven arguments");
     1336        return NULL;
    13291337    }
    13301338
    13311339    if (use_copywin == TRUE) {
    1332         rtn = copywin(self->win, temp->win, sminrow, smincol,
    1333                       dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
     1340        rtn = copywin(self->win, temp->win, sminrow, smincol,
     1341                      dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
    13341342        return PyCursesCheckERR(rtn, "copywin");
    13351343    }
    13361344    else {
    1337             rtn = overwrite(self->win, temp->win);
    1338             return PyCursesCheckERR(rtn, "overwrite");
     1345        rtn = overwrite(self->win, temp->win);
     1346        return PyCursesCheckERR(rtn, "overwrite");
    13391347    }
    13401348}
     
    13431351PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
    13441352{
    1345   PyObject *temp;
    1346  
    1347   if (!PyArg_ParseTuple(args, "O;fileobj", &temp))
    1348     return NULL;
    1349   if (!PyFile_Check(temp)) {
    1350     PyErr_SetString(PyExc_TypeError, "argument must be a file object");
    1351     return NULL;
    1352   }
    1353   return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
    1354                           "putwin");
     1353    PyObject *temp;
     1354
     1355    if (!PyArg_ParseTuple(args, "O;fileobj", &temp))
     1356        return NULL;
     1357    if (!PyFile_Check(temp)) {
     1358        PyErr_SetString(PyExc_TypeError, "argument must be a file object");
     1359        return NULL;
     1360    }
     1361    return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
     1362                            "putwin");
    13551363}
    13561364
     
    13581366PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
    13591367{
    1360   int beg, num;
    1361   if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
    1362     return NULL;
    1363   return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
     1368    int beg, num;
     1369    if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
     1370        return NULL;
     1371    return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
    13641372}
    13651373
     
    13671375PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
    13681376{
    1369   int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
    1370   int rtn;
    1371  
     1377    int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
     1378    int rtn;
     1379
    13721380#ifndef WINDOW_HAS_FLAGS
    1373   if (0) {
     1381    if (0)
    13741382#else
    1375   if (self->win->_flags & _ISPAD) {
    1376 #endif
     1383        if (self->win->_flags & _ISPAD)
     1384#endif
     1385        {
     1386            switch(PyTuple_Size(args)) {
     1387            case 6:
     1388                if (!PyArg_ParseTuple(args,
     1389                                      "iiiiii;" \
     1390                                      "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
     1391                                      &pminrow, &pmincol, &sminrow,
     1392                                      &smincol, &smaxrow, &smaxcol))
     1393                    return NULL;
     1394
     1395                Py_BEGIN_ALLOW_THREADS
     1396                rtn = prefresh(self->win,
     1397                               pminrow, pmincol, sminrow,
     1398                               smincol, smaxrow, smaxcol);
     1399                Py_END_ALLOW_THREADS
     1400                return PyCursesCheckERR(rtn, "prefresh");
     1401            default:
     1402                PyErr_SetString(PyCursesError,
     1403                                "refresh() for a pad requires 6 arguments");
     1404                return NULL;
     1405            }
     1406        } else {
     1407            if (!PyArg_ParseTuple(args, ":refresh"))
     1408                return NULL;
     1409            Py_BEGIN_ALLOW_THREADS
     1410            rtn = wrefresh(self->win);
     1411            Py_END_ALLOW_THREADS
     1412            return PyCursesCheckERR(rtn, "prefresh");
     1413        }
     1414}
     1415
     1416static PyObject *
     1417PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
     1418{
     1419    int x, y;
     1420    if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
     1421        return NULL;
     1422    return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
     1423}
     1424
     1425static PyObject *
     1426PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
     1427{
     1428    WINDOW *win;
     1429    int nlines, ncols, begin_y, begin_x;
     1430
     1431    nlines = 0;
     1432    ncols  = 0;
     1433    switch (PyTuple_Size(args)) {
     1434    case 2:
     1435        if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
     1436            return NULL;
     1437        break;
     1438    case 4:
     1439        if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
     1440                              &nlines,&ncols,&begin_y,&begin_x))
     1441            return NULL;
     1442        break;
     1443    default:
     1444        PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
     1445        return NULL;
     1446    }
     1447
     1448    /* printf("Subwin: %i %i %i %i   \n", nlines, ncols, begin_y, begin_x); */
     1449#ifdef WINDOW_HAS_FLAGS
     1450    if (self->win->_flags & _ISPAD)
     1451        win = subpad(self->win, nlines, ncols, begin_y, begin_x);
     1452    else
     1453#endif
     1454        win = subwin(self->win, nlines, ncols, begin_y, begin_x);
     1455
     1456    if (win == NULL) {
     1457        PyErr_SetString(PyCursesError, catchall_NULL);
     1458        return NULL;
     1459    }
     1460
     1461    return (PyObject *)PyCursesWindow_New(win);
     1462}
     1463
     1464static PyObject *
     1465PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
     1466{
     1467    int nlines;
    13771468    switch(PyTuple_Size(args)) {
    1378     case 6:
    1379       if (!PyArg_ParseTuple(args,
    1380                        "iiiiii;" \
    1381                        "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
    1382                        &pminrow, &pmincol, &sminrow,
    1383                        &smincol, &smaxrow, &smaxcol))
    1384         return NULL;
    1385 
    1386       Py_BEGIN_ALLOW_THREADS
    1387       rtn = prefresh(self->win,
    1388                      pminrow, pmincol, sminrow,
    1389                      smincol, smaxrow, smaxcol);
    1390       Py_END_ALLOW_THREADS
    1391       return PyCursesCheckERR(rtn, "prefresh");
    1392     default:
    1393       PyErr_SetString(PyCursesError,
    1394                       "refresh() for a pad requires 6 arguments");
    1395       return NULL;
    1396     }
    1397   } else {
    1398     if (!PyArg_ParseTuple(args, ":refresh"))
    1399       return NULL;   
    1400     Py_BEGIN_ALLOW_THREADS
    1401     rtn = wrefresh(self->win);
    1402     Py_END_ALLOW_THREADS
    1403     return PyCursesCheckERR(rtn, "prefresh");   
    1404   }
    1405 }
    1406 
    1407 static PyObject *
    1408 PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
    1409 {
    1410   int x, y;
    1411   if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
    1412     return NULL;
    1413   return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
    1414 }
    1415 
    1416 static PyObject *
    1417 PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
    1418 {
    1419   WINDOW *win;
    1420   int nlines, ncols, begin_y, begin_x;
    1421 
    1422   nlines = 0;
    1423   ncols  = 0;
    1424   switch (PyTuple_Size(args)) {
    1425   case 2:
    1426     if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
    1427       return NULL;
    1428     break;
    1429   case 4:
    1430     if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
    1431                    &nlines,&ncols,&begin_y,&begin_x))
    1432       return NULL;
    1433     break;
    1434   default:
    1435     PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
    1436     return NULL;
    1437   }
    1438 
    1439   /* printf("Subwin: %i %i %i %i   \n", nlines, ncols, begin_y, begin_x); */
    1440 #ifdef WINDOW_HAS_FLAGS
    1441   if (self->win->_flags & _ISPAD)
    1442     win = subpad(self->win, nlines, ncols, begin_y, begin_x);
    1443   else
    1444 #endif
    1445     win = subwin(self->win, nlines, ncols, begin_y, begin_x);
    1446 
    1447   if (win == NULL) {
    1448     PyErr_SetString(PyCursesError, catchall_NULL);
    1449     return NULL;
    1450   }
    1451  
    1452   return (PyObject *)PyCursesWindow_New(win);
    1453 }
    1454 
    1455 static PyObject *
    1456 PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
    1457 {
    1458   int nlines;
    1459   switch(PyTuple_Size(args)) {
    1460   case 0:
    1461     return PyCursesCheckERR(scroll(self->win), "scroll");
    1462   case 1:
    1463     if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
    1464       return NULL;
    1465     return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
    1466   default:
    1467     PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
    1468     return NULL;
    1469   }
     1469    case 0:
     1470        return PyCursesCheckERR(scroll(self->win), "scroll");
     1471    case 1:
     1472        if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
     1473            return NULL;
     1474        return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
     1475    default:
     1476        PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
     1477        return NULL;
     1478    }
    14701479}
    14711480
     
    14731482PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
    14741483{
    1475   int st, cnt, val;
    1476   switch (PyTuple_Size(args)) {
    1477   case 2:
    1478     if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
    1479       return NULL;
    1480     return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
    1481   case 3:
    1482     if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
    1483       return NULL;
    1484     return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
    1485   default:
    1486     PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
    1487     return NULL;
    1488   }
     1484    int st, cnt, val;
     1485    switch (PyTuple_Size(args)) {
     1486    case 2:
     1487        if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
     1488            return NULL;
     1489        return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
     1490    case 3:
     1491        if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
     1492            return NULL;
     1493        return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
     1494    default:
     1495        PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
     1496        return NULL;
     1497    }
    14891498}
    14901499
     
    14921501PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
    14931502{
    1494   PyObject *temp;
    1495   chtype ch;
    1496   int n, x, y, code = OK;
    1497   attr_t attr = A_NORMAL;
    1498   long lattr;
    1499 
    1500   switch (PyTuple_Size(args)) {
    1501   case 2:
    1502     if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
    1503       return NULL;
    1504     break;
    1505   case 3:
    1506     if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
    1507       return NULL;
    1508     attr = lattr;
    1509     break;
    1510   case 4:
    1511     if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
    1512       return NULL;
    1513     code = wmove(self->win, y, x);
    1514     break;
    1515   case 5:
    1516     if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
    1517                      &y, &x, &temp, &n, &lattr))
    1518       return NULL;
    1519     attr = lattr;
    1520     code = wmove(self->win, y, x);
    1521     break;
    1522   default:
    1523     PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
    1524     return NULL;
    1525   }
    1526 
    1527   if (code != ERR) {
    1528     if (!PyCurses_ConvertToChtype(temp, &ch)) {
    1529       PyErr_SetString(PyExc_TypeError,
    1530                       "argument 1 or 3 must be a ch or an int");
    1531       return NULL;
    1532     }
    1533     return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
    1534   } else
    1535     return PyCursesCheckERR(code, "wmove");
     1503    PyObject *temp;
     1504    chtype ch;
     1505    int n, x, y, code = OK;
     1506    attr_t attr = A_NORMAL;
     1507    long lattr;
     1508
     1509    switch (PyTuple_Size(args)) {
     1510    case 2:
     1511        if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
     1512            return NULL;
     1513        break;
     1514    case 3:
     1515        if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
     1516            return NULL;
     1517        attr = lattr;
     1518        break;
     1519    case 4:
     1520        if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
     1521            return NULL;
     1522        code = wmove(self->win, y, x);
     1523        break;
     1524    case 5:
     1525        if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
     1526                              &y, &x, &temp, &n, &lattr))
     1527            return NULL;
     1528        attr = lattr;
     1529        code = wmove(self->win, y, x);
     1530        break;
     1531    default:
     1532        PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
     1533        return NULL;
     1534    }
     1535
     1536    if (code != ERR) {
     1537        if (!PyCurses_ConvertToChtype(temp, &ch)) {
     1538            PyErr_SetString(PyExc_TypeError,
     1539                            "argument 1 or 3 must be a ch or an int");
     1540            return NULL;
     1541        }
     1542        return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
     1543    } else
     1544        return PyCursesCheckERR(code, "wmove");
    15361545}
    15371546
    15381547static PyMethodDef PyCursesWindow_Methods[] = {
    1539         {"addch",           (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
    1540         {"addnstr",         (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
    1541         {"addstr",          (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
    1542         {"attroff",         (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
    1543         {"attron",          (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
    1544         {"attrset",         (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
    1545         {"bkgd",            (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
    1546         {"chgat",           (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
    1547         {"bkgdset",         (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
    1548         {"border",          (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
    1549         {"box",             (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
    1550         {"clear",           (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
    1551         {"clearok",         (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
    1552         {"clrtobot",        (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
    1553         {"clrtoeol",        (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
    1554         {"cursyncup",       (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
    1555         {"delch",           (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
    1556         {"deleteln",        (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
    1557         {"derwin",          (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
    1558         {"echochar",        (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
     1548    {"addch",           (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
     1549    {"addnstr",         (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
     1550    {"addstr",          (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
     1551    {"attroff",         (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
     1552    {"attron",          (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
     1553    {"attrset",         (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
     1554    {"bkgd",            (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
     1555    {"chgat",           (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
     1556    {"bkgdset",         (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
     1557    {"border",          (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
     1558    {"box",             (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
     1559    {"clear",           (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
     1560    {"clearok",         (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
     1561    {"clrtobot",        (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
     1562    {"clrtoeol",        (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
     1563    {"cursyncup",       (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
     1564    {"delch",           (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
     1565    {"deleteln",        (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
     1566    {"derwin",          (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
     1567    {"echochar",        (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
    15591568#ifdef NCURSES_MOUSE_VERSION
    1560         {"enclose",         (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
    1561 #endif
    1562         {"erase",           (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
    1563         {"getbegyx",        (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
    1564         {"getbkgd",         (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
    1565         {"getch",           (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
    1566         {"getkey",          (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
    1567         {"getmaxyx",        (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
    1568         {"getparyx",        (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
    1569         {"getstr",          (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
    1570         {"getyx",           (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
    1571         {"hline",           (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
    1572         {"idcok",           (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
    1573         {"idlok",           (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
    1574         {"immedok",         (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
    1575         {"inch",            (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
    1576         {"insch",           (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
    1577         {"insdelln",        (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
    1578         {"insertln",        (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
    1579         {"insnstr",         (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
    1580         {"insstr",          (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
    1581         {"instr",           (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
    1582         {"is_linetouched",  (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
    1583         {"is_wintouched",   (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
    1584         {"keypad",          (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
    1585         {"leaveok",         (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
    1586         {"move",            (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
    1587         {"mvderwin",        (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
    1588         {"mvwin",           (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
    1589         {"nodelay",         (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
    1590         {"notimeout",       (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
    1591         {"noutrefresh",     (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
    1592         /* Backward compatibility alias -- remove in Python 2.3 */
    1593         {"nooutrefresh",    (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
    1594         {"overlay",         (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
    1595         {"overwrite",       (PyCFunction)PyCursesWindow_Overwrite,
    1596          METH_VARARGS},
    1597         {"putwin",          (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS},
    1598         {"redrawln",        (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
    1599         {"redrawwin",       (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
    1600         {"refresh",         (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
     1569    {"enclose",         (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
     1570#endif
     1571    {"erase",           (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
     1572    {"getbegyx",        (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
     1573    {"getbkgd",         (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
     1574    {"getch",           (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
     1575    {"getkey",          (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
     1576    {"getmaxyx",        (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
     1577    {"getparyx",        (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
     1578    {"getstr",          (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
     1579    {"getyx",           (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
     1580    {"hline",           (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
     1581    {"idcok",           (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
     1582    {"idlok",           (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
     1583    {"immedok",         (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
     1584    {"inch",            (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
     1585    {"insch",           (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
     1586    {"insdelln",        (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
     1587    {"insertln",        (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
     1588    {"insnstr",         (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
     1589    {"insstr",          (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
     1590    {"instr",           (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
     1591    {"is_linetouched",  (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
     1592    {"is_wintouched",   (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
     1593    {"keypad",          (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
     1594    {"leaveok",         (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
     1595    {"move",            (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
     1596    {"mvderwin",        (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
     1597    {"mvwin",           (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
     1598    {"nodelay",         (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
     1599    {"notimeout",       (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
     1600    {"noutrefresh",     (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
     1601    /* Backward compatibility alias -- remove in Python 2.3 */
     1602    {"nooutrefresh",    (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
     1603    {"overlay",         (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
     1604    {"overwrite",       (PyCFunction)PyCursesWindow_Overwrite,
     1605     METH_VARARGS},
     1606    {"putwin",          (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS},
     1607    {"redrawln",        (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
     1608    {"redrawwin",       (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
     1609    {"refresh",         (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
    16011610#ifndef STRICT_SYSV_CURSES
    1602         {"resize",          (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
    1603 #endif
    1604         {"scroll",          (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
    1605         {"scrollok",        (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
    1606         {"setscrreg",       (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
    1607         {"standend",        (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
    1608         {"standout",        (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
    1609         {"subpad",          (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
    1610         {"subwin",          (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
    1611         {"syncdown",        (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
    1612         {"syncok",          (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
    1613         {"syncup",          (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
    1614         {"timeout",         (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
    1615         {"touchline",       (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
    1616         {"touchwin",        (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
    1617         {"untouchwin",      (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
    1618         {"vline",           (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
    1619         {NULL,              NULL}   /* sentinel */
     1611    {"resize",          (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
     1612#endif
     1613    {"scroll",          (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
     1614    {"scrollok",        (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
     1615    {"setscrreg",       (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
     1616    {"standend",        (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
     1617    {"standout",        (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
     1618    {"subpad",          (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
     1619    {"subwin",          (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
     1620    {"syncdown",        (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
     1621    {"syncok",          (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
     1622    {"syncup",          (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
     1623    {"timeout",         (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
     1624    {"touchline",       (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
     1625    {"touchwin",        (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
     1626    {"untouchwin",      (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
     1627    {"vline",           (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
     1628    {NULL,                  NULL}   /* sentinel */
    16201629};
    16211630
     
    16231632PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
    16241633{
    1625   return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
     1634    return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
    16261635}
    16271636
     
    16291638
    16301639PyTypeObject PyCursesWindow_Type = {
    1631         PyVarObject_HEAD_INIT(NULL, 0)
    1632         "_curses.curses window",        /*tp_name*/
    1633         sizeof(PyCursesWindowObject),   /*tp_basicsize*/
    1634         0,                      /*tp_itemsize*/
    1635         /* methods */
    1636         (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
    1637         0,                      /*tp_print*/
    1638         (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
    1639         (setattrfunc)0, /*tp_setattr*/
    1640         0,                      /*tp_compare*/
    1641         0,                      /*tp_repr*/
    1642         0,                      /*tp_as_number*/
    1643         0,                      /*tp_as_sequence*/
    1644         0,                      /*tp_as_mapping*/
    1645         0,                      /*tp_hash*/
     1640    PyVarObject_HEAD_INIT(NULL, 0)
     1641    "_curses.curses window",            /*tp_name*/
     1642    sizeof(PyCursesWindowObject),       /*tp_basicsize*/
     1643    0,                          /*tp_itemsize*/
     1644    /* methods */
     1645    (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
     1646    0,                          /*tp_print*/
     1647    (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
     1648    (setattrfunc)0, /*tp_setattr*/
     1649    0,                          /*tp_compare*/
     1650    0,                          /*tp_repr*/
     1651    0,                          /*tp_as_number*/
     1652    0,                          /*tp_as_sequence*/
     1653    0,                          /*tp_as_mapping*/
     1654    0,                          /*tp_hash*/
    16461655};
    16471656
     
    16871696PyCurses_filter(PyObject *self)
    16881697{
    1689   /* not checking for PyCursesInitialised here since filter() must
    1690      be called before initscr() */
    1691   filter();
    1692   Py_INCREF(Py_None);
    1693   return Py_None;
     1698    /* not checking for PyCursesInitialised here since filter() must
     1699       be called before initscr() */
     1700    filter();
     1701    Py_INCREF(Py_None);
     1702    return Py_None;
    16941703}
    16951704
     
    16971706PyCurses_Color_Content(PyObject *self, PyObject *args)
    16981707{
    1699   short color,r,g,b;
    1700 
    1701   PyCursesInitialised
    1702   PyCursesInitialisedColor
    1703 
    1704   if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
    1705 
    1706   if (color_content(color, &r, &g, &b) != ERR)
    1707     return Py_BuildValue("(iii)", r, g, b);
    1708   else {
    1709     PyErr_SetString(PyCursesError,
    1710                     "Argument 1 was out of range. Check value of COLORS.");
    1711     return NULL;
    1712   }
     1708    short color,r,g,b;
     1709
     1710    PyCursesInitialised;
     1711    PyCursesInitialisedColor;
     1712
     1713    if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
     1714
     1715    if (color_content(color, &r, &g, &b) != ERR)
     1716        return Py_BuildValue("(iii)", r, g, b);
     1717    else {
     1718        PyErr_SetString(PyCursesError,
     1719                        "Argument 1 was out of range. Check value of COLORS.");
     1720        return NULL;
     1721    }
    17131722}
    17141723
     
    17161725PyCurses_color_pair(PyObject *self, PyObject *args)
    17171726{
    1718   int n;
    1719 
    1720   PyCursesInitialised
    1721   PyCursesInitialisedColor
    1722 
    1723   if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
    1724   return PyInt_FromLong((long) (n << 8));
     1727    int n;
     1728
     1729    PyCursesInitialised;
     1730    PyCursesInitialisedColor;
     1731
     1732    if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
     1733    return PyInt_FromLong((long) (n << 8));
    17251734}
    17261735
     
    17281737PyCurses_Curs_Set(PyObject *self, PyObject *args)
    17291738{
    1730   int vis,erg;
    1731 
    1732   PyCursesInitialised
    1733 
    1734   if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
    1735 
    1736   erg = curs_set(vis);
    1737   if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
    1738 
    1739   return PyInt_FromLong((long) erg);
     1739    int vis,erg;
     1740
     1741    PyCursesInitialised;
     1742
     1743    if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
     1744
     1745    erg = curs_set(vis);
     1746    if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
     1747
     1748    return PyInt_FromLong((long) erg);
    17401749}
    17411750
     
    17431752PyCurses_Delay_Output(PyObject *self, PyObject *args)
    17441753{
    1745   int ms;
    1746 
    1747   PyCursesInitialised
    1748 
    1749   if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
    1750 
    1751   return PyCursesCheckERR(delay_output(ms), "delay_output");
     1754    int ms;
     1755
     1756    PyCursesInitialised;
     1757
     1758    if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
     1759
     1760    return PyCursesCheckERR(delay_output(ms), "delay_output");
    17521761}
    17531762
     
    17551764PyCurses_EraseChar(PyObject *self)
    17561765{
    1757   char ch;
    1758 
    1759   PyCursesInitialised
    1760 
    1761   ch = erasechar();
    1762 
    1763   return PyString_FromStringAndSize(&ch, 1);
     1766    char ch;
     1767
     1768    PyCursesInitialised;
     1769
     1770    ch = erasechar();
     1771
     1772    return PyString_FromStringAndSize(&ch, 1);
    17641773}
    17651774
     
    17671776PyCurses_getsyx(PyObject *self)
    17681777{
    1769   int x,y;
    1770 
    1771   PyCursesInitialised
    1772 
    1773   getsyx(y, x);
    1774 
    1775   return Py_BuildValue("(ii)", y, x);
     1778    int x = 0;
     1779    int y = 0;
     1780
     1781    PyCursesInitialised;
     1782
     1783    getsyx(y, x);
     1784
     1785    return Py_BuildValue("(ii)", y, x);
    17761786}
    17771787
     
    17801790PyCurses_GetMouse(PyObject *self)
    17811791{
    1782         int rtn;
    1783         MEVENT event;
    1784 
    1785         PyCursesInitialised
    1786 
    1787         rtn = getmouse( &event );
    1788         if (rtn == ERR) {
    1789                 PyErr_SetString(PyCursesError, "getmouse() returned ERR");
    1790                 return NULL;
    1791         }
    1792         return Py_BuildValue("(hiiil)",
    1793                              (short)event.id,
    1794                              event.x, event.y, event.z,
    1795                              (long) event.bstate);
     1792    int rtn;
     1793    MEVENT event;
     1794
     1795    PyCursesInitialised;
     1796
     1797    rtn = getmouse( &event );
     1798    if (rtn == ERR) {
     1799        PyErr_SetString(PyCursesError, "getmouse() returned ERR");
     1800        return NULL;
     1801    }
     1802    return Py_BuildValue("(hiiil)",
     1803                         (short)event.id,
     1804                         event.x, event.y, event.z,
     1805                         (long) event.bstate);
    17961806}
    17971807
     
    17991809PyCurses_UngetMouse(PyObject *self, PyObject *args)
    18001810{
    1801         MEVENT event;
    1802 
    1803         PyCursesInitialised
    1804         if (!PyArg_ParseTuple(args, "hiiil",
    1805                              &event.id,
    1806                              &event.x, &event.y, &event.z,
    1807                              (int *) &event.bstate))
    1808           return NULL;
    1809 
    1810         return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
     1811    MEVENT event;
     1812
     1813    PyCursesInitialised;
     1814    if (!PyArg_ParseTuple(args, "hiiil",
     1815                          &event.id,
     1816                          &event.x, &event.y, &event.z,
     1817                          (int *) &event.bstate))
     1818        return NULL;
     1819
     1820    return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
    18111821}
    18121822#endif
     
    18151825PyCurses_GetWin(PyCursesWindowObject *self, PyObject *temp)
    18161826{
    1817   WINDOW *win;
    1818 
    1819   PyCursesInitialised
    1820 
    1821   if (!PyFile_Check(temp)) {
    1822     PyErr_SetString(PyExc_TypeError, "argument must be a file object");
    1823     return NULL;
    1824   }
    1825 
    1826   win = getwin(PyFile_AsFile(temp));
    1827 
    1828   if (win == NULL) {
    1829     PyErr_SetString(PyCursesError, catchall_NULL);
    1830     return NULL;
    1831   }
    1832 
    1833   return PyCursesWindow_New(win);
     1827    WINDOW *win;
     1828
     1829    PyCursesInitialised;
     1830
     1831    if (!PyFile_Check(temp)) {
     1832        PyErr_SetString(PyExc_TypeError, "argument must be a file object");
     1833        return NULL;
     1834    }
     1835
     1836    win = getwin(PyFile_AsFile(temp));
     1837
     1838    if (win == NULL) {
     1839        PyErr_SetString(PyCursesError, catchall_NULL);
     1840        return NULL;
     1841    }
     1842
     1843    return PyCursesWindow_New(win);
    18341844}
    18351845
     
    18371847PyCurses_HalfDelay(PyObject *self, PyObject *args)
    18381848{
    1839   unsigned char tenths;
    1840 
    1841   PyCursesInitialised
    1842 
    1843   if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
    1844 
    1845   return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
     1849    unsigned char tenths;
     1850
     1851    PyCursesInitialised;
     1852
     1853    if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
     1854
     1855    return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
    18461856}
    18471857
    18481858#ifndef STRICT_SYSV_CURSES
    1849  /* No has_key! */
     1859/* No has_key! */
    18501860static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
    18511861{
    1852   int ch;
    1853 
    1854   PyCursesInitialised
    1855 
    1856   if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
    1857 
    1858   if (has_key(ch) == FALSE) {
    1859     Py_INCREF(Py_False);
    1860     return Py_False;
    1861   }
    1862   Py_INCREF(Py_True);
    1863   return Py_True;
     1862    int ch;
     1863
     1864    PyCursesInitialised;
     1865
     1866    if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
     1867
     1868    if (has_key(ch) == FALSE) {
     1869        Py_INCREF(Py_False);
     1870        return Py_False;
     1871    }
     1872    Py_INCREF(Py_True);
     1873    return Py_True;
    18641874}
    18651875#endif /* STRICT_SYSV_CURSES */
     
    18681878PyCurses_Init_Color(PyObject *self, PyObject *args)
    18691879{
    1870   short color, r, g, b;
    1871 
    1872   PyCursesInitialised
    1873   PyCursesInitialisedColor
    1874 
    1875   switch(PyTuple_Size(args)) {
    1876   case 4:
    1877     if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
    1878     break;
    1879   default:
    1880     PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
    1881     return NULL;
    1882   }
    1883 
    1884   return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
     1880    short color, r, g, b;
     1881
     1882    PyCursesInitialised;
     1883    PyCursesInitialisedColor;
     1884
     1885    switch(PyTuple_Size(args)) {
     1886    case 4:
     1887        if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
     1888        break;
     1889    default:
     1890        PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
     1891        return NULL;
     1892    }
     1893
     1894    return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
    18851895}
    18861896
     
    18881898PyCurses_Init_Pair(PyObject *self, PyObject *args)
    18891899{
    1890   short pair, f, b;
    1891 
    1892   PyCursesInitialised
    1893   PyCursesInitialisedColor
    1894 
    1895   if (PyTuple_Size(args) != 3) {
    1896     PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
    1897     return NULL;
    1898   }
    1899 
    1900   if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
    1901 
    1902   return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
     1900    short pair, f, b;
     1901
     1902    PyCursesInitialised;
     1903    PyCursesInitialisedColor;
     1904
     1905    if (PyTuple_Size(args) != 3) {
     1906        PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
     1907        return NULL;
     1908    }
     1909
     1910    if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
     1911
     1912    return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
    19031913}
    19041914
    19051915static PyObject *ModDict;
    19061916
    1907 static PyObject * 
     1917static PyObject *
    19081918PyCurses_InitScr(PyObject *self)
    19091919{
    1910   WINDOW *win;
    1911 
    1912   if (initialised == TRUE) {
    1913     wrefresh(stdscr);
    1914     return (PyObject *)PyCursesWindow_New(stdscr);
    1915   }
    1916 
    1917   win = initscr();
    1918 
    1919   if (win == NULL) {
    1920     PyErr_SetString(PyCursesError, catchall_NULL);
    1921     return NULL;
    1922   }
    1923 
    1924   initialised = initialised_setupterm = TRUE;
     1920    WINDOW *win;
     1921
     1922    if (initialised == TRUE) {
     1923        wrefresh(stdscr);
     1924        return (PyObject *)PyCursesWindow_New(stdscr);
     1925    }
     1926
     1927    win = initscr();
     1928
     1929    if (win == NULL) {
     1930        PyErr_SetString(PyCursesError, catchall_NULL);
     1931        return NULL;
     1932    }
     1933
     1934    initialised = initialised_setupterm = TRUE;
    19251935
    19261936/* This was moved from initcurses() because it core dumped on SGI,
    19271937   where they're not defined until you've called initscr() */
    1928 #define SetDictInt(string,ch) \
    1929     do {                                                        \
    1930         PyObject *o = PyInt_FromLong((long) (ch));              \
    1931         if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
    1932             Py_DECREF(o);                                       \
    1933         }                                                       \
     1938#define SetDictInt(string,ch)                                           \
     1939    do {                                                                \
     1940        PyObject *o = PyInt_FromLong((long) (ch));                      \
     1941        if (o && PyDict_SetItemString(ModDict, string, o) == 0)     {  \
     1942            Py_DECREF(o);                                               \
     1943        }                                                               \
    19341944    } while (0)
    19351945
    1936         /* Here are some graphic symbols you can use */
    1937         SetDictInt("ACS_ULCORNER",      (ACS_ULCORNER));
    1938         SetDictInt("ACS_LLCORNER",      (ACS_LLCORNER));
    1939         SetDictInt("ACS_URCORNER",      (ACS_URCORNER));
    1940         SetDictInt("ACS_LRCORNER",      (ACS_LRCORNER));
    1941         SetDictInt("ACS_LTEE",          (ACS_LTEE));
    1942         SetDictInt("ACS_RTEE",          (ACS_RTEE));
    1943         SetDictInt("ACS_BTEE",          (ACS_BTEE));
    1944         SetDictInt("ACS_TTEE",          (ACS_TTEE));
    1945         SetDictInt("ACS_HLINE",         (ACS_HLINE));
    1946         SetDictInt("ACS_VLINE",         (ACS_VLINE));
    1947         SetDictInt("ACS_PLUS",          (ACS_PLUS));
     1946    /* Here are some graphic symbols you can use */
     1947    SetDictInt("ACS_ULCORNER",      (ACS_ULCORNER));
     1948    SetDictInt("ACS_LLCORNER",      (ACS_LLCORNER));
     1949    SetDictInt("ACS_URCORNER",      (ACS_URCORNER));
     1950    SetDictInt("ACS_LRCORNER",      (ACS_LRCORNER));
     1951    SetDictInt("ACS_LTEE",          (ACS_LTEE));
     1952    SetDictInt("ACS_RTEE",          (ACS_RTEE));
     1953    SetDictInt("ACS_BTEE",          (ACS_BTEE));
     1954    SetDictInt("ACS_TTEE",          (ACS_TTEE));
     1955    SetDictInt("ACS_HLINE",         (ACS_HLINE));
     1956    SetDictInt("ACS_VLINE",         (ACS_VLINE));
     1957    SetDictInt("ACS_PLUS",          (ACS_PLUS));
    19481958#if !defined(__hpux) || defined(HAVE_NCURSES_H)
    1949         /* On HP/UX 11, these are of type cchar_t, which is not an
    1950            integral type. If this is a problem on more platforms, a
    1951            configure test should be added to determine whether ACS_S1
    1952            is of integral type. */
    1953         SetDictInt("ACS_S1",            (ACS_S1));
    1954         SetDictInt("ACS_S9",            (ACS_S9));
    1955         SetDictInt("ACS_DIAMOND",       (ACS_DIAMOND));
    1956         SetDictInt("ACS_CKBOARD",       (ACS_CKBOARD));
    1957         SetDictInt("ACS_DEGREE",        (ACS_DEGREE));
    1958         SetDictInt("ACS_PLMINUS",       (ACS_PLMINUS));
    1959         SetDictInt("ACS_BULLET",        (ACS_BULLET));
    1960         SetDictInt("ACS_LARROW",        (ACS_LARROW));
    1961         SetDictInt("ACS_RARROW",        (ACS_RARROW));
    1962         SetDictInt("ACS_DARROW",        (ACS_DARROW));
    1963         SetDictInt("ACS_UARROW",        (ACS_UARROW));
    1964         SetDictInt("ACS_BOARD",         (ACS_BOARD));
    1965         SetDictInt("ACS_LANTERN",       (ACS_LANTERN));
    1966         SetDictInt("ACS_BLOCK",         (ACS_BLOCK));
    1967 #endif
    1968         SetDictInt("ACS_BSSB",          (ACS_ULCORNER));
    1969         SetDictInt("ACS_SSBB",          (ACS_LLCORNER));
    1970         SetDictInt("ACS_BBSS",          (ACS_URCORNER));
    1971         SetDictInt("ACS_SBBS",          (ACS_LRCORNER));
    1972         SetDictInt("ACS_SBSS",          (ACS_RTEE));
    1973         SetDictInt("ACS_SSSB",          (ACS_LTEE));
    1974         SetDictInt("ACS_SSBS",          (ACS_BTEE));
    1975         SetDictInt("ACS_BSSS",          (ACS_TTEE));
    1976         SetDictInt("ACS_BSBS",          (ACS_HLINE));
    1977         SetDictInt("ACS_SBSB",          (ACS_VLINE));
    1978         SetDictInt("ACS_SSSS",          (ACS_PLUS));
    1979 
    1980         /* The following are never available with strict SYSV curses */
     1959    /* On HP/UX 11, these are of type cchar_t, which is not an
     1960       integral type. If this is a problem on more platforms, a
     1961       configure test should be added to determine whether ACS_S1
     1962       is of integral type. */
     1963    SetDictInt("ACS_S1",            (ACS_S1));
     1964    SetDictInt("ACS_S9",            (ACS_S9));
     1965    SetDictInt("ACS_DIAMOND",       (ACS_DIAMOND));
     1966    SetDictInt("ACS_CKBOARD",       (ACS_CKBOARD));
     1967    SetDictInt("ACS_DEGREE",        (ACS_DEGREE));
     1968    SetDictInt("ACS_PLMINUS",       (ACS_PLMINUS));
     1969    SetDictInt("ACS_BULLET",        (ACS_BULLET));
     1970    SetDictInt("ACS_LARROW",        (ACS_LARROW));
     1971    SetDictInt("ACS_RARROW",        (ACS_RARROW));
     1972    SetDictInt("ACS_DARROW",        (ACS_DARROW));
     1973    SetDictInt("ACS_UARROW",        (ACS_UARROW));
     1974    SetDictInt("ACS_BOARD",         (ACS_BOARD));
     1975    SetDictInt("ACS_LANTERN",       (ACS_LANTERN));
     1976    SetDictInt("ACS_BLOCK",         (ACS_BLOCK));
     1977#endif
     1978    SetDictInt("ACS_BSSB",          (ACS_ULCORNER));
     1979    SetDictInt("ACS_SSBB",          (ACS_LLCORNER));
     1980    SetDictInt("ACS_BBSS",          (ACS_URCORNER));
     1981    SetDictInt("ACS_SBBS",          (ACS_LRCORNER));
     1982    SetDictInt("ACS_SBSS",          (ACS_RTEE));
     1983    SetDictInt("ACS_SSSB",          (ACS_LTEE));
     1984    SetDictInt("ACS_SSBS",          (ACS_BTEE));
     1985    SetDictInt("ACS_BSSS",          (ACS_TTEE));
     1986    SetDictInt("ACS_BSBS",          (ACS_HLINE));
     1987    SetDictInt("ACS_SBSB",          (ACS_VLINE));
     1988    SetDictInt("ACS_SSSS",          (ACS_PLUS));
     1989
     1990    /* The following are never available with strict SYSV curses */
    19811991#ifdef ACS_S3
    1982         SetDictInt("ACS_S3",            (ACS_S3));
     1992    SetDictInt("ACS_S3",            (ACS_S3));
    19831993#endif
    19841994#ifdef ACS_S7
    1985         SetDictInt("ACS_S7",            (ACS_S7));
     1995    SetDictInt("ACS_S7",            (ACS_S7));
    19861996#endif
    19871997#ifdef ACS_LEQUAL
    1988         SetDictInt("ACS_LEQUAL",        (ACS_LEQUAL));
     1998    SetDictInt("ACS_LEQUAL",        (ACS_LEQUAL));
    19891999#endif
    19902000#ifdef ACS_GEQUAL
    1991         SetDictInt("ACS_GEQUAL",        (ACS_GEQUAL));
     2001    SetDictInt("ACS_GEQUAL",        (ACS_GEQUAL));
    19922002#endif
    19932003#ifdef ACS_PI
    1994         SetDictInt("ACS_PI",            (ACS_PI));
     2004    SetDictInt("ACS_PI",            (ACS_PI));
    19952005#endif
    19962006#ifdef ACS_NEQUAL
    1997         SetDictInt("ACS_NEQUAL",        (ACS_NEQUAL));
     2007    SetDictInt("ACS_NEQUAL",        (ACS_NEQUAL));
    19982008#endif
    19992009#ifdef ACS_STERLING
    2000         SetDictInt("ACS_STERLING",      (ACS_STERLING));
    2001 #endif
    2002 
    2003   SetDictInt("LINES", LINES);
    2004   SetDictInt("COLS", COLS);
    2005 
    2006   return (PyObject *)PyCursesWindow_New(win);
     2010    SetDictInt("ACS_STERLING",      (ACS_STERLING));
     2011#endif
     2012
     2013    SetDictInt("LINES", LINES);
     2014    SetDictInt("COLS", COLS);
     2015
     2016    return (PyObject *)PyCursesWindow_New(win);
    20072017}
    20082018
     
    20102020PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
    20112021{
    2012         int fd = -1;
    2013         int err;
    2014         char* termstr = NULL;
    2015 
    2016         static char *kwlist[] = {"term", "fd", NULL};
    2017 
    2018         if (!PyArg_ParseTupleAndKeywords(
    2019                 args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
    2020                 return NULL;
    2021         }
    2022        
    2023         if (fd == -1) {
    2024                 PyObject* sys_stdout;
    2025 
    2026                 sys_stdout = PySys_GetObject("stdout");
    2027 
    2028                 if (sys_stdout == NULL) {
    2029                         PyErr_SetString(
    2030                                 PyCursesError,
    2031                                 "lost sys.stdout");
    2032                         return NULL;
    2033                 }
    2034 
    2035                 fd = PyObject_AsFileDescriptor(sys_stdout);
    2036 
    2037                 if (fd == -1) {
    2038                         return NULL;
    2039                 }
    2040         }
    2041 
    2042         if (setupterm(termstr,fd,&err) == ERR) {
    2043                 char* s = "setupterm: unknown error";
    2044                
    2045                 if (err == 0) {
    2046                         s = "setupterm: could not find terminal";
    2047                 } else if (err == -1) {
    2048                         s = "setupterm: could not find terminfo database";
    2049                 }
    2050 
    2051                 PyErr_SetString(PyCursesError,s);
    2052                 return NULL;
    2053         }
    2054 
    2055         initialised_setupterm = TRUE;
    2056 
    2057         Py_INCREF(Py_None);
    2058         return Py_None;
    2059 }
    2060 
    2061 static PyObject *
    2062 PyCurses_IntrFlush(PyObject *self, PyObject *args)
    2063 {
    2064   int ch;
    2065 
    2066   PyCursesInitialised
    2067 
    2068   switch(PyTuple_Size(args)) {
    2069   case 1:
    2070     if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
    2071     break;
    2072   default:
    2073     PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
    2074     return NULL;
    2075   }
    2076 
    2077   return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
    2078 }
    2079 
    2080 #ifdef HAVE_CURSES_IS_TERM_RESIZED
    2081 static PyObject *
    2082 PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
    2083 {
    2084   int lines;
    2085   int columns;
    2086   int result;
    2087 
    2088   PyCursesInitialised
    2089 
    2090   if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
    2091     return NULL;
    2092   result = is_term_resized(lines, columns);
    2093   if (result == TRUE) {
    2094     Py_INCREF(Py_True);
    2095     return Py_True;
    2096   } else {
    2097     Py_INCREF(Py_False);
    2098     return Py_False;
    2099   }
    2100 }
    2101 #endif /* HAVE_CURSES_IS_TERM_RESIZED */
    2102 
    2103 #if !defined(__NetBSD__)
    2104 static PyObject *
    2105 PyCurses_KeyName(PyObject *self, PyObject *args)
    2106 {
    2107   const char *knp;
    2108   int ch;
    2109 
    2110   PyCursesInitialised
    2111 
    2112   if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
    2113 
    2114   if (ch < 0) {
    2115     PyErr_SetString(PyExc_ValueError, "invalid key number");
    2116     return NULL;
    2117   }
    2118   knp = keyname(ch);
    2119 
    2120   return PyString_FromString((knp == NULL) ? "" : (char *)knp);
    2121 }
    2122 #endif
    2123 
    2124 static PyObject * 
    2125 PyCurses_KillChar(PyObject *self) 
    2126 
    2127   char ch; 
    2128 
    2129   ch = killchar(); 
    2130 
    2131   return PyString_FromStringAndSize(&ch, 1); 
    2132 
    2133 
    2134 static PyObject *
    2135 PyCurses_Meta(PyObject *self, PyObject *args)
    2136 {
    2137   int ch;
    2138 
    2139   PyCursesInitialised
    2140 
    2141   switch(PyTuple_Size(args)) {
    2142   case 1:
    2143     if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
    2144     break;
    2145   default:
    2146     PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
    2147     return NULL;
    2148   }
    2149 
    2150   return PyCursesCheckERR(meta(stdscr, ch), "meta");
    2151 }
    2152 
    2153 #ifdef NCURSES_MOUSE_VERSION
    2154 static PyObject *
    2155 PyCurses_MouseInterval(PyObject *self, PyObject *args)
    2156 {
    2157         int interval;
    2158         PyCursesInitialised
    2159 
    2160         if (!PyArg_ParseTuple(args,"i;interval",&interval))
    2161                 return NULL;
    2162         return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
    2163 }
    2164 
    2165 static PyObject *
    2166 PyCurses_MouseMask(PyObject *self, PyObject *args)
    2167 {
    2168         int newmask;
    2169         mmask_t oldmask, availmask;
    2170 
    2171         PyCursesInitialised
    2172         if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
    2173                 return NULL;
    2174         availmask = mousemask(newmask, &oldmask);
    2175         return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
    2176 }
    2177 #endif
    2178 
    2179 static PyObject *
    2180 PyCurses_Napms(PyObject *self, PyObject *args)
    2181 {
    2182     int ms;
    2183 
    2184     PyCursesInitialised
    2185     if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
    2186 
    2187     return Py_BuildValue("i", napms(ms));
    2188 }
    2189 
    2190 
    2191 static PyObject *
    2192 PyCurses_NewPad(PyObject *self, PyObject *args)
    2193 {
    2194   WINDOW *win;
    2195   int nlines, ncols;
    2196 
    2197   PyCursesInitialised
    2198 
    2199   if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
    2200 
    2201   win = newpad(nlines, ncols);
    2202  
    2203   if (win == NULL) {
    2204     PyErr_SetString(PyCursesError, catchall_NULL);
    2205     return NULL;
    2206   }
    2207 
    2208   return (PyObject *)PyCursesWindow_New(win);
    2209 }
    2210 
    2211 static PyObject *
    2212 PyCurses_NewWindow(PyObject *self, PyObject *args)
    2213 {
    2214   WINDOW *win;
    2215   int nlines, ncols, begin_y=0, begin_x=0;
    2216 
    2217   PyCursesInitialised
    2218 
    2219   switch (PyTuple_Size(args)) {
    2220   case 2:
    2221     if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
    2222       return NULL;
    2223     break;
    2224   case 4:
    2225     if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
    2226                    &nlines,&ncols,&begin_y,&begin_x))
    2227       return NULL;
    2228     break;
    2229   default:
    2230     PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
    2231     return NULL;
    2232   }
    2233 
    2234   win = newwin(nlines,ncols,begin_y,begin_x);
    2235   if (win == NULL) {
    2236     PyErr_SetString(PyCursesError, catchall_NULL);
    2237     return NULL;
    2238   }
    2239 
    2240   return (PyObject *)PyCursesWindow_New(win);
    2241 }
    2242 
    2243 static PyObject *
    2244 PyCurses_Pair_Content(PyObject *self, PyObject *args)
    2245 {
    2246   short pair,f,b;
    2247 
    2248   PyCursesInitialised
    2249   PyCursesInitialisedColor
    2250 
    2251   switch(PyTuple_Size(args)) {
    2252   case 1:
    2253     if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
    2254     break;
    2255   default:
    2256     PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
    2257     return NULL;
    2258   }
    2259 
    2260   if (pair_content(pair, &f, &b)==ERR) {
    2261     PyErr_SetString(PyCursesError,
    2262                     "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
    2263     return NULL;
    2264   }
    2265 
    2266   return Py_BuildValue("(ii)", f, b);
    2267 }
    2268 
    2269 static PyObject *
    2270 PyCurses_pair_number(PyObject *self, PyObject *args)
    2271 {
    2272   int n;
    2273 
    2274   PyCursesInitialised
    2275   PyCursesInitialisedColor
    2276 
    2277   switch(PyTuple_Size(args)) {
    2278   case 1:
    2279     if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
    2280     break;
    2281   default:
    2282     PyErr_SetString(PyExc_TypeError,
    2283                     "pair_number requires 1 argument");
    2284     return NULL;
    2285   }
    2286 
    2287   return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
    2288 }
    2289 
    2290 static PyObject *
    2291 PyCurses_Putp(PyObject *self, PyObject *args)
    2292 {
    2293   char *str;
    2294 
    2295   if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
    2296   return PyCursesCheckERR(putp(str), "putp");
    2297 }
    2298 
    2299 static PyObject *
    2300 PyCurses_QiFlush(PyObject *self, PyObject *args)
    2301 {
    2302   int flag = 0;
    2303 
    2304   PyCursesInitialised
    2305 
    2306   switch(PyTuple_Size(args)) {
    2307   case 0:
    2308     qiflush();
     2022    int fd = -1;
     2023    int err;
     2024    char* termstr = NULL;
     2025
     2026    static char *kwlist[] = {"term", "fd", NULL};
     2027
     2028    if (!PyArg_ParseTupleAndKeywords(
     2029            args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
     2030        return NULL;
     2031    }
     2032
     2033    if (fd == -1) {
     2034        PyObject* sys_stdout;
     2035
     2036        sys_stdout = PySys_GetObject("stdout");
     2037
     2038        if (sys_stdout == NULL) {
     2039            PyErr_SetString(
     2040                PyCursesError,
     2041                "lost sys.stdout");
     2042            return NULL;
     2043        }
     2044
     2045        fd = PyObject_AsFileDescriptor(sys_stdout);
     2046
     2047        if (fd == -1) {
     2048            return NULL;
     2049        }
     2050    }
     2051
     2052    if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) {
     2053        char* s = "setupterm: unknown error";
     2054
     2055        if (err == 0) {
     2056            s = "setupterm: could not find terminal";
     2057        } else if (err == -1) {
     2058            s = "setupterm: could not find terminfo database";
     2059        }
     2060
     2061        PyErr_SetString(PyCursesError,s);
     2062        return NULL;
     2063    }
     2064
     2065    initialised_setupterm = TRUE;
     2066
    23092067    Py_INCREF(Py_None);
    23102068    return Py_None;
    2311   case 1:
    2312     if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
    2313     if (flag) qiflush();
    2314     else noqiflush();
    2315     Py_INCREF(Py_None);
    2316     return Py_None;
    2317   default:
    2318     PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
    2319     return NULL;
    2320   }
     2069}
     2070
     2071static PyObject *
     2072PyCurses_IntrFlush(PyObject *self, PyObject *args)
     2073{
     2074    int ch;
     2075
     2076    PyCursesInitialised;
     2077
     2078    switch(PyTuple_Size(args)) {
     2079    case 1:
     2080        if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
     2081        break;
     2082    default:
     2083        PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
     2084        return NULL;
     2085    }
     2086
     2087    return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
     2088}
     2089
     2090#ifdef HAVE_CURSES_IS_TERM_RESIZED
     2091static PyObject *
     2092PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
     2093{
     2094    int lines;
     2095    int columns;
     2096    int result;
     2097
     2098    PyCursesInitialised;
     2099
     2100    if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
     2101        return NULL;
     2102    result = is_term_resized(lines, columns);
     2103    if (result == TRUE) {
     2104        Py_INCREF(Py_True);
     2105        return Py_True;
     2106    } else {
     2107        Py_INCREF(Py_False);
     2108        return Py_False;
     2109    }
     2110}
     2111#endif /* HAVE_CURSES_IS_TERM_RESIZED */
     2112
     2113#if !defined(__NetBSD__)
     2114static PyObject *
     2115PyCurses_KeyName(PyObject *self, PyObject *args)
     2116{
     2117    const char *knp;
     2118    int ch;
     2119
     2120    PyCursesInitialised;
     2121
     2122    if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
     2123
     2124    if (ch < 0) {
     2125        PyErr_SetString(PyExc_ValueError, "invalid key number");
     2126        return NULL;
     2127    }
     2128    knp = keyname(ch);
     2129
     2130    return PyString_FromString((knp == NULL) ? "" : (char *)knp);
     2131}
     2132#endif
     2133
     2134static PyObject *
     2135PyCurses_KillChar(PyObject *self)
     2136{
     2137    char ch;
     2138
     2139    ch = killchar();
     2140
     2141    return PyString_FromStringAndSize(&ch, 1);
     2142}
     2143
     2144static PyObject *
     2145PyCurses_Meta(PyObject *self, PyObject *args)
     2146{
     2147    int ch;
     2148
     2149    PyCursesInitialised;
     2150
     2151    switch(PyTuple_Size(args)) {
     2152    case 1:
     2153        if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
     2154        break;
     2155    default:
     2156        PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
     2157        return NULL;
     2158    }
     2159
     2160    return PyCursesCheckERR(meta(stdscr, ch), "meta");
     2161}
     2162
     2163#ifdef NCURSES_MOUSE_VERSION
     2164static PyObject *
     2165PyCurses_MouseInterval(PyObject *self, PyObject *args)
     2166{
     2167    int interval;
     2168    PyCursesInitialised;
     2169
     2170    if (!PyArg_ParseTuple(args,"i;interval",&interval))
     2171        return NULL;
     2172    return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
     2173}
     2174
     2175static PyObject *
     2176PyCurses_MouseMask(PyObject *self, PyObject *args)
     2177{
     2178    int newmask;
     2179    mmask_t oldmask, availmask;
     2180
     2181    PyCursesInitialised;
     2182    if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
     2183        return NULL;
     2184    availmask = mousemask(newmask, &oldmask);
     2185    return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
     2186}
     2187#endif
     2188
     2189static PyObject *
     2190PyCurses_Napms(PyObject *self, PyObject *args)
     2191{
     2192    int ms;
     2193
     2194    PyCursesInitialised;
     2195    if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
     2196
     2197    return Py_BuildValue("i", napms(ms));
     2198}
     2199
     2200
     2201static PyObject *
     2202PyCurses_NewPad(PyObject *self, PyObject *args)
     2203{
     2204    WINDOW *win;
     2205    int nlines, ncols;
     2206
     2207    PyCursesInitialised;
     2208
     2209    if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
     2210
     2211    win = newpad(nlines, ncols);
     2212
     2213    if (win == NULL) {
     2214        PyErr_SetString(PyCursesError, catchall_NULL);
     2215        return NULL;
     2216    }
     2217
     2218    return (PyObject *)PyCursesWindow_New(win);
     2219}
     2220
     2221static PyObject *
     2222PyCurses_NewWindow(PyObject *self, PyObject *args)
     2223{
     2224    WINDOW *win;
     2225    int nlines, ncols, begin_y=0, begin_x=0;
     2226
     2227    PyCursesInitialised;
     2228
     2229    switch (PyTuple_Size(args)) {
     2230    case 2:
     2231        if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
     2232            return NULL;
     2233        break;
     2234    case 4:
     2235        if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
     2236                              &nlines,&ncols,&begin_y,&begin_x))
     2237            return NULL;
     2238        break;
     2239    default:
     2240        PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
     2241        return NULL;
     2242    }
     2243
     2244    win = newwin(nlines,ncols,begin_y,begin_x);
     2245    if (win == NULL) {
     2246        PyErr_SetString(PyCursesError, catchall_NULL);
     2247        return NULL;
     2248    }
     2249
     2250    return (PyObject *)PyCursesWindow_New(win);
     2251}
     2252
     2253static PyObject *
     2254PyCurses_Pair_Content(PyObject *self, PyObject *args)
     2255{
     2256    short pair,f,b;
     2257
     2258    PyCursesInitialised;
     2259    PyCursesInitialisedColor;
     2260
     2261    switch(PyTuple_Size(args)) {
     2262    case 1:
     2263        if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
     2264        break;
     2265    default:
     2266        PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
     2267        return NULL;
     2268    }
     2269
     2270    if (pair_content(pair, &f, &b)==ERR) {
     2271        PyErr_SetString(PyCursesError,
     2272                        "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
     2273        return NULL;
     2274    }
     2275
     2276    return Py_BuildValue("(ii)", f, b);
     2277}
     2278
     2279static PyObject *
     2280PyCurses_pair_number(PyObject *self, PyObject *args)
     2281{
     2282    int n;
     2283
     2284    PyCursesInitialised;
     2285    PyCursesInitialisedColor;
     2286
     2287    switch(PyTuple_Size(args)) {
     2288    case 1:
     2289        if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
     2290        break;
     2291    default:
     2292        PyErr_SetString(PyExc_TypeError,
     2293                        "pair_number requires 1 argument");
     2294        return NULL;
     2295    }
     2296
     2297    return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
     2298}
     2299
     2300static PyObject *
     2301PyCurses_Putp(PyObject *self, PyObject *args)
     2302{
     2303    char *str;
     2304
     2305    if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
     2306    return PyCursesCheckERR(putp(str), "putp");
     2307}
     2308
     2309static PyObject *
     2310PyCurses_QiFlush(PyObject *self, PyObject *args)
     2311{
     2312    int flag = 0;
     2313
     2314    PyCursesInitialised;
     2315
     2316    switch(PyTuple_Size(args)) {
     2317    case 0:
     2318        qiflush();
     2319        Py_INCREF(Py_None);
     2320        return Py_None;
     2321    case 1:
     2322        if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
     2323        if (flag) qiflush();
     2324        else noqiflush();
     2325        Py_INCREF(Py_None);
     2326        return Py_None;
     2327    default:
     2328        PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
     2329        return NULL;
     2330    }
    23212331}
    23222332
     
    23272337update_lines_cols(void)
    23282338{
    2329   PyObject *o;
    2330   PyObject *m = PyImport_ImportModuleNoBlock("curses");
    2331 
    2332   if (!m)
    2333     return 0;
    2334 
    2335   o = PyInt_FromLong(LINES);
    2336   if (!o) {
     2339    PyObject *o;
     2340    PyObject *m = PyImport_ImportModuleNoBlock("curses");
     2341
     2342    if (!m)
     2343        return 0;
     2344
     2345    o = PyInt_FromLong(LINES);
     2346    if (!o) {
     2347        Py_DECREF(m);
     2348        return 0;
     2349    }
     2350    if (PyObject_SetAttrString(m, "LINES", o)) {
     2351        Py_DECREF(m);
     2352        Py_DECREF(o);
     2353        return 0;
     2354    }
     2355    if (PyDict_SetItemString(ModDict, "LINES", o)) {
     2356        Py_DECREF(m);
     2357        Py_DECREF(o);
     2358        return 0;
     2359    }
     2360    Py_DECREF(o);
     2361    o = PyInt_FromLong(COLS);
     2362    if (!o) {
     2363        Py_DECREF(m);
     2364        return 0;
     2365    }
     2366    if (PyObject_SetAttrString(m, "COLS", o)) {
     2367        Py_DECREF(m);
     2368        Py_DECREF(o);
     2369        return 0;
     2370    }
     2371    if (PyDict_SetItemString(ModDict, "COLS", o)) {
     2372        Py_DECREF(m);
     2373        Py_DECREF(o);
     2374        return 0;
     2375    }
     2376    Py_DECREF(o);
    23372377    Py_DECREF(m);
    2338     return 0;
    2339   }
    2340   if (PyObject_SetAttrString(m, "LINES", o)) {
    2341     Py_DECREF(m);
    2342     Py_DECREF(o);
    2343     return 0;
    2344   }
    2345   if (PyDict_SetItemString(ModDict, "LINES", o)) {
    2346     Py_DECREF(m);
    2347     Py_DECREF(o);
    2348     return 0;
    2349   }
    2350   Py_DECREF(o);
    2351   o = PyInt_FromLong(COLS);
    2352   if (!o) {
    2353     Py_DECREF(m);
    2354     return 0;
    2355   }
    2356   if (PyObject_SetAttrString(m, "COLS", o)) {
    2357     Py_DECREF(m);
    2358     Py_DECREF(o);
    2359     return 0;
    2360   }
    2361   if (PyDict_SetItemString(ModDict, "COLS", o)) {
    2362     Py_DECREF(m);
    2363     Py_DECREF(o);
    2364     return 0;
    2365   }
    2366   Py_DECREF(o);
    2367   Py_DECREF(m);
    2368   return 1;
     2378    return 1;
    23692379}
    23702380#endif
     
    23742384PyCurses_ResizeTerm(PyObject *self, PyObject *args)
    23752385{
    2376   int lines;
    2377   int columns;
    2378   PyObject *result;
    2379 
    2380   PyCursesInitialised
    2381 
    2382   if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
    2383     return NULL;
    2384 
    2385   result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
    2386   if (!result)
    2387     return NULL;
    2388   if (!update_lines_cols())
    2389     return NULL;
    2390   return result;
     2386    int lines;
     2387    int columns;
     2388    PyObject *result;
     2389
     2390    PyCursesInitialised;
     2391
     2392    if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
     2393        return NULL;
     2394
     2395    result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
     2396    if (!result)
     2397        return NULL;
     2398    if (!update_lines_cols())
     2399        return NULL;
     2400    return result;
    23912401}
    23922402
     
    23972407PyCurses_Resize_Term(PyObject *self, PyObject *args)
    23982408{
    2399   int lines;
    2400   int columns;
    2401 
    2402   PyObject *result;
    2403 
    2404   PyCursesInitialised
    2405 
    2406   if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
    2407     return NULL;
    2408 
    2409   result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
    2410   if (!result)
    2411     return NULL;
    2412   if (!update_lines_cols())
    2413     return NULL;
    2414   return result;
     2409    int lines;
     2410    int columns;
     2411
     2412    PyObject *result;
     2413
     2414    PyCursesInitialised;
     2415
     2416    if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
     2417        return NULL;
     2418
     2419    result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
     2420    if (!result)
     2421        return NULL;
     2422    if (!update_lines_cols())
     2423        return NULL;
     2424    return result;
    24152425}
    24162426#endif /* HAVE_CURSES_RESIZE_TERM */
     
    24192429PyCurses_setsyx(PyObject *self, PyObject *args)
    24202430{
    2421   int y,x;
    2422 
    2423   PyCursesInitialised
    2424 
    2425   if (PyTuple_Size(args)!=2) {
    2426     PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
    2427     return NULL;
    2428   }
    2429 
    2430   if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
    2431 
    2432   setsyx(y,x);
    2433 
    2434   Py_INCREF(Py_None);
    2435   return Py_None;
    2436 }
    2437 
    2438 static PyObject *
    2439 PyCurses_Start_Color(PyObject *self)
    2440 {
    2441   int code;
    2442   PyObject *c, *cp;
    2443 
    2444   PyCursesInitialised
    2445 
    2446   code = start_color();
    2447   if (code != ERR) {
    2448     initialisedcolors = TRUE;
    2449     c = PyInt_FromLong((long) COLORS);
    2450     PyDict_SetItemString(ModDict, "COLORS", c);
    2451     Py_DECREF(c);
    2452     cp = PyInt_FromLong((long) COLOR_PAIRS);
    2453     PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
    2454     Py_DECREF(cp);
     2431    int y,x;
     2432
     2433    PyCursesInitialised;
     2434
     2435    if (PyTuple_Size(args)!=2) {
     2436        PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
     2437        return NULL;
     2438    }
     2439
     2440    if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
     2441
     2442    setsyx(y,x);
     2443
    24552444    Py_INCREF(Py_None);
    24562445    return Py_None;
    2457   } else {
    2458     PyErr_SetString(PyCursesError, "start_color() returned ERR");
    2459     return NULL;
    2460   }
     2446}
     2447
     2448static PyObject *
     2449PyCurses_Start_Color(PyObject *self)
     2450{
     2451    int code;
     2452    PyObject *c, *cp;
     2453
     2454    PyCursesInitialised;
     2455
     2456    code = start_color();
     2457    if (code != ERR) {
     2458        initialisedcolors = TRUE;
     2459        c = PyInt_FromLong((long) COLORS);
     2460        PyDict_SetItemString(ModDict, "COLORS", c);
     2461        Py_DECREF(c);
     2462        cp = PyInt_FromLong((long) COLOR_PAIRS);
     2463        PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
     2464        Py_DECREF(cp);
     2465        Py_INCREF(Py_None);
     2466        return Py_None;
     2467    } else {
     2468        PyErr_SetString(PyCursesError, "start_color() returned ERR");
     2469        return NULL;
     2470    }
    24612471}
    24622472
     
    24642474PyCurses_tigetflag(PyObject *self, PyObject *args)
    24652475{
    2466         char *capname;
    2467 
    2468         PyCursesSetupTermCalled;
    2469                
    2470         if (!PyArg_ParseTuple(args, "z", &capname))
    2471                 return NULL;
    2472 
    2473         return PyInt_FromLong( (long) tigetflag( capname ) );
     2476    char *capname;
     2477
     2478    PyCursesSetupTermCalled;
     2479
     2480    if (!PyArg_ParseTuple(args, "s", &capname))
     2481        return NULL;
     2482
     2483    return PyInt_FromLong( (long) tigetflag( capname ) );
    24742484}
    24752485
     
    24772487PyCurses_tigetnum(PyObject *self, PyObject *args)
    24782488{
    2479         char *capname;
    2480 
    2481         PyCursesSetupTermCalled;
    2482                
    2483         if (!PyArg_ParseTuple(args, "z", &capname))
    2484                 return NULL;
    2485 
    2486         return PyInt_FromLong( (long) tigetnum( capname ) );
     2489    char *capname;
     2490
     2491    PyCursesSetupTermCalled;
     2492
     2493    if (!PyArg_ParseTuple(args, "s", &capname))
     2494        return NULL;
     2495
     2496    return PyInt_FromLong( (long) tigetnum( capname ) );
    24872497}
    24882498
     
    24902500PyCurses_tigetstr(PyObject *self, PyObject *args)
    24912501{
    2492         char *capname;
    2493 
    2494         PyCursesSetupTermCalled;
    2495                
    2496         if (!PyArg_ParseTuple(args, "z", &capname))
    2497                 return NULL;
    2498 
    2499         capname = tigetstr( capname );
    2500         if (capname == 0 || capname == (char*) -1) {
    2501                 Py_INCREF(Py_None);
    2502                 return Py_None;
    2503         }
    2504         return PyString_FromString( capname );
     2502    char *capname;
     2503
     2504    PyCursesSetupTermCalled;
     2505
     2506    if (!PyArg_ParseTuple(args, "s", &capname))
     2507        return NULL;
     2508
     2509    capname = tigetstr( capname );
     2510    if (capname == 0 || capname == (char*) -1) {
     2511        Py_INCREF(Py_None);
     2512        return Py_None;
     2513    }
     2514    return PyString_FromString( capname );
    25052515}
    25062516
     
    25082518PyCurses_tparm(PyObject *self, PyObject *args)
    25092519{
    2510         char* fmt;
    2511         char* result = NULL;
    2512         int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
    2513 
    2514         PyCursesSetupTermCalled;
    2515 
    2516         if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
    2517                               &fmt, &i1, &i2, &i3, &i4,
    2518                               &i5, &i6, &i7, &i8, &i9)) {
    2519                 return NULL;
    2520         }
    2521 
    2522         result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
    2523         if (!result) {
    2524                 PyErr_SetString(PyCursesError, "tparm() returned NULL");
    2525                 return NULL;
    2526         }
    2527 
    2528         return PyString_FromString(result);
     2520    char* fmt;
     2521    char* result = NULL;
     2522    int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
     2523
     2524    PyCursesSetupTermCalled;
     2525
     2526    if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
     2527                          &fmt, &i1, &i2, &i3, &i4,
     2528                          &i5, &i6, &i7, &i8, &i9)) {
     2529        return NULL;
     2530    }
     2531
     2532    result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
     2533    if (!result) {
     2534        PyErr_SetString(PyCursesError, "tparm() returned NULL");
     2535        return NULL;
     2536    }
     2537
     2538    return PyString_FromString(result);
    25292539}
    25302540
     
    25322542PyCurses_TypeAhead(PyObject *self, PyObject *args)
    25332543{
    2534   int fd;
    2535 
    2536   PyCursesInitialised
    2537 
    2538   if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
    2539 
    2540   return PyCursesCheckERR(typeahead( fd ), "typeahead");
     2544    int fd;
     2545
     2546    PyCursesInitialised;
     2547
     2548    if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
     2549
     2550    return PyCursesCheckERR(typeahead( fd ), "typeahead");
    25412551}
    25422552
     
    25442554PyCurses_UnCtrl(PyObject *self, PyObject *args)
    25452555{
    2546   PyObject *temp;
    2547   chtype ch;
    2548 
    2549   PyCursesInitialised
    2550 
    2551   if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
    2552 
    2553   if (PyInt_Check(temp))
    2554     ch = (chtype) PyInt_AsLong(temp);
    2555   else if (PyString_Check(temp))
    2556     ch = (chtype) *PyString_AsString(temp);
    2557   else {
    2558     PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
    2559     return NULL;
    2560   }
    2561 
    2562   return PyString_FromString(unctrl(ch));
     2556    PyObject *temp;
     2557    chtype ch;
     2558
     2559    PyCursesInitialised;
     2560
     2561    if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
     2562
     2563    if (PyInt_Check(temp))
     2564        ch = (chtype) PyInt_AsLong(temp);
     2565    else if (PyString_Check(temp))
     2566        ch = (chtype) *PyString_AsString(temp);
     2567    else {
     2568        PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
     2569        return NULL;
     2570    }
     2571
     2572    return PyString_FromString(unctrl(ch));
    25632573}
    25642574
     
    25662576PyCurses_UngetCh(PyObject *self, PyObject *args)
    25672577{
    2568   PyObject *temp;
    2569   int ch;
    2570 
    2571   PyCursesInitialised
    2572 
    2573   if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
    2574 
    2575   if (PyInt_Check(temp))
    2576     ch = (int) PyInt_AsLong(temp);
    2577   else if (PyString_Check(temp))
    2578     ch = (int) *PyString_AsString(temp);
    2579   else {
    2580     PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
    2581     return NULL;
    2582   }
    2583 
    2584   return PyCursesCheckERR(ungetch(ch), "ungetch");
     2578    PyObject *temp;
     2579    int ch;
     2580
     2581    PyCursesInitialised;
     2582
     2583    if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
     2584
     2585    if (PyInt_Check(temp))
     2586        ch = (int) PyInt_AsLong(temp);
     2587    else if (PyString_Check(temp))
     2588        ch = (int) *PyString_AsString(temp);
     2589    else {
     2590        PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
     2591        return NULL;
     2592    }
     2593
     2594    return PyCursesCheckERR(ungetch(ch), "ungetch");
    25852595}
    25862596
     
    25882598PyCurses_Use_Env(PyObject *self, PyObject *args)
    25892599{
    2590   int flag;
    2591 
    2592   switch(PyTuple_Size(args)) {
    2593   case 1:
    2594     if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
    2595       return NULL;
    2596     break;
    2597   default:
    2598     PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
    2599     return NULL;
    2600   }
    2601   use_env(flag);
    2602   Py_INCREF(Py_None);
    2603   return Py_None;
    2604 }
    2605 
    2606 #ifndef STRICT_SYSV_CURSES
    2607 static PyObject *
    2608 PyCurses_Use_Default_Colors(PyObject *self)
    2609 {
    2610   int code;
    2611 
    2612   PyCursesInitialised
    2613   PyCursesInitialisedColor
    2614 
    2615   code = use_default_colors();
    2616   if (code != ERR) {
     2600    int flag;
     2601
     2602    switch(PyTuple_Size(args)) {
     2603    case 1:
     2604        if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
     2605            return NULL;
     2606        break;
     2607    default:
     2608        PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
     2609        return NULL;
     2610    }
     2611    use_env(flag);
    26172612    Py_INCREF(Py_None);
    26182613    return Py_None;
    2619   } else {
    2620     PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
    2621     return NULL;
    2622   }
     2614}
     2615
     2616#ifndef STRICT_SYSV_CURSES
     2617static PyObject *
     2618PyCurses_Use_Default_Colors(PyObject *self)
     2619{
     2620    int code;
     2621
     2622    PyCursesInitialised;
     2623    PyCursesInitialisedColor;
     2624
     2625    code = use_default_colors();
     2626    if (code != ERR) {
     2627        Py_INCREF(Py_None);
     2628        return Py_None;
     2629    } else {
     2630        PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
     2631        return NULL;
     2632    }
    26232633}
    26242634#endif /* STRICT_SYSV_CURSES */
     
    26272637
    26282638static PyMethodDef PyCurses_methods[] = {
    2629   {"baudrate",            (PyCFunction)PyCurses_baudrate, METH_NOARGS},
    2630   {"beep",                (PyCFunction)PyCurses_beep, METH_NOARGS},
    2631   {"can_change_color",    (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
    2632   {"cbreak",              (PyCFunction)PyCurses_cbreak, METH_VARARGS},
    2633   {"color_content",       (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
    2634   {"color_pair",          (PyCFunction)PyCurses_color_pair, METH_VARARGS},
    2635   {"curs_set",            (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
    2636   {"def_prog_mode",       (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
    2637   {"def_shell_mode",      (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
    2638   {"delay_output",        (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
    2639   {"doupdate",            (PyCFunction)PyCurses_doupdate, METH_NOARGS},
    2640   {"echo",                (PyCFunction)PyCurses_echo, METH_VARARGS},
    2641   {"endwin",              (PyCFunction)PyCurses_endwin, METH_NOARGS},
    2642   {"erasechar",           (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
    2643   {"filter",              (PyCFunction)PyCurses_filter, METH_NOARGS},
    2644   {"flash",               (PyCFunction)PyCurses_flash, METH_NOARGS},
    2645   {"flushinp",            (PyCFunction)PyCurses_flushinp, METH_NOARGS},
     2639    {"baudrate",            (PyCFunction)PyCurses_baudrate, METH_NOARGS},
     2640    {"beep",                (PyCFunction)PyCurses_beep, METH_NOARGS},
     2641    {"can_change_color",    (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
     2642    {"cbreak",              (PyCFunction)PyCurses_cbreak, METH_VARARGS},
     2643    {"color_content",       (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
     2644    {"color_pair",          (PyCFunction)PyCurses_color_pair, METH_VARARGS},
     2645    {"curs_set",            (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
     2646    {"def_prog_mode",       (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
     2647    {"def_shell_mode",      (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
     2648    {"delay_output",        (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
     2649    {"doupdate",            (PyCFunction)PyCurses_doupdate, METH_NOARGS},
     2650    {"echo",                (PyCFunction)PyCurses_echo, METH_VARARGS},
     2651    {"endwin",              (PyCFunction)PyCurses_endwin, METH_NOARGS},
     2652    {"erasechar",           (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
     2653    {"filter",              (PyCFunction)PyCurses_filter, METH_NOARGS},
     2654    {"flash",               (PyCFunction)PyCurses_flash, METH_NOARGS},
     2655    {"flushinp",            (PyCFunction)PyCurses_flushinp, METH_NOARGS},
    26462656#ifdef NCURSES_MOUSE_VERSION
    2647   {"getmouse",            (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
    2648   {"ungetmouse",          (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
    2649 #endif
    2650   {"getsyx",              (PyCFunction)PyCurses_getsyx, METH_NOARGS},
    2651   {"getwin",              (PyCFunction)PyCurses_GetWin, METH_O},
    2652   {"has_colors",          (PyCFunction)PyCurses_has_colors, METH_NOARGS},
    2653   {"has_ic",              (PyCFunction)PyCurses_has_ic, METH_NOARGS},
    2654   {"has_il",              (PyCFunction)PyCurses_has_il, METH_NOARGS},
     2657    {"getmouse",            (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
     2658    {"ungetmouse",          (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
     2659#endif
     2660    {"getsyx",              (PyCFunction)PyCurses_getsyx, METH_NOARGS},
     2661    {"getwin",              (PyCFunction)PyCurses_GetWin, METH_O},
     2662    {"has_colors",          (PyCFunction)PyCurses_has_colors, METH_NOARGS},
     2663    {"has_ic",              (PyCFunction)PyCurses_has_ic, METH_NOARGS},
     2664    {"has_il",              (PyCFunction)PyCurses_has_il, METH_NOARGS},
    26552665#ifndef STRICT_SYSV_CURSES
    2656   {"has_key",             (PyCFunction)PyCurses_has_key, METH_VARARGS},
    2657 #endif
    2658   {"halfdelay",           (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
    2659   {"init_color",          (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
    2660   {"init_pair",           (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
    2661   {"initscr",             (PyCFunction)PyCurses_InitScr, METH_NOARGS},
    2662   {"intrflush",           (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
    2663   {"isendwin",            (PyCFunction)PyCurses_isendwin, METH_NOARGS},
     2666    {"has_key",             (PyCFunction)PyCurses_has_key, METH_VARARGS},
     2667#endif
     2668    {"halfdelay",           (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
     2669    {"init_color",          (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
     2670    {"init_pair",           (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
     2671    {"initscr",             (PyCFunction)PyCurses_InitScr, METH_NOARGS},
     2672    {"intrflush",           (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
     2673    {"isendwin",            (PyCFunction)PyCurses_isendwin, METH_NOARGS},
    26642674#ifdef HAVE_CURSES_IS_TERM_RESIZED
    2665   {"is_term_resized",     (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
     2675    {"is_term_resized",     (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
    26662676#endif
    26672677#if !defined(__NetBSD__)
    2668   {"keyname",             (PyCFunction)PyCurses_KeyName, METH_VARARGS},
    2669 #endif
    2670   {"killchar",            (PyCFunction)PyCurses_KillChar, METH_NOARGS},
    2671   {"longname",            (PyCFunction)PyCurses_longname, METH_NOARGS},
    2672   {"meta",                (PyCFunction)PyCurses_Meta, METH_VARARGS},
     2678    {"keyname",             (PyCFunction)PyCurses_KeyName, METH_VARARGS},
     2679#endif
     2680    {"killchar",            (PyCFunction)PyCurses_KillChar, METH_NOARGS},
     2681    {"longname",            (PyCFunction)PyCurses_longname, METH_NOARGS},
     2682    {"meta",                (PyCFunction)PyCurses_Meta, METH_VARARGS},
    26732683#ifdef NCURSES_MOUSE_VERSION
    2674   {"mouseinterval",       (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
    2675   {"mousemask",           (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
    2676 #endif
    2677   {"napms",               (PyCFunction)PyCurses_Napms, METH_VARARGS},
    2678   {"newpad",              (PyCFunction)PyCurses_NewPad, METH_VARARGS},
    2679   {"newwin",              (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
    2680   {"nl",                  (PyCFunction)PyCurses_nl, METH_VARARGS},
    2681   {"nocbreak",            (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
    2682   {"noecho",              (PyCFunction)PyCurses_noecho, METH_NOARGS},
    2683   {"nonl",                (PyCFunction)PyCurses_nonl, METH_NOARGS},
    2684   {"noqiflush",           (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
    2685   {"noraw",               (PyCFunction)PyCurses_noraw, METH_NOARGS},
    2686   {"pair_content",        (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
    2687   {"pair_number",         (PyCFunction)PyCurses_pair_number, METH_VARARGS},
    2688   {"putp",                (PyCFunction)PyCurses_Putp, METH_VARARGS},
    2689   {"qiflush",             (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
    2690   {"raw",                 (PyCFunction)PyCurses_raw, METH_VARARGS},
    2691   {"reset_prog_mode",     (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
    2692   {"reset_shell_mode",    (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
    2693   {"resetty",             (PyCFunction)PyCurses_resetty, METH_NOARGS},
     2684    {"mouseinterval",       (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
     2685    {"mousemask",           (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
     2686#endif
     2687    {"napms",               (PyCFunction)PyCurses_Napms, METH_VARARGS},
     2688    {"newpad",              (PyCFunction)PyCurses_NewPad, METH_VARARGS},
     2689    {"newwin",              (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
     2690    {"nl",                  (PyCFunction)PyCurses_nl, METH_VARARGS},
     2691    {"nocbreak",            (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
     2692    {"noecho",              (PyCFunction)PyCurses_noecho, METH_NOARGS},
     2693    {"nonl",                (PyCFunction)PyCurses_nonl, METH_NOARGS},
     2694    {"noqiflush",           (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
     2695    {"noraw",               (PyCFunction)PyCurses_noraw, METH_NOARGS},
     2696    {"pair_content",        (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
     2697    {"pair_number",         (PyCFunction)PyCurses_pair_number, METH_VARARGS},
     2698    {"putp",                (PyCFunction)PyCurses_Putp, METH_VARARGS},
     2699    {"qiflush",             (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
     2700    {"raw",                 (PyCFunction)PyCurses_raw, METH_VARARGS},
     2701    {"reset_prog_mode",     (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
     2702    {"reset_shell_mode",    (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
     2703    {"resetty",             (PyCFunction)PyCurses_resetty, METH_NOARGS},
    26942704#ifdef HAVE_CURSES_RESIZETERM
    2695   {"resizeterm",          (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
     2705    {"resizeterm",          (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
    26962706#endif
    26972707#ifdef HAVE_CURSES_RESIZE_TERM
    2698   {"resize_term",         (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
    2699 #endif
    2700   {"savetty",             (PyCFunction)PyCurses_savetty, METH_NOARGS},
    2701   {"setsyx",              (PyCFunction)PyCurses_setsyx, METH_VARARGS},
    2702   {"setupterm",           (PyCFunction)PyCurses_setupterm,
    2703    METH_VARARGS|METH_KEYWORDS},
    2704   {"start_color",         (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
    2705   {"termattrs",           (PyCFunction)PyCurses_termattrs, METH_NOARGS},
    2706   {"termname",            (PyCFunction)PyCurses_termname, METH_NOARGS},
    2707   {"tigetflag",           (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
    2708   {"tigetnum",            (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
    2709   {"tigetstr",            (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
    2710   {"tparm",               (PyCFunction)PyCurses_tparm, METH_VARARGS},
    2711   {"typeahead",           (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
    2712   {"unctrl",              (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
    2713   {"ungetch",             (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
    2714   {"use_env",             (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
     2708    {"resize_term",         (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
     2709#endif
     2710    {"savetty",             (PyCFunction)PyCurses_savetty, METH_NOARGS},
     2711    {"setsyx",              (PyCFunction)PyCurses_setsyx, METH_VARARGS},
     2712    {"setupterm",           (PyCFunction)PyCurses_setupterm,
     2713     METH_VARARGS|METH_KEYWORDS},
     2714    {"start_color",         (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
     2715    {"termattrs",           (PyCFunction)PyCurses_termattrs, METH_NOARGS},
     2716    {"termname",            (PyCFunction)PyCurses_termname, METH_NOARGS},
     2717    {"tigetflag",           (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
     2718    {"tigetnum",            (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
     2719    {"tigetstr",            (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
     2720    {"tparm",               (PyCFunction)PyCurses_tparm, METH_VARARGS},
     2721    {"typeahead",           (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
     2722    {"unctrl",              (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
     2723    {"ungetch",             (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
     2724    {"use_env",             (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
    27152725#ifndef STRICT_SYSV_CURSES
    2716   {"use_default_colors",  (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
    2717 #endif
    2718   {NULL,                  NULL}         /* sentinel */
     2726    {"use_default_colors",  (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
     2727#endif
     2728    {NULL,                  NULL}         /* sentinel */
    27192729};
    27202730
     
    27242734init_curses(void)
    27252735{
    2726         PyObject *m, *d, *v, *c_api_object;
    2727         static void *PyCurses_API[PyCurses_API_pointers];
    2728 
    2729         /* Initialize object type */
    2730         Py_TYPE(&PyCursesWindow_Type) = &PyType_Type;
    2731 
    2732         /* Initialize the C API pointer array */
    2733         PyCurses_API[0] = (void *)&PyCursesWindow_Type;
    2734         PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
    2735         PyCurses_API[2] = (void *)func_PyCursesInitialised;
    2736         PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
    2737 
    2738         /* Create the module and add the functions */
    2739         m = Py_InitModule("_curses", PyCurses_methods);
    2740         if (m == NULL)
    2741                 return;
    2742 
    2743         /* Add some symbolic constants to the module */
    2744         d = PyModule_GetDict(m);
    2745         if (d == NULL)
    2746                 return;
    2747         ModDict = d; /* For PyCurses_InitScr to use later */
    2748 
    2749         /* Add a CObject for the C API */
    2750         c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
    2751         PyDict_SetItemString(d, "_C_API", c_api_object);
    2752         Py_DECREF(c_api_object);
    2753 
    2754         /* For exception curses.error */
    2755         PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
    2756         PyDict_SetItemString(d, "error", PyCursesError);
    2757 
    2758         /* Make the version available */
    2759         v = PyString_FromString(PyCursesVersion);
    2760         PyDict_SetItemString(d, "version", v);
    2761         PyDict_SetItemString(d, "__version__", v);
    2762         Py_DECREF(v);
    2763 
    2764         SetDictInt("ERR", ERR);
    2765         SetDictInt("OK", OK);
    2766 
    2767         /* Here are some attributes you can add to chars to print */
    2768        
    2769         SetDictInt("A_ATTRIBUTES",      A_ATTRIBUTES);
    2770         SetDictInt("A_NORMAL",          A_NORMAL);
    2771         SetDictInt("A_STANDOUT",        A_STANDOUT);
    2772         SetDictInt("A_UNDERLINE",       A_UNDERLINE);
    2773         SetDictInt("A_REVERSE",         A_REVERSE);
    2774         SetDictInt("A_BLINK",           A_BLINK);
    2775         SetDictInt("A_DIM",             A_DIM);
    2776         SetDictInt("A_BOLD",            A_BOLD);
    2777         SetDictInt("A_ALTCHARSET",      A_ALTCHARSET);
     2736    PyObject *m, *d, *v, *c_api_object;
     2737    static void *PyCurses_API[PyCurses_API_pointers];
     2738
     2739    /* Initialize object type */
     2740    Py_TYPE(&PyCursesWindow_Type) = &PyType_Type;
     2741
     2742    /* Initialize the C API pointer array */
     2743    PyCurses_API[0] = (void *)&PyCursesWindow_Type;
     2744    PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
     2745    PyCurses_API[2] = (void *)func_PyCursesInitialised;
     2746    PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
     2747
     2748    /* Create the module and add the functions */
     2749    m = Py_InitModule("_curses", PyCurses_methods);
     2750    if (m == NULL)
     2751        return;
     2752
     2753    /* Add some symbolic constants to the module */
     2754    d = PyModule_GetDict(m);
     2755    if (d == NULL)
     2756        return;
     2757    ModDict = d; /* For PyCurses_InitScr to use later */
     2758
     2759    /* Add a capsule for the C API */
     2760    c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
     2761    PyDict_SetItemString(d, "_C_API", c_api_object);
     2762    Py_DECREF(c_api_object);
     2763
     2764    /* For exception curses.error */
     2765    PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
     2766    PyDict_SetItemString(d, "error", PyCursesError);
     2767
     2768    /* Make the version available */
     2769    v = PyString_FromString(PyCursesVersion);
     2770    PyDict_SetItemString(d, "version", v);
     2771    PyDict_SetItemString(d, "__version__", v);
     2772    Py_DECREF(v);
     2773
     2774    SetDictInt("ERR", ERR);
     2775    SetDictInt("OK", OK);
     2776
     2777    /* Here are some attributes you can add to chars to print */
     2778
     2779    SetDictInt("A_ATTRIBUTES",      A_ATTRIBUTES);
     2780    SetDictInt("A_NORMAL",              A_NORMAL);
     2781    SetDictInt("A_STANDOUT",            A_STANDOUT);
     2782    SetDictInt("A_UNDERLINE",           A_UNDERLINE);
     2783    SetDictInt("A_REVERSE",             A_REVERSE);
     2784    SetDictInt("A_BLINK",               A_BLINK);
     2785    SetDictInt("A_DIM",                 A_DIM);
     2786    SetDictInt("A_BOLD",                A_BOLD);
     2787    SetDictInt("A_ALTCHARSET",          A_ALTCHARSET);
    27782788#if !defined(__NetBSD__)
    2779         SetDictInt("A_INVIS",           A_INVIS);
    2780 #endif
    2781         SetDictInt("A_PROTECT",         A_PROTECT);
    2782         SetDictInt("A_CHARTEXT",        A_CHARTEXT);
    2783         SetDictInt("A_COLOR",           A_COLOR);
    2784 
    2785         /* The following are never available with strict SYSV curses */
     2789    SetDictInt("A_INVIS",           A_INVIS);
     2790#endif
     2791    SetDictInt("A_PROTECT",         A_PROTECT);
     2792    SetDictInt("A_CHARTEXT",        A_CHARTEXT);
     2793    SetDictInt("A_COLOR",           A_COLOR);
     2794
     2795    /* The following are never available with strict SYSV curses */
    27862796#ifdef A_HORIZONTAL
    2787         SetDictInt("A_HORIZONTAL",      A_HORIZONTAL);
     2797    SetDictInt("A_HORIZONTAL",      A_HORIZONTAL);
    27882798#endif
    27892799#ifdef A_LEFT
    2790         SetDictInt("A_LEFT",            A_LEFT);
     2800    SetDictInt("A_LEFT",            A_LEFT);
    27912801#endif
    27922802#ifdef A_LOW
    2793         SetDictInt("A_LOW",             A_LOW);
     2803    SetDictInt("A_LOW",             A_LOW);
    27942804#endif
    27952805#ifdef A_RIGHT
    2796         SetDictInt("A_RIGHT",           A_RIGHT);
     2806    SetDictInt("A_RIGHT",           A_RIGHT);
    27972807#endif
    27982808#ifdef A_TOP
    2799         SetDictInt("A_TOP",             A_TOP);
     2809    SetDictInt("A_TOP",             A_TOP);
    28002810#endif
    28012811#ifdef A_VERTICAL
    2802         SetDictInt("A_VERTICAL",        A_VERTICAL);
    2803 #endif
    2804 
    2805         SetDictInt("COLOR_BLACK",       COLOR_BLACK);
    2806         SetDictInt("COLOR_RED",         COLOR_RED);
    2807         SetDictInt("COLOR_GREEN",       COLOR_GREEN);
    2808         SetDictInt("COLOR_YELLOW",      COLOR_YELLOW);
    2809         SetDictInt("COLOR_BLUE",        COLOR_BLUE);
    2810         SetDictInt("COLOR_MAGENTA",     COLOR_MAGENTA);
    2811         SetDictInt("COLOR_CYAN",        COLOR_CYAN);
    2812         SetDictInt("COLOR_WHITE",       COLOR_WHITE);
     2812    SetDictInt("A_VERTICAL",        A_VERTICAL);
     2813#endif
     2814
     2815    SetDictInt("COLOR_BLACK",       COLOR_BLACK);
     2816    SetDictInt("COLOR_RED",         COLOR_RED);
     2817    SetDictInt("COLOR_GREEN",       COLOR_GREEN);
     2818    SetDictInt("COLOR_YELLOW",      COLOR_YELLOW);
     2819    SetDictInt("COLOR_BLUE",        COLOR_BLUE);
     2820    SetDictInt("COLOR_MAGENTA",     COLOR_MAGENTA);
     2821    SetDictInt("COLOR_CYAN",        COLOR_CYAN);
     2822    SetDictInt("COLOR_WHITE",       COLOR_WHITE);
    28132823
    28142824#ifdef NCURSES_MOUSE_VERSION
    2815         /* Mouse-related constants */
    2816         SetDictInt("BUTTON1_PRESSED",          BUTTON1_PRESSED);
    2817         SetDictInt("BUTTON1_RELEASED",         BUTTON1_RELEASED);
    2818         SetDictInt("BUTTON1_CLICKED",          BUTTON1_CLICKED);
    2819         SetDictInt("BUTTON1_DOUBLE_CLICKED",   BUTTON1_DOUBLE_CLICKED);
    2820         SetDictInt("BUTTON1_TRIPLE_CLICKED",   BUTTON1_TRIPLE_CLICKED);
    2821 
    2822         SetDictInt("BUTTON2_PRESSED",          BUTTON2_PRESSED);
    2823         SetDictInt("BUTTON2_RELEASED",         BUTTON2_RELEASED);
    2824         SetDictInt("BUTTON2_CLICKED",          BUTTON2_CLICKED);
    2825         SetDictInt("BUTTON2_DOUBLE_CLICKED",   BUTTON2_DOUBLE_CLICKED);
    2826         SetDictInt("BUTTON2_TRIPLE_CLICKED",   BUTTON2_TRIPLE_CLICKED);
    2827 
    2828         SetDictInt("BUTTON3_PRESSED",          BUTTON3_PRESSED);
    2829         SetDictInt("BUTTON3_RELEASED",         BUTTON3_RELEASED);
    2830         SetDictInt("BUTTON3_CLICKED",          BUTTON3_CLICKED);
    2831         SetDictInt("BUTTON3_DOUBLE_CLICKED",   BUTTON3_DOUBLE_CLICKED);
    2832         SetDictInt("BUTTON3_TRIPLE_CLICKED",   BUTTON3_TRIPLE_CLICKED);
    2833 
    2834         SetDictInt("BUTTON4_PRESSED",          BUTTON4_PRESSED);
    2835         SetDictInt("BUTTON4_RELEASED",         BUTTON4_RELEASED);
    2836         SetDictInt("BUTTON4_CLICKED",          BUTTON4_CLICKED);
    2837         SetDictInt("BUTTON4_DOUBLE_CLICKED",   BUTTON4_DOUBLE_CLICKED);
    2838         SetDictInt("BUTTON4_TRIPLE_CLICKED",   BUTTON4_TRIPLE_CLICKED);
    2839 
    2840         SetDictInt("BUTTON_SHIFT",             BUTTON_SHIFT);
    2841         SetDictInt("BUTTON_CTRL",              BUTTON_CTRL);
    2842         SetDictInt("BUTTON_ALT",               BUTTON_ALT);
    2843 
    2844         SetDictInt("ALL_MOUSE_EVENTS",         ALL_MOUSE_EVENTS);
    2845         SetDictInt("REPORT_MOUSE_POSITION",    REPORT_MOUSE_POSITION);
    2846 #endif
    2847         /* Now set everything up for KEY_ variables */
    2848         {
    2849           int key;
    2850           char *key_n;
    2851           char *key_n2;
     2825    /* Mouse-related constants */
     2826    SetDictInt("BUTTON1_PRESSED",          BUTTON1_PRESSED);
     2827    SetDictInt("BUTTON1_RELEASED",         BUTTON1_RELEASED);
     2828    SetDictInt("BUTTON1_CLICKED",          BUTTON1_CLICKED);
     2829    SetDictInt("BUTTON1_DOUBLE_CLICKED",   BUTTON1_DOUBLE_CLICKED);
     2830    SetDictInt("BUTTON1_TRIPLE_CLICKED",   BUTTON1_TRIPLE_CLICKED);
     2831
     2832    SetDictInt("BUTTON2_PRESSED",          BUTTON2_PRESSED);
     2833    SetDictInt("BUTTON2_RELEASED",         BUTTON2_RELEASED);
     2834    SetDictInt("BUTTON2_CLICKED",          BUTTON2_CLICKED);
     2835    SetDictInt("BUTTON2_DOUBLE_CLICKED",   BUTTON2_DOUBLE_CLICKED);
     2836    SetDictInt("BUTTON2_TRIPLE_CLICKED",   BUTTON2_TRIPLE_CLICKED);
     2837
     2838    SetDictInt("BUTTON3_PRESSED",          BUTTON3_PRESSED);
     2839    SetDictInt("BUTTON3_RELEASED",         BUTTON3_RELEASED);
     2840    SetDictInt("BUTTON3_CLICKED",          BUTTON3_CLICKED);
     2841    SetDictInt("BUTTON3_DOUBLE_CLICKED",   BUTTON3_DOUBLE_CLICKED);
     2842    SetDictInt("BUTTON3_TRIPLE_CLICKED",   BUTTON3_TRIPLE_CLICKED);
     2843
     2844    SetDictInt("BUTTON4_PRESSED",          BUTTON4_PRESSED);
     2845    SetDictInt("BUTTON4_RELEASED",         BUTTON4_RELEASED);
     2846    SetDictInt("BUTTON4_CLICKED",          BUTTON4_CLICKED);
     2847    SetDictInt("BUTTON4_DOUBLE_CLICKED",   BUTTON4_DOUBLE_CLICKED);
     2848    SetDictInt("BUTTON4_TRIPLE_CLICKED",   BUTTON4_TRIPLE_CLICKED);
     2849
     2850    SetDictInt("BUTTON_SHIFT",             BUTTON_SHIFT);
     2851    SetDictInt("BUTTON_CTRL",              BUTTON_CTRL);
     2852    SetDictInt("BUTTON_ALT",               BUTTON_ALT);
     2853
     2854    SetDictInt("ALL_MOUSE_EVENTS",         ALL_MOUSE_EVENTS);
     2855    SetDictInt("REPORT_MOUSE_POSITION",    REPORT_MOUSE_POSITION);
     2856#endif
     2857    /* Now set everything up for KEY_ variables */
     2858    {
     2859        int key;
     2860        char *key_n;
     2861        char *key_n2;
    28522862#if !defined(__NetBSD__)
    2853           for (key=KEY_MIN;key < KEY_MAX; key++) {
    2854             key_n = (char *)keyname(key);
    2855             if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
    2856               continue;
    2857             if (strncmp(key_n,"KEY_F(",6)==0) {
    2858               char *p1, *p2;
    2859               key_n2 = malloc(strlen(key_n)+1);
    2860               if (!key_n2) {
    2861                 PyErr_NoMemory();
    2862                 break;
    2863               }
    2864               p1 = key_n;
    2865               p2 = key_n2;
    2866               while (*p1) {
    2867                 if (*p1 != '(' && *p1 != ')') {
    2868                   *p2 = *p1;
    2869                   p2++;
    2870                 }
    2871                 p1++;
    2872               }
    2873               *p2 = (char)0;
    2874             } else
    2875               key_n2 = key_n;
    2876             SetDictInt(key_n2,key);
    2877             if (key_n2 != key_n)
    2878               free(key_n2);
    2879           }
    2880 #endif
    2881           SetDictInt("KEY_MIN", KEY_MIN);
    2882           SetDictInt("KEY_MAX", KEY_MAX);
    2883         }
    2884 }
     2863        for (key=KEY_MIN;key < KEY_MAX; key++) {
     2864            key_n = (char *)keyname(key);
     2865            if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
     2866                continue;
     2867            if (strncmp(key_n,"KEY_F(",6)==0) {
     2868                char *p1, *p2;
     2869                key_n2 = malloc(strlen(key_n)+1);
     2870                if (!key_n2) {
     2871                    PyErr_NoMemory();
     2872                    break;
     2873                }
     2874                p1 = key_n;
     2875                p2 = key_n2;
     2876                while (*p1) {
     2877                    if (*p1 != '(' && *p1 != ')') {
     2878                        *p2 = *p1;
     2879                        p2++;
     2880                    }
     2881                    p1++;
     2882                }
     2883                *p2 = (char)0;
     2884            } else
     2885                key_n2 = key_n;
     2886            SetDictInt(key_n2,key);
     2887            if (key_n2 != key_n)
     2888                free(key_n2);
     2889        }
     2890#endif
     2891        SetDictInt("KEY_MIN", KEY_MIN);
     2892        SetDictInt("KEY_MAX", KEY_MAX);
     2893    }
     2894}
Note: See TracChangeset for help on using the changeset viewer.