[Python-checkins] CVS: python/dist/src/Modules termios.c,2.24,2.24.2.1

Fred L. Drake fdrake@users.sourceforge.net
Fri, 11 May 2001 09:34:25 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv10999

Modified Files:
      Tag: release21-maint
	termios.c 
Log Message:

Migrate the last few revisions from the head to the bugfix branch -- these
have all been portability fixes and improving the consistency of how file
descriptors and file objects are handled.


Index: termios.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/termios.c,v
retrieving revision 2.24
retrieving revision 2.24.2.1
diff -C2 -r2.24 -r2.24.2.1
*** termios.c	2001/04/11 20:57:57	2.24
--- termios.c	2001/05/11 16:34:23	2.24.2.1
***************
*** 6,13 ****
  
  #include <termios.h>
! /* XXX Some systems need this to get all the symbols, while
!        this breaks for others.
  #include <sys/ioctl.h>
! */
  
  static char termios__doc__[] = "\
--- 6,27 ----
  
  #include <termios.h>
! #ifdef __osf__
! /* On OSF, sys/ioctl.h requires that struct termio already be defined,
!  * so this needs to be included first on that platform. */
! #include <termio.h>
! #endif
  #include <sys/ioctl.h>
! 
! #ifdef __BEOS__
! #include <unistd.h>
! #endif
! 
! /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
!  * MDTR, MRI, and MRTS (appearantly used internally by some things
!  * defined as macros; these are not used here directly).
!  */
! #ifdef HAVE_SYS_MODEM_H
! #include <sys/modem.h>
! #endif
  
  static char termios__doc__[] = "\
***************
*** 15,42 ****
  For a complete description of these calls, see the Posix or Unix manual\n\
  pages. It is only available for those Unix versions that support Posix\n\
! termios style tty I/O control (and then only if configured at installation\n\
! time).\n\
  \n\
  All functions in this module take a file descriptor fd as their first\n\
! argument. This must be an integer file descriptor, such as returned by\n\
! sys.stdin.fileno().";
! 
  
- #ifdef __BEOS__
- #include <unistd.h>
- #endif
- 
- #define BAD "bad termios argument"
- 
  static PyObject *TermiosError;
  
! /* termios = tcgetattr(fd)
!    termios is
!    [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]] 
  
!    Return the attributes of the terminal device.  */
  
  static char termios_tcgetattr__doc__[] = "\
  tcgetattr(fd) -> list_of_attrs\n\
  Get the tty attributes for file descriptor fd, as follows:\n\
  [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
--- 29,55 ----
  For a complete description of these calls, see the Posix or Unix manual\n\
  pages. It is only available for those Unix versions that support Posix\n\
! termios style tty I/O control.\n\
  \n\
  All functions in this module take a file descriptor fd as their first\n\
! argument. This can be an integer file descriptor, such as returned by\n\
! sys.stdin.fileno(), or a file object, such as sys.stdin itself.";
  
  static PyObject *TermiosError;
  
! static int fdconv(PyObject* obj, void* p)
! {
! 	int fd;
  
! 	fd = PyObject_AsFileDescriptor(obj);
! 	if (fd >= 0) {
! 		*(int*)p = fd;
! 		return 1;
! 	}
! 	return 0;
! }
  
  static char termios_tcgetattr__doc__[] = "\
  tcgetattr(fd) -> list_of_attrs\n\
+ \n\
  Get the tty attributes for file descriptor fd, as follows:\n\
  [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
***************
*** 58,62 ****
  	char ch;
  
! 	if (!PyArg_Parse(args, "i", &fd))
  		return NULL;
  
--- 71,76 ----
  	char ch;
  
! 	if (!PyArg_ParseTuple(args, "O&:tcgetattr", 
! 			      fdconv, (void*)&fd))
  		return NULL;
  
***************
*** 112,120 ****
  }
  
- /* tcsetattr(fd, when, termios)
-    Set the attributes of the terminal device.  */
- 
  static char termios_tcsetattr__doc__[] = "\
  tcsetattr(fd, when, attributes) -> None\n\
  Set the tty attributes for file descriptor fd.\n\
  The attributes to be set are taken from the attributes argument, which\n\
--- 126,132 ----
  }
  
  static char termios_tcsetattr__doc__[] = "\
  tcsetattr(fd, when, attributes) -> None\n\
+ \n\
  Set the tty attributes for file descriptor fd.\n\
  The attributes to be set are taken from the attributes argument, which\n\
***************
*** 134,141 ****
  	int i;
  
! 	if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
  		return NULL;
  	if (!PyList_Check(term) || PyList_Size(term) != 7) {
! 		PyErr_SetString(PyExc_TypeError, BAD);
  		return NULL;
  	}
--- 146,155 ----
  	int i;
  
! 	if (!PyArg_ParseTuple(args, "O&iO:tcsetattr", 
! 			      fdconv, &fd, &when, &term))
  		return NULL;
  	if (!PyList_Check(term) || PyList_Size(term) != 7) {
! 		PyErr_SetString(PyExc_TypeError, 
! 			     "tcsetattr, arg 3: must be 7 element list");
  		return NULL;
  	}
***************
*** 155,159 ****
  
  	if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
! 		PyErr_SetString(PyExc_TypeError, BAD);
  		return NULL;
  	}
--- 169,175 ----
  
  	if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
! 		PyErr_Format(PyExc_TypeError, 
! 			"tcsetattr: attributes[6] must be %d element list",
! 			     NCCS);
  		return NULL;
  	}
***************
*** 167,171 ****
  			mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
  		else {
! 			PyErr_SetString(PyExc_TypeError, BAD);
  			return NULL;
  		}
--- 183,188 ----
  			mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
  		else {
! 			PyErr_SetString(PyExc_TypeError, 
!      "tcsetattr: elements of attributes must be characters or integers");
  			return NULL;
  		}
***************
*** 183,194 ****
  }
  
- /* tcsendbreak(fd, duration)
-    Generate a break condition.  */
- 
  static char termios_tcsendbreak__doc__[] = "\
  tcsendbreak(fd, duration) -> None\n\
  Send a break on file descriptor fd.\n\
! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
! has a system dependent meaning. ";
  
  static PyObject *
--- 200,209 ----
  }
  
  static char termios_tcsendbreak__doc__[] = "\
  tcsendbreak(fd, duration) -> None\n\
+ \n\
  Send a break on file descriptor fd.\n\
! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
! has a system dependent meaning.";
  
  static PyObject *
***************
*** 197,201 ****
  	int fd, duration;
  
! 	if (!PyArg_Parse(args, "(ii)", &fd, &duration))
  		return NULL;
  	if (tcsendbreak(fd, duration) == -1)
--- 212,217 ----
  	int fd, duration;
  
! 	if (!PyArg_ParseTuple(args, "O&i:tcsendbreak", 
! 			      fdconv, &fd, &duration))
  		return NULL;
  	if (tcsendbreak(fd, duration) == -1)
***************
*** 206,216 ****
  }
  
- /* tcdrain(fd) 
-    Wait until all queued output to the terminal has been 
-    transmitted.  */
- 
  static char termios_tcdrain__doc__[] = "\
  tcdrain(fd) -> None\n\
! Wait until all output written to file descriptor fd has been transmitted. ";
  
  static PyObject *
--- 222,229 ----
  }
  
  static char termios_tcdrain__doc__[] = "\
  tcdrain(fd) -> None\n\
! \n\
! Wait until all output written to file descriptor fd has been transmitted.";
  
  static PyObject *
***************
*** 219,223 ****
  	int fd;
  
! 	if (!PyArg_Parse(args, "i", &fd))
  		return NULL;
  	if (tcdrain(fd) == -1)
--- 232,237 ----
  	int fd;
  
! 	if (!PyArg_ParseTuple(args, "O&:tcdrain", 
! 			      fdconv, &fd))
  		return NULL;
  	if (tcdrain(fd) == -1)
***************
*** 228,237 ****
  }
  
- /* tcflush(fd, queue) 
-    Clear the input and/or output queues associated with 
-    the terminal.  */
- 
  static char termios_tcflush__doc__[] = "\
  tcflush(fd, queue) -> None\n\
  Discard queued data on file descriptor fd.\n\
  The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
--- 242,248 ----
  }
  
  static char termios_tcflush__doc__[] = "\
  tcflush(fd, queue) -> None\n\
+ \n\
  Discard queued data on file descriptor fd.\n\
  The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
***************
*** 244,248 ****
  	int fd, queue;
  
! 	if (!PyArg_Parse(args, "(ii)", &fd, &queue))
  		return NULL;
  	if (tcflush(fd, queue) == -1)
--- 255,260 ----
  	int fd, queue;
  
! 	if (!PyArg_ParseTuple(args, "O&i:tcflush", 
! 			      fdconv, &fd, &queue))
  		return NULL;
  	if (tcflush(fd, queue) == -1)
***************
*** 253,262 ****
  }
  
- /* tcflow(fd, action) 
-    Perform operations relating to XON/XOFF flow control on 
-    the terminal.  */
- 
  static char termios_tcflow__doc__[] = "\
  tcflow(fd, action) -> None\n\
  Suspend or resume input or output on file descriptor fd.\n\
  The action argument can be termios.TCOOFF to suspend output,\n\
--- 265,271 ----
  }
  
  static char termios_tcflow__doc__[] = "\
  tcflow(fd, action) -> None\n\
+ \n\
  Suspend or resume input or output on file descriptor fd.\n\
  The action argument can be termios.TCOOFF to suspend output,\n\
***************
*** 269,273 ****
  	int fd, action;
  
! 	if (!PyArg_Parse(args, "(ii)", &fd, &action))
  		return NULL;
  	if (tcflow(fd, action) == -1)
--- 278,283 ----
  	int fd, action;
  
! 	if (!PyArg_ParseTuple(args, "O&i:tcflow", 
! 			      fdconv, &fd, &action))
  		return NULL;
  	if (tcflow(fd, action) == -1)
***************
*** 281,295 ****
  {
  	{"tcgetattr", termios_tcgetattr, 
! 	 METH_OLDARGS, termios_tcgetattr__doc__},
  	{"tcsetattr", termios_tcsetattr, 
! 	 METH_OLDARGS, termios_tcsetattr__doc__},
  	{"tcsendbreak", termios_tcsendbreak, 
! 	 METH_OLDARGS, termios_tcsendbreak__doc__},
  	{"tcdrain", termios_tcdrain, 
! 	 METH_OLDARGS, termios_tcdrain__doc__},
  	{"tcflush", termios_tcflush, 
! 	 METH_OLDARGS, termios_tcflush__doc__},
  	{"tcflow", termios_tcflow, 
! 	 METH_OLDARGS, termios_tcflow__doc__},
  	{NULL, NULL}
  };
--- 291,305 ----
  {
  	{"tcgetattr", termios_tcgetattr, 
! 	 METH_VARARGS, termios_tcgetattr__doc__},
  	{"tcsetattr", termios_tcsetattr, 
! 	 METH_VARARGS, termios_tcsetattr__doc__},
  	{"tcsendbreak", termios_tcsendbreak, 
! 	 METH_VARARGS, termios_tcsendbreak__doc__},
  	{"tcdrain", termios_tcdrain, 
! 	 METH_VARARGS, termios_tcdrain__doc__},
  	{"tcflush", termios_tcflush, 
! 	 METH_VARARGS, termios_tcflush__doc__},
  	{"tcflow", termios_tcflow, 
! 	 METH_VARARGS, termios_tcflow__doc__},
  	{NULL, NULL}
  };
***************
*** 527,532 ****
--- 537,546 ----
  	{"VSUSP", VSUSP},
  	{"VEOL", VEOL},
+ #ifndef VREPRINT
  	{"VREPRINT", VREPRINT},
+ #endif
+ #ifndef VDISCARD
  	{"VDISCARD", VDISCARD},
+ #endif
  	{"VWERASE", VWERASE},
  	{"VLNEXT", VLNEXT},