[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

termios (was: Re: MiNT 1.11 BETA)



Addition to Juergen's patches for the termios emulation in MiNTlib:

I've changed the CS? values to match _TF_?BIT so that they can be
copied more easily, and fixed a bug in his patch.
And i added code for backward compatibility since TIOCSETP has changed.

--- orig/termios.h	Fri Aug 19 21:44:12 1994
+++ termios.h	Fri Aug 19 21:46:28 1994
@@ -97,11 +97,12 @@
 /* control modes */
 #define CLOCAL	0x0001
 #define CREAD	0x0002
-#define CS5	0x0004
+/* next four must agree with _TF_?BIT */
+#define CS5	0x000C
 #define CS6	0x0008
-#define CS7	0x0010
-#define CS8	0x0020
-# define CSIZE	(CS5 | CS6 | CS7 | CS8)
+#define CS7	0x0004
+#define CS8	0x0000
+# define CSIZE	0x000C
 #define CSTOPB	0x0040
 #define HUPCL	0x0080
 #define PARENB	0x0100
--- orig/tcattr.c	Fri Aug 19 22:10:38 1994
+++ tcattr.c	Fri Aug 19 22:11:18 1994
@@ -15,6 +15,8 @@
 
 #define VTIME_MS	(1000/HZ)
 
+extern int __mint;
+
 int
 tcgetattr(fd, stp)
   int fd;
@@ -61,25 +63,10 @@
 			| ((flags & _TF_CAR) ? 0 : CLOCAL)
 			| ((state & _TS_HPCL) ? HUPCL : 0)
 			| (((flags & _TF_STOPBITS) == _TF_2STOP) ? CSTOPB : 0)
+			| (flags & _TF_CHARBITS)
 			| ((sg.sg_flags & RTSCTS) ? CRTSCTS : 0)
 			| ((sg.sg_flags & EVENP) ? PARENB : 0)
 			| ((sg.sg_flags & ODDP) ? (PARENB | PARODD) : 0));
-  switch (flags & _TF_CHARBITS)
-  {
-    case _TF_5BIT:
-      stp->c_cflag |= CS5;
-      break;
-    case _TF_6BIT:
-      stp->c_cflag |= CS6;
-      break;
-    case _TF_7BIT:
-      stp->c_cflag |= CS7;
-      break;
-    case _TF_8BIT:
-    default:
-      stp->c_cflag |= CS8;
-      break;
-  }
   stp->c_lflag = (tcflag_t) ((sg.sg_flags & (TOSTOP | NOFLSH))
 			| ((sg.sg_flags & ECHO) ? (ECHO | ECHOE | ECHOK) : 0)
 			| ((sg.sg_flags & XKEY) ? IEXTEN : 0)
@@ -143,27 +130,12 @@
 			| ((stp->c_cflag & CRTSCTS) ? RTSCTS : 0));
   flags = ((stp->c_cflag & CSTOPB) ? _TF_2STOP : _TF_1STOP) |
 		((stp->c_cflag & CLOCAL) ? 0 : _TF_CAR) |
-		((stp->c_iflag & BRKINT) ? _TF_BRKINT : 0);
+		((stp->c_iflag & BRKINT) ? _TF_BRKINT : 0) |
+		(stp->c_cflag & CSIZE);
   state = (stp->c_cflag & HUPCL) ? _TS_HPCL : 0;
   sg.sg_flags |= ((stp->c_cflag & PARENB)
 			? ((stp->c_cflag & PARODD) ? ODDP : EVENP)
 			: 0);
-  switch (stp->c_cflag & (CS5 | CS6 | CS7 | CS8))
-  {
-    case CS5:
-      flags |= _TF_5BIT;
-      break;
-    case CS6:
-      flags |= _TF_6BIT;
-      break;
-    case CS7:
-      flags |= _TF_7BIT;
-      break;
-    case CS8:
-    default:
-      flags |= _TF_8BIT;
-      break;
-  }
   sg.sg_flags |= ((stp->c_lflag & (TOSTOP | NOFLSH | ECHO))
 			| ((stp->c_lflag & IEXTEN) ? XKEY : 0)
 			| ((stp->c_lflag & ISIG)
@@ -192,7 +164,7 @@
       tcflush(fd, TCIFLUSH);
       /* fall through */
     case TCSADRAIN:
-      r = Fcntl((short) fd, (long) &sg, TIOCSETP);
+      r = Fcntl((short) fd, (long) &sg, __mint < 0x10b ? TIOCSETN : TIOCSETP);
       if (r < 0) {
         errno = (int) -r;
         return -1;
@@ -227,7 +199,7 @@
     (void) Fcntl((short) fd, (long) &sflags, TIOCGFLAGS);
     sflags &= ~(_TF_STOPBITS | _TF_CHARBITS);
     sflags |= flags & (_TF_STOPBITS | _TF_CHARBITS);
-    (void) Fcntl((short) fd, (long) &flags, TIOCSFLAGS);
+    (void) Fcntl((short) fd, (long) &sflags, TIOCSFLAGS);
   }
   (void) Fcntl((short) fd, (long) &vmin, TIOCSVMIN);
   bits[0] = (unsigned)state;