summaryrefslogtreecommitdiff
path: root/emulators/x48/patches/patch-ae
blob: f82ee24b98b8afcf4898edf75d9e85762a9f19d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
$NetBSD: patch-ae,v 1.2 2005/12/03 17:16:52 joerg Exp $

--- src/serial.c.orig	1999-06-28 22:12:29.000000000 +0000
+++ src/serial.c
@@ -69,7 +69,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/time.h>
-#if defined(LINUX) || defined(HPUX)
+#if defined(LINUX) || defined(HPUX) || defined(CSRG_BASED)
 #include <sys/ioctl.h>
 #endif
 #include <unistd.h>
@@ -77,6 +77,8 @@
 #ifdef SOLARIS
 #include <sys/stream.h>
 #include <sys/stropts.h>
+#endif
+#if defined(SOLARIS) || defined(CSRG_BASED)
 #include <sys/termios.h>
 #endif
 
@@ -129,6 +131,9 @@ serial_init()
 #else
   int   c;
 #endif
+#if defined(CSRG_BASED)
+  char *ptr1, *ptr2;
+#endif
   int   n;
   char  tty_dev_name[128];
   struct termios ttybuf;
@@ -200,6 +205,51 @@ serial_init()
         }
       while ((wire_fd < 0) && (errno != ENOENT));
 #else  /* LINUX */
+#if defined(CSRG_BASED)
+      c = c; /* XXX gcc */
+/* This is how Stevens does it in:
+ * Advanced programming in the UNIX environment
+ */
+      strcpy(tty_dev_name, "/dev/ptyXY");
+        /* array index: 0123456789 (for references in following code) */
+      for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++)
+        {
+          tty_dev_name[8] = *ptr1;
+          for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++)
+            {
+              tty_dev_name[9] = *ptr2;
+
+              /* try open the master */
+              if ((wire_fd = open(tty_dev_name, O_RDWR, 0666)) < 0)
+                {
+                  if (errno == ENOENT)
+                    {
+                      wire_fd = -1;              /* out of pty devices */
+                      ttyp = -1;
+                      goto break_for_pty;
+                    }
+                  else
+                    continue;                    /* try next pty device */
+                }
+
+              tty_dev_name[5] = 't';   /* change pty to tty */
+              if ((ttyp = open(tty_dev_name, O_RDWR, 0666)) < 0)
+                {
+                  printf("open tty: %s failed: %s, trying with another\n",
+                          tty_dev_name, strerror(errno));
+                  close(wire_fd);
+                  wire_fd = -1;
+                  ttyp = -1;
+                  continue;
+                }
+              if (verbose)
+                printf("%s: wire connection on %s\n", progname, tty_dev_name);
+              wire_name = strdup(tty_dev_name);
+              goto break_for_pty;
+            }
+        }
+break_for_pty:
+#else
       /*
        * Here we go for SUNOS, HPUX
        */
@@ -231,14 +281,16 @@ serial_init()
           c++;
         }
       while ((wire_fd < 0) && (errno != ENOENT));
+#endif /* CSRG_BASED */
 #endif /* LINUX */
 #endif /* SOLARIS */
 #endif /* IRIX */
+	;
     }
 
   if (ttyp >= 0)
     {
-#if defined(SUNOS) || defined(HPUX)
+#if defined(SUNOS) || defined(HPUX) || defined(CSRG_BASED)
       if (tcgetattr(ttyp, &ttybuf) < 0)
 #else
       if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0)
@@ -263,7 +315,7 @@ serial_init()
 
   if (ttyp >= 0)
     {
-#if defined(SUNOS) || defined (HPUX)
+#if defined(SUNOS) || defined (HPUX) || defined(CSRG_BASED)
       if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0)
 #else
       if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0)
@@ -291,7 +343,7 @@ serial_init()
 
   if (ir_fd >= 0)
     {
-#if defined(SUNOS) || defined (HPUX)
+#if defined(SUNOS) || defined (HPUX) || defined(CSRG_BASED)
       if (tcgetattr(ir_fd, &ttybuf) < 0)
 #else
       if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0)
@@ -315,7 +367,7 @@ serial_init()
 
   if (ir_fd >= 0)
     {
-#if defined(SUNOS) || defined(HPUX)
+#if defined(SUNOS) || defined(HPUX) || defined(CSRG_BASED)
       if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0)
 #else
       if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0)
@@ -344,7 +396,7 @@ int baud;
 
   if (ir_fd >= 0)
     {
-#if defined(SUNOS) || defined (HPUX)
+#if defined(SUNOS) || defined (HPUX) || defined(CSRG_BASED)
       if (tcgetattr(ir_fd, &ttybuf) < 0)
 #else
       if (ioctl(ir_fd, TCGETS, (char *)&ttybuf) < 0)
@@ -358,6 +410,10 @@ int baud;
         }
     }
 
+#if defined(CSRG_BASED)
+  cfsetspeed(&ttybuf, baud);
+#else
+
   ttybuf.c_cflag &= ~CBAUD;
 
   baud &= 0x7;
@@ -404,9 +460,11 @@ int baud;
       ttybuf.c_cflag |= B9600;
     }
 
+#endif /* CSRG_BASED */
+
   if (ir_fd >= 0)
     {
-#if defined(SUNOS) || defined(HPUX)
+#if defined(SUNOS) || defined(HPUX) || defined(CSRG_BASED)
       if (tcsetattr(ir_fd, TCSANOW, &ttybuf) < 0)
 #else
       if (ioctl(ir_fd, TCSETS, (char *)&ttybuf) < 0)
@@ -422,7 +480,7 @@ int baud;
 
   if (ttyp >= 0)
     {
-#if defined(SUNOS) || defined(HPUX)
+#if defined(SUNOS) || defined(HPUX) || defined(CSRG_BASED)
       if (tcgetattr(ttyp, &ttybuf) < 0)
 #else
       if (ioctl(ttyp, TCGETS, (char *)&ttybuf) < 0)
@@ -437,6 +495,9 @@ int baud;
         }
     }
 
+#if defined(CSRG_BASED)
+  cfsetspeed(&ttybuf, baud);
+#else
   ttybuf.c_cflag &= ~CBAUD;
 
   baud &= 0x7;
@@ -482,10 +543,11 @@ int baud;
         fprintf(stderr, "%s: can\'t set baud rate, using 9600\n", progname);
       ttybuf.c_cflag |= B9600;
     }
+#endif
 
   if (ttyp >= 0)
     {
-#if defined(SUNOS) || defined(HPUX)
+#if defined(SUNOS) || defined(HPUX) || defined(CSRG_BASED)
       if (tcsetattr(ttyp, TCSANOW, &ttybuf) < 0)
 #else
       if (ioctl(ttyp, TCSETS, (char *)&ttybuf) < 0)