Debian Codegraph @

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