Debian Codegraph @

terminal-jansi/src/main/java/org/jline/terminal/impl/jansi/linux/LinuxNativePty.java

raw
1 /*
2 * Copyright (c) 2002-2017, the original author or authors.
3 *
4 * This software is distributable under the BSD license. See the terms of the
5 * BSD license in the documentation provided with this software.
6 *
7 * http://www.opensource.org/licenses/bsd-license.php
8 */
9 package org.jline.terminal.impl.jansi.linux;
10
11 import org.fusesource.jansi.internal.CLibrary;
12 import org.jline.terminal.Attributes;
13 import org.jline.terminal.Size;
14 import org.jline.terminal.impl.jansi.JansiNativePty;
15 import org.jline.terminal.impl.jansi.osx.OsXNativePty;
16
17 import java.io.FileDescriptor;
18 import java.io.IOException;
19 import java.util.EnumMap;
20 import java.util.EnumSet;
21
22 public class LinuxNativePty extends JansiNativePty {
23
24 public static LinuxNativePty current() throws IOException {
25 try {
26 String name = ttyname();
27 return new LinuxNativePty(-1, null, 0, FileDescriptor.in, name);
28 } catch (IOException e) {
29 throw new IOException("Not a tty", e);
30 }
31 }
32
33 public static LinuxNativePty open(Attributes attr, Size size) throws IOException {
34 int[] master = new int[1];
35 int[] slave = new int[1];
36 byte[] buf = new byte[64];
37 CLibrary.openpty(master, slave, buf,
38 attr != null ? termios(attr) : null,
39 size != null ? new CLibrary.WinSize((short) size.getRows(), (short) size.getColumns()) : null);
40 int len = 0;
41 while (buf[len] != 0) {
42 len++;
43 }
44 String name = new String(buf, 0, len);
45 return new LinuxNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name);
46 }
47
48 public LinuxNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) {
49 super(master, masterFD, slave, slaveFD, name);
50 }
51
52 // CONSTANTS
53
54 private static final int VINTR = 0;
55 private static final int VQUIT = 1;
56 private static final int VERASE = 2;
57 private static final int VKILL = 3;
58 private static final int VEOF = 4;
59 private static final int VTIME = 5;
60 private static final int VMIN = 6;
61 private static final int VSWTC = 7;
62 private static final int VSTART = 8;
63 private static final int VSTOP = 9;
64 private static final int VSUSP = 10;
65 private static final int VEOL = 11;
66 private static final int VREPRINT = 12;
67 private static final int VDISCARD = 13;
68 private static final int VWERASE = 14;
69 private static final int VLNEXT = 15;
70 private static final int VEOL2 = 16;
71
72 private static final int IGNBRK = 0x0000001;
73 private static final int BRKINT = 0x0000002;
74 private static final int IGNPAR = 0x0000004;
75 private static final int PARMRK = 0x0000008;
76 private static final int INPCK = 0x0000010;
77 private static final int ISTRIP = 0x0000020;
78 private static final int INLCR = 0x0000040;
79 private static final int IGNCR = 0x0000080;
80 private static final int ICRNL = 0x0000100;
81 private static final int IUCLC = 0x0000200;
82 private static final int IXON = 0x0000400;
83 private static final int IXANY = 0x0000800;
84 private static final int IXOFF = 0x0001000;
85 private static final int IMAXBEL = 0x0002000;
86 private static final int IUTF8 = 0x0004000;
87
88 private static final int OPOST = 0x0000001;
89 private static final int OLCUC = 0x0000002;
90 private static final int ONLCR = 0x0000004;
91 private static final int OCRNL = 0x0000008;
92 private static final int ONOCR = 0x0000010;
93 private static final int ONLRET = 0x0000020;
94 private static final int OFILL = 0x0000040;
95 private static final int OFDEL = 0x0000080;
96 private static final int NLDLY = 0x0000100;
97 private static final int NL0 = 0x0000000;
98 private static final int NL1 = 0x0000100;
99 private static final int CRDLY = 0x0000600;
100 private static final int CR0 = 0x0000000;
101 private static final int CR1 = 0x0000200;
102 private static final int CR2 = 0x0000400;
103 private static final int CR3 = 0x0000600;
104 private static final int TABDLY = 0x0001800;
105 private static final int TAB0 = 0x0000000;
106 private static final int TAB1 = 0x0000800;
107 private static final int TAB2 = 0x0001000;
108 private static final int TAB3 = 0x0001800;
109 private static final int XTABS = 0x0001800;
110 private static final int BSDLY = 0x0002000;
111 private static final int BS0 = 0x0000000;
112 private static final int BS1 = 0x0002000;
113 private static final int VTDLY = 0x0004000;
114 private static final int VT0 = 0x0000000;
115 private static final int VT1 = 0x0004000;
116 private static final int FFDLY = 0x0008000;
117 private static final int FF0 = 0x0000000;
118 private static final int FF1 = 0x0008000;
119
120 private static final int CBAUD = 0x000100f;
121 private static final int B0 = 0x0000000;
122 private static final int B50 = 0x0000001;
123 private static final int B75 = 0x0000002;
124 private static final int B110 = 0x0000003;
125 private static final int B134 = 0x0000004;
126 private static final int B150 = 0x0000005;
127 private static final int B200 = 0x0000006;
128 private static final int B300 = 0x0000007;
129 private static final int B600 = 0x0000008;
130 private static final int B1200 = 0x0000009;
131 private static final int B1800 = 0x000000a;
132 private static final int B2400 = 0x000000b;
133 private static final int B4800 = 0x000000c;
134 private static final int B9600 = 0x000000d;
135 private static final int B19200 = 0x000000e;
136 private static final int B38400 = 0x000000f;
137 private static final int EXTA = B19200;
138 private static final int EXTB = B38400;
139 private static final int CSIZE = 0x0000030;
140 private static final int CS5 = 0x0000000;
141 private static final int CS6 = 0x0000010;
142 private static final int CS7 = 0x0000020;
143 private static final int CS8 = 0x0000030;
144 private static final int CSTOPB = 0x0000040;
145 private static final int CREAD = 0x0000080;
146 private static final int PARENB = 0x0000100;
147 private static final int PARODD = 0x0000200;
148 private static final int HUPCL = 0x0000400;
149 private static final int CLOCAL = 0x0000800;
150
151 private static final int ISIG = 0x0000001;
152 private static final int ICANON = 0x0000002;
153 private static final int XCASE = 0x0000004;
154 private static final int ECHO = 0x0000008;
155 private static final int ECHOE = 0x0000010;
156 private static final int ECHOK = 0x0000020;
157 private static final int ECHONL = 0x0000040;
158 private static final int NOFLSH = 0x0000080;
159 private static final int TOSTOP = 0x0000100;
160 private static final int ECHOCTL = 0x0000200;
161 private static final int ECHOPRT = 0x0000400;
162 private static final int ECHOKE = 0x0000800;
163 private static final int FLUSHO = 0x0001000;
164 private static final int PENDIN = 0x0002000;
165 private static final int IEXTEN = 0x0008000;
166 private static final int EXTPROC = 0x0010000;
167
168 protected CLibrary.Termios toTermios(Attributes t) {
169 return termios(t);
170 }
171
172 static CLibrary.Termios termios(Attributes t) {
173 CLibrary.Termios tio = new CLibrary.Termios();
174 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNBRK), IGNBRK, tio.c_iflag);
175 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.BRKINT), BRKINT, tio.c_iflag);
176 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNPAR), IGNPAR, tio.c_iflag);
177 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.PARMRK), PARMRK, tio.c_iflag);
178 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.INPCK), INPCK, tio.c_iflag);
179 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.ISTRIP), ISTRIP, tio.c_iflag);
180 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.INLCR), INLCR, tio.c_iflag);
181 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNCR), IGNCR, tio.c_iflag);
182 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.ICRNL), ICRNL, tio.c_iflag);
183 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXON), IXON, tio.c_iflag);
184 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXOFF), IXOFF, tio.c_iflag);
185 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXANY), IXANY, tio.c_iflag);
186 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IMAXBEL), IMAXBEL, tio.c_iflag);
187 tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IUTF8), IUTF8, tio.c_iflag);
188 // Output flags
189 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OPOST), OPOST, tio.c_oflag);
190 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONLCR), ONLCR, tio.c_oflag);
191 // tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OXTABS), OXTABS, tio.c_oflag);
192 // tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONOEOT), ONOEOT, tio.c_oflag);
193 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OCRNL), OCRNL, tio.c_oflag);
194 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONOCR), ONOCR, tio.c_oflag);
195 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONLRET), ONLRET, tio.c_oflag);
196 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OFILL), OFILL, tio.c_oflag);
197 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.NLDLY), NLDLY, tio.c_oflag);
198 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.TABDLY), TABDLY, tio.c_oflag);
199 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.CRDLY), CRDLY, tio.c_oflag);
200 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.FFDLY), FFDLY, tio.c_oflag);
201 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.BSDLY), BSDLY, tio.c_oflag);
202 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.VTDLY), VTDLY, tio.c_oflag);
203 tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OFDEL), OFDEL, tio.c_oflag);
204 // Control flags
205 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CIGNORE), CIGNORE, tio.c_cflag);
206 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS5), CS5, tio.c_cflag);
207 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS6), CS6, tio.c_cflag);
208 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS7), CS7, tio.c_cflag);
209 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS8), CS8, tio.c_cflag);
210 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CSTOPB), CSTOPB, tio.c_cflag);
211 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CREAD), CREAD, tio.c_cflag);
212 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.PARENB), PARENB, tio.c_cflag);
213 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.PARODD), PARODD, tio.c_cflag);
214 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.HUPCL), HUPCL, tio.c_cflag);
215 tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CLOCAL), CLOCAL, tio.c_cflag);
216 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CCTS_OFLOW), CCTS_OFLOW, tio.c_cflag);
217 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CRTS_IFLOW), CRTS_IFLOW, tio.c_cflag);
218 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CDTR_IFLOW), CDTR_IFLOW, tio.c_cflag);
219 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CDSR_OFLOW), CDSR_OFLOW, tio.c_cflag);
220 // tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CCAR_OFLOW), CCAR_OFLOW, tio.c_cflag);
221 // Local flags
222 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOKE), ECHOKE, tio.c_lflag);
223 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOE), ECHOE, tio.c_lflag);
224 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOK), ECHOK, tio.c_lflag);
225 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHO), ECHO, tio.c_lflag);
226 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHONL), ECHONL, tio.c_lflag);
227 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOPRT), ECHOPRT, tio.c_lflag);
228 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOCTL), ECHOCTL, tio.c_lflag);
229 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ISIG), ISIG, tio.c_lflag);
230 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ICANON), ICANON, tio.c_lflag);
231 // tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ALTWERASE), ALTWERASE, tio.c_lflag);
232 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.IEXTEN), IEXTEN, tio.c_lflag);
233 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.EXTPROC), EXTPROC, tio.c_lflag);
234 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.TOSTOP), TOSTOP, tio.c_lflag);
235 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.FLUSHO), FLUSHO, tio.c_lflag);
236 // tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.NOKERNINFO), NOKERNINFO, tio.c_lflag);
237 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.PENDIN), PENDIN, tio.c_lflag);
238 tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.NOFLSH), NOFLSH, tio.c_lflag);
239 // Control chars
240 tio.c_cc[VEOF] = (byte) t.getControlChar(Attributes.ControlChar.VEOF);
241 tio.c_cc[VEOL] = (byte) t.getControlChar(Attributes.ControlChar.VEOL);
242 tio.c_cc[VEOL2] = (byte) t.getControlChar(Attributes.ControlChar.VEOL2);
243 tio.c_cc[VERASE] = (byte) t.getControlChar(Attributes.ControlChar.VERASE);
244 tio.c_cc[VWERASE] = (byte) t.getControlChar(Attributes.ControlChar.VWERASE);
245 tio.c_cc[VKILL] = (byte) t.getControlChar(Attributes.ControlChar.VKILL);
246 tio.c_cc[VREPRINT] = (byte) t.getControlChar(Attributes.ControlChar.VREPRINT);
247 tio.c_cc[VINTR] = (byte) t.getControlChar(Attributes.ControlChar.VINTR);
248 tio.c_cc[VQUIT] = (byte) t.getControlChar(Attributes.ControlChar.VQUIT);
249 tio.c_cc[VSUSP] = (byte) t.getControlChar(Attributes.ControlChar.VSUSP);
250 tio.c_cc[VSTART] = (byte) t.getControlChar(Attributes.ControlChar.VSTART);
251 tio.c_cc[VSTOP] = (byte) t.getControlChar(Attributes.ControlChar.VSTOP);
252 tio.c_cc[VLNEXT] = (byte) t.getControlChar(Attributes.ControlChar.VLNEXT);
253 tio.c_cc[VDISCARD] = (byte) t.getControlChar(Attributes.ControlChar.VDISCARD);
254 tio.c_cc[VMIN] = (byte) t.getControlChar(Attributes.ControlChar.VMIN);
255 tio.c_cc[VTIME] = (byte) t.getControlChar(Attributes.ControlChar.VTIME);
256 // tio.c_cc[VSTATUS] = (byte) t.getControlChar(Attributes.ControlChar.VSTATUS);
257 return tio;
258 }
259
260 protected Attributes toAttributes(CLibrary.Termios tio) {
261 Attributes attr = new Attributes();
262 // Input flags
263 EnumSet<Attributes.InputFlag> iflag = attr.getInputFlags();
264 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNBRK, IGNBRK);
265 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNBRK, IGNBRK);
266 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.BRKINT, BRKINT);
267 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNPAR, IGNPAR);
268 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.PARMRK, PARMRK);
269 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.INPCK, INPCK);
270 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.ISTRIP, ISTRIP);
271 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.INLCR, INLCR);
272 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNCR, IGNCR);
273 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.ICRNL, ICRNL);
274 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXON, IXON);
275 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXOFF, IXOFF);
276 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXANY, IXANY);
277 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IMAXBEL, IMAXBEL);
278 addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IUTF8, IUTF8);
279 // Output flags
280 EnumSet<Attributes.OutputFlag> oflag = attr.getOutputFlags();
281 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OPOST, OPOST);
282 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONLCR, ONLCR);
283 // addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OXTABS, OXTABS);
284 // addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONOEOT, ONOEOT);
285 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OCRNL, OCRNL);
286 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONOCR, ONOCR);
287 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONLRET, ONLRET);
288 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OFILL, OFILL);
289 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.NLDLY, NLDLY);
290 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.TABDLY, TABDLY);
291 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.CRDLY, CRDLY);
292 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.FFDLY, FFDLY);
293 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.BSDLY, BSDLY);
294 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.VTDLY, VTDLY);
295 addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OFDEL, OFDEL);
296 // Control flags
297 EnumSet<Attributes.ControlFlag> cflag = attr.getControlFlags();
298 // addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CIGNORE, CIGNORE);
299 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS5, CS5);
300 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS6, CS6);
301 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS7, CS7);
302 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS8, CS8);
303 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CSTOPB, CSTOPB);
304 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CREAD, CREAD);
305 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.PARENB, PARENB);
306 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.PARODD, PARODD);
307 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.HUPCL, HUPCL);
308 addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CLOCAL, CLOCAL);
309 // addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CCTS_OFLOW, CCTS_OFLOW);
310 // addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CRTS_IFLOW, CRTS_IFLOW);
311 // addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CDSR_OFLOW, CDSR_OFLOW);
312 // addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CCAR_OFLOW, CCAR_OFLOW);
313 // Local flags
314 EnumSet<Attributes.LocalFlag> lflag = attr.getLocalFlags();
315 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOKE, ECHOKE);
316 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOE, ECHOE);
317 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOK, ECHOK);
318 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHO, ECHO);
319 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHONL, ECHONL);
320 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOPRT, ECHOPRT);
321 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOCTL, ECHOCTL);
322 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ISIG, ISIG);
323 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ICANON, ICANON);
324 // addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ALTWERASE, ALTWERASE);
325 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.IEXTEN, IEXTEN);
326 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.EXTPROC, EXTPROC);
327 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.TOSTOP, TOSTOP);
328 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.FLUSHO, FLUSHO);
329 // addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.NOKERNINFO, NOKERNINFO);
330 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.PENDIN, PENDIN);
331 addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.NOFLSH, NOFLSH);
332 // Control chars
333 EnumMap<Attributes.ControlChar, Integer> cc = attr.getControlChars();
334 cc.put(Attributes.ControlChar.VEOF, (int) tio.c_cc[VEOF]);
335 cc.put(Attributes.ControlChar.VEOL, (int) tio.c_cc[VEOL]);
336 cc.put(Attributes.ControlChar.VEOL2, (int) tio.c_cc[VEOL2]);
337 cc.put(Attributes.ControlChar.VERASE, (int) tio.c_cc[VERASE]);
338 cc.put(Attributes.ControlChar.VWERASE, (int) tio.c_cc[VWERASE]);
339 cc.put(Attributes.ControlChar.VKILL, (int) tio.c_cc[VKILL]);
340 cc.put(Attributes.ControlChar.VREPRINT, (int) tio.c_cc[VREPRINT]);
341 cc.put(Attributes.ControlChar.VINTR, (int) tio.c_cc[VINTR]);
342 cc.put(Attributes.ControlChar.VQUIT, (int) tio.c_cc[VQUIT]);
343 cc.put(Attributes.ControlChar.VSUSP, (int) tio.c_cc[VSUSP]);
344 cc.put(Attributes.ControlChar.VSTART, (int) tio.c_cc[VSTART]);
345 cc.put(Attributes.ControlChar.VSTOP, (int) tio.c_cc[VSTOP]);
346 cc.put(Attributes.ControlChar.VLNEXT, (int) tio.c_cc[VLNEXT]);
347 cc.put(Attributes.ControlChar.VDISCARD, (int) tio.c_cc[VDISCARD]);
348 cc.put(Attributes.ControlChar.VMIN, (int) tio.c_cc[VMIN]);
349 cc.put(Attributes.ControlChar.VTIME, (int) tio.c_cc[VTIME]);
350 // cc.put(Attributes.ControlChar.VSTATUS, (int) tio.c_cc[VSTATUS]);
351 // Return
352 return attr;
353 }
354
355 private static long setFlag(boolean flag, long value, long org) {
356 return flag ? org | value : org;
357 }
358
359 private static <T extends Enum<T>> void addFlag(long value, EnumSet<T> flags, T flag, int v) {
360 if ((value & v) != 0) {
361 flags.add(flag);
362 }
363 }
364 }