|
| 1 | +/* |
| 2 | + * Copyright 2023 dorkbox, llc |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package dorkbox.jna.macos.structs; |
| 17 | + |
| 18 | +import java.util.Arrays; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import com.sun.jna.NativeLong; |
| 22 | +import com.sun.jna.Structure; |
| 23 | + |
| 24 | +@SuppressWarnings("ALL") |
| 25 | +public |
| 26 | +class Termios extends Structure { |
| 27 | + |
| 28 | + // Input flags - software input processing |
| 29 | + public static class Input { |
| 30 | + public static final int IGNBRK = 0x00000001; // ignore BREAK condition |
| 31 | + public static final int BRKINT = 0x00000002; // map BREAK to SIGINTR |
| 32 | + public static final int IGNPAR = 0x00000004; // ignore (discard) parity errors |
| 33 | + public static final int PARMRK = 0x00000008; // mark parity and framing errors |
| 34 | + public static final int INPCK = 0x00000010; // enable checking of parity errors |
| 35 | + public static final int ISTRIP = 0x00000020; // strip 8th bit off chars |
| 36 | + public static final int INLCR = 0x00000010; // map NL into CR |
| 37 | + public static final int IGNCR = 0x00000080; // ignore CR |
| 38 | + public static final int ICRNL = 0x00000100; // map CR to NL (ala CRMOD) |
| 39 | + public static final int IXON = 0x00000200; // enable output flow control |
| 40 | + public static final int IXOFF = 0x00000400; // enable input flow control |
| 41 | + public static final int IXANY = 0x00000800; // any char will restart after stop |
| 42 | + public static final int IMAXBEL = 0x00002000; // ring bell on input queue full |
| 43 | + public static final int IUTF8 = 0x00004000; // (since Linux 2.6.4) (not in POSIX) Input is UTF8; this allows character-erase to be correctly performed in cooked mode. |
| 44 | + } |
| 45 | + |
| 46 | + public static class Output { |
| 47 | + // Output flags - software output processing |
| 48 | + public static final int OPOST = 0x00000001; // enable following output processing (not set = raw output) |
| 49 | + public static final int ONLCR = 0x00000002; // map NL to CR-NL (ala CRMOD) |
| 50 | + public static final int OCRNL = 0x00000010; // map CR to NL on output |
| 51 | + public static final int ONOCR = 0x00000020; // no CR output at column 0 |
| 52 | + public static final int ONLRET = 0x00000040; // NL performs CR function |
| 53 | + public static final int OFILL = 0x00000080; // Send fill characters for a delay, rather than using a timed delay. |
| 54 | + public static final int OFDEL = 0x00020000; // Fill character is ASCII DEL (0177). If unset, fill character is ASCII NUL ('\0'). (Not implemented on Linux.) |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public static class Control { |
| 59 | + // Control flags - hardware control of terminal |
| 60 | + public static final int CSIZE = 0000060; // character size mask |
| 61 | + public static final int CS5 = 0x00000000; // 5 bits (pseudo) |
| 62 | + public static final int CS6 = 0x00000100; // 6 bits |
| 63 | + public static final int CS7 = 0x00000200; // 7 bits |
| 64 | + public static final int CS8 = 0x00000300; // 8 bits |
| 65 | + public static final int CSTOPB = 0x00000400; // send 2 stop bits |
| 66 | + public static final int CREAD = 0x00000800; // enable receiver |
| 67 | + public static final int PARENB = 0x00001000; // parity enable |
| 68 | + public static final int PARODD = 0x00002000; // odd parity, else even |
| 69 | + public static final int HUPCL = 0x00004000; // hang up on last close |
| 70 | + public static final int CLOCAL = 0x00008000; // ignore modem status lines |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + public static class Local { |
| 75 | + // "Local" flags - dumping ground for other state |
| 76 | + // Warning: some flags in this structure begin with the letter "I" and look like they belong in the input flag. |
| 77 | + public static final int ECHOKE = 0x00000001; // visual erase for line kill |
| 78 | + public static final int ECHOE = 0x00000002; // visually erase chars |
| 79 | + public static final int ECHOK = 0x00000004; // echo NL after line kill |
| 80 | + public static final int ECHO = 0x00000008; // enable echoing |
| 81 | + public static final int ECHONL = 0x00000010; // echo NL even if ECHO is off |
| 82 | + public static final int ECHOPRT = 0x00000020; // visual erase mode for hardcopy |
| 83 | + public static final int ECHOCTL = 0x00000040; // echo control chars as ^(Char) |
| 84 | + public static final int ISIG = 0x00000080; // enable signals INTR, QUIT, [D]SUSP |
| 85 | + public static final int ICANON = 0x00000100; // canonicalize input lines |
| 86 | + public static final int IEXTEN = 0x00000400; // enable DISCARD and LNEXT |
| 87 | + public static final int EXTPROC = 0x00000800; // external processing |
| 88 | + public static final int TOSTOP = 0x00400000; // stop background jobs from output |
| 89 | + public static final int FLUSHO = 0x00800000; // output being flushed (state) |
| 90 | + public static final int PENDIN = 0x20000000; // XXX retype pending input (state) |
| 91 | + public static final int NOFLSH = 0x80000000; // don't flush after interrupt |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + public static class ControlChars { |
| 96 | + // Special Control Characters |
| 97 | + // |
| 98 | + // the value is the index into c_cc[] character array. |
| 99 | + public static final int VEOF = 0; |
| 100 | + public static final int VEOL = 1; |
| 101 | + public static final int VEOL2 = 2; |
| 102 | + public static final int VERASE = 3; |
| 103 | + public static final int VWERASE = 4; |
| 104 | + public static final int VKILL = 5; |
| 105 | + public static final int VREPRINT = 6; |
| 106 | + public static final int VINTR = 8; |
| 107 | + public static final int VQUIT = 9; |
| 108 | + public static final int VSUSP = 10; |
| 109 | + public static final int VDSUSP = 11; |
| 110 | + public static final int VSTART = 12; |
| 111 | + public static final int VSTOP = 13; |
| 112 | + public static final int VLNEXT = 14; |
| 113 | + public static final int VDISCARD = 15; |
| 114 | + public static final int VMIN = 16; |
| 115 | + public static final int VTIME = 17; |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + public static void and(NativeLong org, int value) { |
| 120 | + org.setValue(org.longValue() & value); |
| 121 | + } |
| 122 | + |
| 123 | + public static void and(NativeLong org, long value) { |
| 124 | + org.setValue(org.longValue() & value); |
| 125 | + } |
| 126 | + |
| 127 | + public static void or(NativeLong org, long value) { |
| 128 | + org.setValue(org.longValue() | value); |
| 129 | + } |
| 130 | + |
| 131 | + public static void or(NativeLong org, int value) { |
| 132 | + org.setValue(org.longValue() | value); |
| 133 | + } |
| 134 | + |
| 135 | + |
| 136 | + public static final long TCSANOW = 0x00000000; |
| 137 | + |
| 138 | + /** |
| 139 | + * input mode flags |
| 140 | + */ |
| 141 | + public NativeLong inputFlags; |
| 142 | + |
| 143 | + /** |
| 144 | + * output mode flags |
| 145 | + */ |
| 146 | + public NativeLong outputFlags; |
| 147 | + |
| 148 | + /** |
| 149 | + * control mode flags |
| 150 | + */ |
| 151 | + public NativeLong controlFlags; |
| 152 | + |
| 153 | + /** |
| 154 | + * local mode flags |
| 155 | + */ |
| 156 | + public NativeLong localFlags; |
| 157 | + |
| 158 | + /** |
| 159 | + * control characters |
| 160 | + */ |
| 161 | + public byte[] controlChars = new byte[20]; |
| 162 | + |
| 163 | + /** |
| 164 | + * input speed |
| 165 | + */ |
| 166 | + public NativeLong inputSpeed; |
| 167 | + |
| 168 | + /** |
| 169 | + * output speed |
| 170 | + */ |
| 171 | + public NativeLong outputSpeed; |
| 172 | + |
| 173 | + public |
| 174 | + Termios() {} |
| 175 | + |
| 176 | + @Override |
| 177 | + protected |
| 178 | + List<String> getFieldOrder() { |
| 179 | + return Arrays.asList("inputFlags", |
| 180 | + "outputFlags", |
| 181 | + "controlFlags", |
| 182 | + "localFlags", |
| 183 | + "controlChars", |
| 184 | + "inputSpeed", |
| 185 | + "outputSpeed"); |
| 186 | + } |
| 187 | +} |
0 commit comments