[Python-checkins] CVS: python/dist/src/Modules _cursesmodule.c,2.41,2.42
A.M. Kuchling
python-dev@python.org
Sat, 18 Nov 2000 09:46:02 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv20498
Modified Files:
_cursesmodule.c
Log Message:
Patch #102412 from mwh: Add support for the setupterm() function, to
initialize the terminal without necessarily calling initscr()
Index: _cursesmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_cursesmodule.c,v
retrieving revision 2.41
retrieving revision 2.42
diff -C2 -r2.41 -r2.42
*** _cursesmodule.c 2000/11/07 03:34:44 2.41
--- _cursesmodule.c 2000/11/18 17:45:59 2.42
***************
*** 45,54 ****
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr napms newterm
! overlay overwrite resetty resizeterm restartterm ripoffline
! savetty scr_dump scr_init scr_restore scr_set scrl set_curterm
! set_term setterm setupterm tgetent tgetflag tgetnum tgetstr
! tgoto timeout tputs typeahead use_default_colors vidattr
! vidputs waddchnstr waddchstr wchgat wcolor_set winchnstr
! winchstr winnstr wmouse_trafo wredrawln wscrl wtimeout
Low-priority:
--- 45,53 ----
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr napms newterm
! overlay overwrite resizeterm restartterm ripoffline scr_dump
! scr_init scr_restore scr_set scrl set_curterm set_term setterm
! tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
! use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
! wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Low-priority:
***************
*** 78,86 ****
#endif
#ifdef sgi
- /* This prototype is in <term.h>, but including this header #defines
- many common symbols (such as "lines") which breaks the curses
- module in other ways. So the code will just specify an explicit
- prototype here. */
extern char *tigetstr(char *);
#endif
--- 77,86 ----
#endif
+ /* These prototypes are in <term.h>, but including this header
+ #defines many common symbols (such as "lines") which breaks the
+ curses module in other ways. So the code will just specify
+ explicit prototypes here. */
+ extern int setupterm(char *,int,int *);
#ifdef sgi
extern char *tigetstr(char *);
#endif
***************
*** 99,102 ****
--- 99,105 ----
static char *catchall_NULL = "curses function returned NULL";
+ /* Tells whether setupterm() has been called to initialise terminfo. */
+ static int initialised_setupterm = FALSE;
+
/* Tells whether initscr() has been called to initialise curses. */
static int initialised = FALSE;
***************
*** 109,112 ****
--- 112,121 ----
(((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
+ #define PyCursesSetupTermCalled \
+ if (initialised_setupterm != TRUE) { \
+ PyErr_SetString(PyCursesError, \
+ "must call (at least) setupterm() first"); \
+ return NULL; }
+
#define PyCursesInitialised \
if (initialised != TRUE) { \
***************
*** 1703,1707 ****
}
! initialised = TRUE;
/* This was moved from initcurses() because it core dumped on SGI,
--- 1712,1716 ----
}
! initialised = initialised_setupterm = TRUE;
/* This was moved from initcurses() because it core dumped on SGI,
***************
*** 1781,1784 ****
--- 1790,1844 ----
}
+ static PyObject *
+ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
+ {
+ int fd = -1;
+ int err;
+ char* termstr = NULL;
+
+ static char *kwlist[] = {"term", "fd", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args,keywds,"|zi:setupterm",kwlist,&termstr,&fd)) {
+ return NULL;
+ }
+
+ if (fd == -1) {
+ PyObject* sys_stdout;
+
+ sys_stdout = PySys_GetObject("stdout");
+
+ if (sys_stdout == NULL) {
+ PyErr_SetString(
+ PyCursesError,
+ "lost sys.stdout");
+ return NULL;
+ }
+
+ fd = PyObject_AsFileDescriptor(sys_stdout);
+
+ if (fd == -1) {
+ return NULL;
+ }
+ }
+
+ if (setupterm(termstr,fd,&err) == ERR) {
+ char* s = "setupterm: unknown error";
+
+ if (err == 0) {
+ s = "setupterm: could not find terminal";
+ } else if (err == -1) {
+ s = "setupterm: could not find terminfo database";
+ }
+
+ PyErr_SetString(PyCursesError,s);
+ return NULL;
+ }
+
+ initialised_setupterm = TRUE;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
static PyObject *
***************
*** 2058,2062 ****
char *capname;
! PyCursesInitialised;
if (!PyArg_ParseTuple(args, "z", &capname))
--- 2118,2122 ----
char *capname;
! PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
***************
*** 2071,2075 ****
char *capname;
! PyCursesInitialised;
if (!PyArg_ParseTuple(args, "z", &capname))
--- 2131,2135 ----
char *capname;
! PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
***************
*** 2084,2088 ****
char *capname;
! PyCursesInitialised;
if (!PyArg_ParseTuple(args, "z", &capname))
--- 2144,2148 ----
char *capname;
! PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
***************
*** 2104,2108 ****
int i1,i2,i3,i4,i5,i6,i7,i8,i9;
! PyCursesInitialised;
if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
--- 2164,2168 ----
int i1,i2,i3,i4,i5,i6,i7,i8,i9;
! PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
***************
*** 2291,2294 ****
--- 2351,2355 ----
{"savetty", (PyCFunction)PyCurses_savetty},
{"setsyx", (PyCFunction)PyCurses_setsyx},
+ {"setupterm", (PyCFunction)PyCurses_setupterm, METH_VARARGS|METH_KEYWORDS},
{"start_color", (PyCFunction)PyCurses_Start_Color},
{"termattrs", (PyCFunction)PyCurses_termattrs},