Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / window / wwpty.c
index eff0ec4..0919d52 100644 (file)
@@ -1,39 +1,63 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwpty.c     3.1 83/08/09";
+static char sccsid[] = "@(#)wwpty.c    3.11 %G%";
 #endif
 
 #endif
 
+/*
+ * Copyright (c) 1983 Regents of the University of California,
+ * All rights reserved.  Redistribution permitted subject to
+ * the terms of the Berkeley Software License Agreement.
+ */
+
 #include "ww.h"
 
 #include "ww.h"
 
+/*
+ * To satisfy Chris, we allocate pty's backwards, and if
+ * there are more than the ptyp's (i.e. the ptyq's)
+ * on the machine, we don't use the p's.
+ */
 wwgetpty(w)
 wwgetpty(w)
-       register struct ww *w;
+register struct ww *w;
 {
        register char c;
 {
        register char c;
-       register char *line;
        register int i;
        register int i;
-#define PTY "/dev/ptyXX"
+       int tty;
+       int on = 1;
+       char hasq = 0;
+#define PTY "/dev/XtyXX"
+#define _PT    5
+#define _PQRS  8
+#define _0_9   9
 
 
-       for (c = 'p'; c <= 's'; c++) {
-               line = PTY;
-               line[sizeof PTY - 6] = 'p';
-               line[sizeof PTY - 3] = c;
-               line[sizeof PTY - 2] = '0';
-               if (access(line, 0) < 0)
+       (void) strcpy(w->ww_ttyname, PTY);
+       for (c = 's'; c >= 'p'; c--) {
+               w->ww_ttyname[_PT] = 'p';
+               w->ww_ttyname[_PQRS] = c;
+               w->ww_ttyname[_0_9] = '0';
+               if (access(w->ww_ttyname, 0) < 0)
+                       continue;
+               if (c != 'p')
+                       hasq = 1;
+               else if (hasq)
                        break;
                        break;
-               for (i = 0; i < 16; i++) {
-                       line[sizeof PTY - 6] = 'p';
-                       line[sizeof PTY - 2] = "0123456789abcdef"[i];
-                       w->ww_pty = open(line, 2);
-                       if (w->ww_pty >= 0) {
-                               line[sizeof PTY - 6] = 't';
-                               w->ww_tty = open(line, 2);
-                               if (w->ww_tty >= 0)
-                                       goto good;
+               for (i = 15; i >= 0; i--) {
+                       w->ww_ttyname[_PT] = 'p';
+                       w->ww_ttyname[_0_9] = "0123456789abcdef"[i];
+                       if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0)
+                               continue;
+                       w->ww_ttyname[_PT] = 't';
+                       if ((tty = open(w->ww_ttyname, 2)) < 0) {
+                               (void) close(w->ww_pty);
+                               continue;
+                       }
+                       (void) close(tty);
+                       if (ioctl(w->ww_pty, (int)TIOCPKT, (char *)&on) < 0) {
                                (void) close(w->ww_pty);
                                (void) close(w->ww_pty);
+                               continue;
                        }
                        }
+                       return 0;
                }
        }
                }
        }
+       w->ww_pty = -1;
+       wwerrno = WWE_NOPTY;
        return -1;
        return -1;
-good:
-       (void) strcpy(w->ww_ttyname, line);
-       return 0;
 }
 }