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