| 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.osx; |
| 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 |
|
| 16 |
import java.io.FileDescriptor; |
| 17 |
import java.io.IOException; |
| 18 |
import java.util.EnumMap; |
| 19 |
import java.util.EnumSet; |
| 20 |
|
| 21 |
public class OsXNativePty extends JansiNativePty { |
| 22 |
|
| 23 |
public static OsXNativePty current() throws IOException { |
| 24 |
try { |
| 25 |
String name = ttyname(); |
| 26 |
return new OsXNativePty(-1, null, 0, FileDescriptor.in, name); |
| 27 |
} catch (IOException e) { |
| 28 |
throw new IOException("Not a tty", e); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
public static OsXNativePty open(Attributes attr, Size size) throws IOException { |
| 33 |
int[] master = new int[1]; |
| 34 |
int[] slave = new int[1]; |
| 35 |
byte[] buf = new byte[64]; |
| 36 |
CLibrary.openpty(master, slave, buf, |
| 37 |
attr != null ? termios(attr) : null, |
| 38 |
size != null ? new CLibrary.WinSize((short) size.getRows(), (short) size.getColumns()) : null); |
| 39 |
int len = 0; |
| 40 |
while (buf[len] != 0) { |
| 41 |
len++; |
| 42 |
} |
| 43 |
String name = new String(buf, 0, len); |
| 44 |
return new OsXNativePty(master[0], newDescriptor(master[0]), slave[0], newDescriptor(slave[0]), name); |
| 45 |
} |
| 46 |
|
| 47 |
public OsXNativePty(int master, FileDescriptor masterFD, int slave, FileDescriptor slaveFD, String name) { |
| 48 |
super(master, masterFD, slave, slaveFD, name); |
| 49 |
} |
| 50 |
|
| 51 |
// CONSTANTS |
| 52 |
|
| 53 |
private static final int VEOF = 0; |
| 54 |
private static final int VEOL = 1; |
| 55 |
private static final int VEOL2 = 2; |
| 56 |
private static final int VERASE = 3; |
| 57 |
private static final int VWERASE = 4; |
| 58 |
private static final int VKILL = 5; |
| 59 |
private static final int VREPRINT = 6; |
| 60 |
private static final int VINTR = 8; |
| 61 |
private static final int VQUIT = 9; |
| 62 |
private static final int VSUSP = 10; |
| 63 |
private static final int VDSUSP = 11; |
| 64 |
private static final int VSTART = 12; |
| 65 |
private static final int VSTOP = 13; |
| 66 |
private static final int VLNEXT = 14; |
| 67 |
private static final int VDISCARD = 15; |
| 68 |
private static final int VMIN = 16; |
| 69 |
private static final int VTIME = 17; |
| 70 |
private static final int VSTATUS = 18; |
| 71 |
|
| 72 |
private static final int IGNBRK = 0x00000001; |
| 73 |
private static final int BRKINT = 0x00000002; |
| 74 |
private static final int IGNPAR = 0x00000004; |
| 75 |
private static final int PARMRK = 0x00000008; |
| 76 |
private static final int INPCK = 0x00000010; |
| 77 |
private static final int ISTRIP = 0x00000020; |
| 78 |
private static final int INLCR = 0x00000040; |
| 79 |
private static final int IGNCR = 0x00000080; |
| 80 |
private static final int ICRNL = 0x00000100; |
| 81 |
private static final int IXON = 0x00000200; |
| 82 |
private static final int IXOFF = 0x00000400; |
| 83 |
private static final int IXANY = 0x00000800; |
| 84 |
private static final int IMAXBEL = 0x00002000; |
| 85 |
private static final int IUTF8 = 0x00004000; |
| 86 |
|
| 87 |
private static final int OPOST = 0x00000001; |
| 88 |
private static final int ONLCR = 0x00000002; |
| 89 |
private static final int OXTABS = 0x00000004; |
| 90 |
private static final int ONOEOT = 0x00000008; |
| 91 |
private static final int OCRNL = 0x00000010; |
| 92 |
private static final int ONOCR = 0x00000020; |
| 93 |
private static final int ONLRET = 0x00000040; |
| 94 |
private static final int OFILL = 0x00000080; |
| 95 |
private static final int NLDLY = 0x00000300; |
| 96 |
private static final int TABDLY = 0x00000c04; |
| 97 |
private static final int CRDLY = 0x00003000; |
| 98 |
private static final int FFDLY = 0x00004000; |
| 99 |
private static final int BSDLY = 0x00008000; |
| 100 |
private static final int VTDLY = 0x00010000; |
| 101 |
private static final int OFDEL = 0x00020000; |
| 102 |
|
| 103 |
private static final int CIGNORE = 0x00000001; |
| 104 |
private static final int CS5 = 0x00000000; |
| 105 |
private static final int CS6 = 0x00000100; |
| 106 |
private static final int CS7 = 0x00000200; |
| 107 |
private static final int CS8 = 0x00000300; |
| 108 |
private static final int CSTOPB = 0x00000400; |
| 109 |
private static final int CREAD = 0x00000800; |
| 110 |
private static final int PARENB = 0x00001000; |
| 111 |
private static final int PARODD = 0x00002000; |
| 112 |
private static final int HUPCL = 0x00004000; |
| 113 |
private static final int CLOCAL = 0x00008000; |
| 114 |
private static final int CCTS_OFLOW = 0x00010000; |
| 115 |
private static final int CRTS_IFLOW = 0x00020000; |
| 116 |
private static final int CDTR_IFLOW = 0x00040000; |
| 117 |
private static final int CDSR_OFLOW = 0x00080000; |
| 118 |
private static final int CCAR_OFLOW = 0x00100000; |
| 119 |
|
| 120 |
private static final int ECHOKE = 0x00000001; |
| 121 |
private static final int ECHOE = 0x00000002; |
| 122 |
private static final int ECHOK = 0x00000004; |
| 123 |
private static final int ECHO = 0x00000008; |
| 124 |
private static final int ECHONL = 0x00000010; |
| 125 |
private static final int ECHOPRT = 0x00000020; |
| 126 |
private static final int ECHOCTL = 0x00000040; |
| 127 |
private static final int ISIG = 0x00000080; |
| 128 |
private static final int ICANON = 0x00000100; |
| 129 |
private static final int ALTWERASE = 0x00000200; |
| 130 |
private static final int IEXTEN = 0x00000400; |
| 131 |
private static final int EXTPROC = 0x00000800; |
| 132 |
private static final int TOSTOP = 0x00400000; |
| 133 |
private static final int FLUSHO = 0x00800000; |
| 134 |
private static final int NOKERNINFO = 0x02000000; |
| 135 |
private static final int PENDIN = 0x20000000; |
| 136 |
private static final int NOFLSH = 0x80000000; |
| 137 |
|
| 138 |
protected CLibrary.Termios toTermios(Attributes t) { |
| 139 |
return termios(t); |
| 140 |
} |
| 141 |
|
| 142 |
static CLibrary.Termios termios(Attributes t) { |
| 143 |
CLibrary.Termios tio = new CLibrary.Termios(); |
| 144 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNBRK), IGNBRK, tio.c_iflag); |
| 145 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.BRKINT), BRKINT, tio.c_iflag); |
| 146 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNPAR), IGNPAR, tio.c_iflag); |
| 147 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.PARMRK), PARMRK, tio.c_iflag); |
| 148 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.INPCK), INPCK, tio.c_iflag); |
| 149 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.ISTRIP), ISTRIP, tio.c_iflag); |
| 150 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.INLCR), INLCR, tio.c_iflag); |
| 151 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IGNCR), IGNCR, tio.c_iflag); |
| 152 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.ICRNL), ICRNL, tio.c_iflag); |
| 153 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXON), IXON, tio.c_iflag); |
| 154 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXOFF), IXOFF, tio.c_iflag); |
| 155 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IXANY), IXANY, tio.c_iflag); |
| 156 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IMAXBEL), IMAXBEL, tio.c_iflag); |
| 157 |
tio.c_iflag = setFlag(t.getInputFlag(Attributes.InputFlag.IUTF8), IUTF8, tio.c_iflag); |
| 158 |
// Output flags |
| 159 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OPOST), OPOST, tio.c_oflag); |
| 160 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONLCR), ONLCR, tio.c_oflag); |
| 161 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OXTABS), OXTABS, tio.c_oflag); |
| 162 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONOEOT), ONOEOT, tio.c_oflag); |
| 163 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OCRNL), OCRNL, tio.c_oflag); |
| 164 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONOCR), ONOCR, tio.c_oflag); |
| 165 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.ONLRET), ONLRET, tio.c_oflag); |
| 166 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OFILL), OFILL, tio.c_oflag); |
| 167 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.NLDLY), NLDLY, tio.c_oflag); |
| 168 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.TABDLY), TABDLY, tio.c_oflag); |
| 169 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.CRDLY), CRDLY, tio.c_oflag); |
| 170 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.FFDLY), FFDLY, tio.c_oflag); |
| 171 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.BSDLY), BSDLY, tio.c_oflag); |
| 172 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.VTDLY), VTDLY, tio.c_oflag); |
| 173 |
tio.c_oflag = setFlag(t.getOutputFlag(Attributes.OutputFlag.OFDEL), OFDEL, tio.c_oflag); |
| 174 |
// Control flags |
| 175 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CIGNORE), CIGNORE, tio.c_cflag); |
| 176 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS5), CS5, tio.c_cflag); |
| 177 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS6), CS6, tio.c_cflag); |
| 178 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS7), CS7, tio.c_cflag); |
| 179 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CS8), CS8, tio.c_cflag); |
| 180 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CSTOPB), CSTOPB, tio.c_cflag); |
| 181 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CREAD), CREAD, tio.c_cflag); |
| 182 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.PARENB), PARENB, tio.c_cflag); |
| 183 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.PARODD), PARODD, tio.c_cflag); |
| 184 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.HUPCL), HUPCL, tio.c_cflag); |
| 185 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CLOCAL), CLOCAL, tio.c_cflag); |
| 186 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CCTS_OFLOW), CCTS_OFLOW, tio.c_cflag); |
| 187 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CRTS_IFLOW), CRTS_IFLOW, tio.c_cflag); |
| 188 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CDTR_IFLOW), CDTR_IFLOW, tio.c_cflag); |
| 189 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CDSR_OFLOW), CDSR_OFLOW, tio.c_cflag); |
| 190 |
tio.c_cflag = setFlag(t.getControlFlag(Attributes.ControlFlag.CCAR_OFLOW), CCAR_OFLOW, tio.c_cflag); |
| 191 |
// Local flags |
| 192 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOKE), ECHOKE, tio.c_lflag); |
| 193 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOE), ECHOE, tio.c_lflag); |
| 194 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOK), ECHOK, tio.c_lflag); |
| 195 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHO), ECHO, tio.c_lflag); |
| 196 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHONL), ECHONL, tio.c_lflag); |
| 197 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOPRT), ECHOPRT, tio.c_lflag); |
| 198 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ECHOCTL), ECHOCTL, tio.c_lflag); |
| 199 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ISIG), ISIG, tio.c_lflag); |
| 200 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ICANON), ICANON, tio.c_lflag); |
| 201 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.ALTWERASE), ALTWERASE, tio.c_lflag); |
| 202 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.IEXTEN), IEXTEN, tio.c_lflag); |
| 203 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.EXTPROC), EXTPROC, tio.c_lflag); |
| 204 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.TOSTOP), TOSTOP, tio.c_lflag); |
| 205 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.FLUSHO), FLUSHO, tio.c_lflag); |
| 206 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.NOKERNINFO), NOKERNINFO, tio.c_lflag); |
| 207 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.PENDIN), PENDIN, tio.c_lflag); |
| 208 |
tio.c_lflag = setFlag(t.getLocalFlag(Attributes.LocalFlag.NOFLSH), NOFLSH, tio.c_lflag); |
| 209 |
// Control chars |
| 210 |
tio.c_cc[VEOF] = (byte) t.getControlChar(Attributes.ControlChar.VEOF); |
| 211 |
tio.c_cc[VEOL] = (byte) t.getControlChar(Attributes.ControlChar.VEOL); |
| 212 |
tio.c_cc[VEOL2] = (byte) t.getControlChar(Attributes.ControlChar.VEOL2); |
| 213 |
tio.c_cc[VERASE] = (byte) t.getControlChar(Attributes.ControlChar.VERASE); |
| 214 |
tio.c_cc[VWERASE] = (byte) t.getControlChar(Attributes.ControlChar.VWERASE); |
| 215 |
tio.c_cc[VKILL] = (byte) t.getControlChar(Attributes.ControlChar.VKILL); |
| 216 |
tio.c_cc[VREPRINT] = (byte) t.getControlChar(Attributes.ControlChar.VREPRINT); |
| 217 |
tio.c_cc[VINTR] = (byte) t.getControlChar(Attributes.ControlChar.VINTR); |
| 218 |
tio.c_cc[VQUIT] = (byte) t.getControlChar(Attributes.ControlChar.VQUIT); |
| 219 |
tio.c_cc[VSUSP] = (byte) t.getControlChar(Attributes.ControlChar.VSUSP); |
| 220 |
tio.c_cc[VDSUSP] = (byte) t.getControlChar(Attributes.ControlChar.VDSUSP); |
| 221 |
tio.c_cc[VSTART] = (byte) t.getControlChar(Attributes.ControlChar.VSTART); |
| 222 |
tio.c_cc[VSTOP] = (byte) t.getControlChar(Attributes.ControlChar.VSTOP); |
| 223 |
tio.c_cc[VLNEXT] = (byte) t.getControlChar(Attributes.ControlChar.VLNEXT); |
| 224 |
tio.c_cc[VDISCARD] = (byte) t.getControlChar(Attributes.ControlChar.VDISCARD); |
| 225 |
tio.c_cc[VMIN] = (byte) t.getControlChar(Attributes.ControlChar.VMIN); |
| 226 |
tio.c_cc[VTIME] = (byte) t.getControlChar(Attributes.ControlChar.VTIME); |
| 227 |
tio.c_cc[VSTATUS] = (byte) t.getControlChar(Attributes.ControlChar.VSTATUS); |
| 228 |
return tio; |
| 229 |
} |
| 230 |
|
| 231 |
protected Attributes toAttributes(CLibrary.Termios tio) { |
| 232 |
Attributes attr = new Attributes(); |
| 233 |
// Input flags |
| 234 |
EnumSet<Attributes.InputFlag> iflag = attr.getInputFlags(); |
| 235 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNBRK, IGNBRK); |
| 236 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNBRK, IGNBRK); |
| 237 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.BRKINT, BRKINT); |
| 238 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNPAR, IGNPAR); |
| 239 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.PARMRK, PARMRK); |
| 240 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.INPCK, INPCK); |
| 241 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.ISTRIP, ISTRIP); |
| 242 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.INLCR, INLCR); |
| 243 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IGNCR, IGNCR); |
| 244 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.ICRNL, ICRNL); |
| 245 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXON, IXON); |
| 246 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXOFF, IXOFF); |
| 247 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IXANY, IXANY); |
| 248 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IMAXBEL, IMAXBEL); |
| 249 |
addFlag(tio.c_iflag, iflag, Attributes.InputFlag.IUTF8, IUTF8); |
| 250 |
// Output flags |
| 251 |
EnumSet<Attributes.OutputFlag> oflag = attr.getOutputFlags(); |
| 252 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OPOST, OPOST); |
| 253 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONLCR, ONLCR); |
| 254 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OXTABS, OXTABS); |
| 255 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONOEOT, ONOEOT); |
| 256 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OCRNL, OCRNL); |
| 257 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONOCR, ONOCR); |
| 258 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.ONLRET, ONLRET); |
| 259 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OFILL, OFILL); |
| 260 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.NLDLY, NLDLY); |
| 261 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.TABDLY, TABDLY); |
| 262 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.CRDLY, CRDLY); |
| 263 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.FFDLY, FFDLY); |
| 264 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.BSDLY, BSDLY); |
| 265 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.VTDLY, VTDLY); |
| 266 |
addFlag(tio.c_oflag, oflag, Attributes.OutputFlag.OFDEL, OFDEL); |
| 267 |
// Control flags |
| 268 |
EnumSet<Attributes.ControlFlag> cflag = attr.getControlFlags(); |
| 269 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CIGNORE, CIGNORE); |
| 270 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS5, CS5); |
| 271 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS6, CS6); |
| 272 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS7, CS7); |
| 273 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CS8, CS8); |
| 274 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CSTOPB, CSTOPB); |
| 275 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CREAD, CREAD); |
| 276 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.PARENB, PARENB); |
| 277 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.PARODD, PARODD); |
| 278 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.HUPCL, HUPCL); |
| 279 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CLOCAL, CLOCAL); |
| 280 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CCTS_OFLOW, CCTS_OFLOW); |
| 281 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CRTS_IFLOW, CRTS_IFLOW); |
| 282 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CDSR_OFLOW, CDSR_OFLOW); |
| 283 |
addFlag(tio.c_cflag, cflag, Attributes.ControlFlag.CCAR_OFLOW, CCAR_OFLOW); |
| 284 |
// Local flags |
| 285 |
EnumSet<Attributes.LocalFlag> lflag = attr.getLocalFlags(); |
| 286 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOKE, ECHOKE); |
| 287 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOE, ECHOE); |
| 288 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOK, ECHOK); |
| 289 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHO, ECHO); |
| 290 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHONL, ECHONL); |
| 291 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOPRT, ECHOPRT); |
| 292 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ECHOCTL, ECHOCTL); |
| 293 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ISIG, ISIG); |
| 294 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ICANON, ICANON); |
| 295 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.ALTWERASE, ALTWERASE); |
| 296 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.IEXTEN, IEXTEN); |
| 297 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.EXTPROC, EXTPROC); |
| 298 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.TOSTOP, TOSTOP); |
| 299 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.FLUSHO, FLUSHO); |
| 300 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.NOKERNINFO, NOKERNINFO); |
| 301 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.PENDIN, PENDIN); |
| 302 |
addFlag(tio.c_lflag, lflag, Attributes.LocalFlag.NOFLSH, NOFLSH); |
| 303 |
// Control chars |
| 304 |
EnumMap<Attributes.ControlChar, Integer> cc = attr.getControlChars(); |
| 305 |
cc.put(Attributes.ControlChar.VEOF, (int) tio.c_cc[VEOF]); |
| 306 |
cc.put(Attributes.ControlChar.VEOL, (int) tio.c_cc[VEOL]); |
| 307 |
cc.put(Attributes.ControlChar.VEOL2, (int) tio.c_cc[VEOL2]); |
| 308 |
cc.put(Attributes.ControlChar.VERASE, (int) tio.c_cc[VERASE]); |
| 309 |
cc.put(Attributes.ControlChar.VWERASE, (int) tio.c_cc[VWERASE]); |
| 310 |
cc.put(Attributes.ControlChar.VKILL, (int) tio.c_cc[VKILL]); |
| 311 |
cc.put(Attributes.ControlChar.VREPRINT, (int) tio.c_cc[VREPRINT]); |
| 312 |
cc.put(Attributes.ControlChar.VINTR, (int) tio.c_cc[VINTR]); |
| 313 |
cc.put(Attributes.ControlChar.VQUIT, (int) tio.c_cc[VQUIT]); |
| 314 |
cc.put(Attributes.ControlChar.VSUSP, (int) tio.c_cc[VSUSP]); |
| 315 |
cc.put(Attributes.ControlChar.VDSUSP, (int) tio.c_cc[VDSUSP]); |
| 316 |
cc.put(Attributes.ControlChar.VSTART, (int) tio.c_cc[VSTART]); |
| 317 |
cc.put(Attributes.ControlChar.VSTOP, (int) tio.c_cc[VSTOP]); |
| 318 |
cc.put(Attributes.ControlChar.VLNEXT, (int) tio.c_cc[VLNEXT]); |
| 319 |
cc.put(Attributes.ControlChar.VDISCARD, (int) tio.c_cc[VDISCARD]); |
| 320 |
cc.put(Attributes.ControlChar.VMIN, (int) tio.c_cc[VMIN]); |
| 321 |
cc.put(Attributes.ControlChar.VTIME, (int) tio.c_cc[VTIME]); |
| 322 |
cc.put(Attributes.ControlChar.VSTATUS, (int) tio.c_cc[VSTATUS]); |
| 323 |
// Return |
| 324 |
return attr; |
| 325 |
} |
| 326 |
|
| 327 |
private static long setFlag(boolean flag, long value, long org) { |
| 328 |
return flag ? org | value : org; |
| 329 |
} |
| 330 |
|
| 331 |
private static <T extends Enum<T>> void addFlag(long value, EnumSet<T> flags, T flag, int v) { |
| 332 |
if ((value & v) != 0) { |
| 333 |
flags.add(flag); |
| 334 |
} |
| 335 |
} |
| 336 |
} |