Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions eng/scripts/generate_os_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ def generate_codes(cw, codeval, access, fmt, unix_only=False):

value = windows_code_expr(codes, fmt)
typ = "int"
if (all(c.isdigit() for c in value) or re.match(r'^0x[0-9a-fA-F]+$', value)):
n = eval(value)
for match in re.findall(r'0x[0-9a-fA-F]+', value):
n = eval(match)
if n > 2**31 - 1 or n < -2**31:
typ = "long"
break
cw.write(f"{access} static {typ} {name} => {value};")


Expand Down Expand Up @@ -286,6 +287,23 @@ def generate_LOCK_flags(cw):
generate_codes(cw, codeval, 'public', hex, unix_only=True)


# python3 -c 'import termios;print(dict(sorted((s, getattr(termios, s)) for s in dir(termios) if s.startswith("TIOC"))))'
# Python 3.6.15 [GCC 12.2.0] on linux 6.10.14
# Python 3.12.3 [GCC 13.2.0] on linux 6.8.0
TIOC_cmd_linux = {'TIOCCONS': 21533, 'TIOCEXCL': 21516, 'TIOCGETD': 21540, 'TIOCGICOUNT': 21597, 'TIOCGLCKTRMIOS': 21590, 'TIOCGPGRP': 21519, 'TIOCGSERIAL': 21534, 'TIOCGSOFTCAR': 21529, 'TIOCGWINSZ': 21523, 'TIOCINQ': 21531, 'TIOCLINUX': 21532, 'TIOCMBIC': 21527, 'TIOCMBIS': 21526, 'TIOCMGET': 21525, 'TIOCMIWAIT': 21596, 'TIOCMSET': 21528, 'TIOCM_CAR': 64, 'TIOCM_CD': 64, 'TIOCM_CTS': 32, 'TIOCM_DSR': 256, 'TIOCM_DTR': 2, 'TIOCM_LE': 1, 'TIOCM_RI': 128, 'TIOCM_RNG': 128, 'TIOCM_RTS': 4, 'TIOCM_SR': 16, 'TIOCM_ST': 8, 'TIOCNOTTY': 21538, 'TIOCNXCL': 21517, 'TIOCOUTQ': 21521, 'TIOCPKT': 21536, 'TIOCPKT_DATA': 0, 'TIOCPKT_DOSTOP': 32, 'TIOCPKT_FLUSHREAD': 1, 'TIOCPKT_FLUSHWRITE': 2, 'TIOCPKT_NOSTOP': 16, 'TIOCPKT_START': 8, 'TIOCPKT_STOP': 4, 'TIOCSCTTY': 21518, 'TIOCSERCONFIG': 21587, 'TIOCSERGETLSR': 21593, 'TIOCSERGETMULTI': 21594, 'TIOCSERGSTRUCT': 21592, 'TIOCSERGWILD': 21588, 'TIOCSERSETMULTI': 21595, 'TIOCSERSWILD': 21589, 'TIOCSER_TEMT': 1, 'TIOCSETD': 21539, 'TIOCSLCKTRMIOS': 21591, 'TIOCSPGRP': 21520, 'TIOCSSERIAL': 21535, 'TIOCSSOFTCAR': 21530, 'TIOCSTI': 21522, 'TIOCSWINSZ': 21524}
# Python 3.12.0 [Clang 14.0.6 ] on darwin 24.2.0
TIOC_cmd_darwin = {'TIOCCONS': 2147775586, 'TIOCEXCL': 536900621, 'TIOCGETD': 1074033690, 'TIOCGPGRP': 1074033783, 'TIOCGSIZE': 1074295912, 'TIOCGWINSZ': 1074295912, 'TIOCMBIC': 2147775595, 'TIOCMBIS': 2147775596, 'TIOCMGET': 1074033770, 'TIOCMSET': 2147775597, 'TIOCM_CAR': 64, 'TIOCM_CD': 64, 'TIOCM_CTS': 32, 'TIOCM_DSR': 256, 'TIOCM_DTR': 2, 'TIOCM_LE': 1, 'TIOCM_RI': 128, 'TIOCM_RNG': 128, 'TIOCM_RTS': 4, 'TIOCM_SR': 16, 'TIOCM_ST': 8, 'TIOCNOTTY': 536900721, 'TIOCNXCL': 536900622, 'TIOCOUTQ': 1074033779, 'TIOCPKT': 2147775600, 'TIOCPKT_DATA': 0, 'TIOCPKT_DOSTOP': 32, 'TIOCPKT_FLUSHREAD': 1, 'TIOCPKT_FLUSHWRITE': 2, 'TIOCPKT_NOSTOP': 16, 'TIOCPKT_START': 8, 'TIOCPKT_STOP': 4, 'TIOCSCTTY': 536900705, 'TIOCSETD': 2147775515, 'TIOCSPGRP': 2147775606, 'TIOCSSIZE': 2148037735, 'TIOCSTI': 2147578994, 'TIOCSWINSZ': 2148037735}

def generate_TIOC_commands(cw):
codeval = {}
for name in TIOC_cmd_linux:
set_value(codeval, name, TIOC_cmd_linux[name], linux_idx)
for name in TIOC_cmd_darwin:
set_value(codeval, name, TIOC_cmd_darwin[name], darwin_idx)
codeval = OrderedDict(sorted(codeval.items()))
generate_codes(cw, codeval, 'public', hex, unix_only=True)


def main():
return generate(
("Errno Codes", generate_errno_codes),
Expand All @@ -296,6 +314,7 @@ def main():
("FD Commands", generate_FD_commands),
("Directory Notify Flags", generate_DN_flags),
("LOCK Flags", generate_LOCK_flags),
("TIOC Commands", generate_TIOC_commands),
)

if __name__ == "__main__":
Expand Down
157 changes: 156 additions & 1 deletion src/core/IronPython.Modules/termios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,165 @@ public static void PerformModuleReload(PythonContext context, PythonDictionary d
#pragma warning restore IPY01 // Parameter which is marked not nullable does not have the NotNullAttribute


#region termios IO Control Codes (TIOC*)
#region Generated TIOC Commands

// *** BEGIN GENERATED CODE ***
// generated by function: generate_TIOC_commands from: generate_os_codes.py


public static long TIOCCONS => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x80047462 : 0x541d;

public static int TIOCEXCL => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x2000740d : 0x540c;

public static int TIOCGETD => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x4004741a : 0x5424;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCGICOUNT => 0x545d;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCGLCKTRMIOS => 0x5456;

public static int TIOCGPGRP => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x40047477 : 0x540f;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCGSERIAL => 0x541e;

[PythonHidden(PlatformID.Unix)]
[SupportedOSPlatform("macos")]
public static int TIOCGSIZE => 0x40087468;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCGSOFTCAR => 0x5419;

public static int TIOCGWINSZ => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x40087468 : 0x5413;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCINQ => 0x541b;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCLINUX => 0x541c;

public static long TIOCMBIC => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x8004746b : 0x5417;

public static long TIOCMBIS => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x8004746c : 0x5416;

public static int TIOCMGET => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x4004746a : 0x5415;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCMIWAIT => 0x545c;

public static long TIOCMSET => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x8004746d : 0x5418;

public static int TIOCM_CAR => 0x40;

public static int TIOCM_CD => 0x40;

public static int TIOCM_CTS => 0x20;

public static int TIOCM_DSR => 0x100;

public static int TIOCM_DTR => 0x2;

public static int TIOCM_LE => 0x1;

public static int TIOCM_RI => 0x80;

public static int TIOCM_RNG => 0x80;

public static int TIOCM_RTS => 0x4;

public static int TIOCM_SR => 0x10;

public static int TIOCM_ST => 0x8;

public static int TIOCNOTTY => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x20007471 : 0x5422;

public static int TIOCNXCL => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x2000740e : 0x540d;

public static int TIOCOUTQ => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x40047473 : 0x5411;

public static long TIOCPKT => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x80047470 : 0x5420;

public static int TIOCPKT_DATA => 0x0;

public static int TIOCPKT_DOSTOP => 0x20;

public static int TIOCPKT_FLUSHREAD => 0x1;

public static int TIOCPKT_FLUSHWRITE => 0x2;

public static int TIOCPKT_NOSTOP => 0x10;

public static int TIOCPKT_START => 0x8;

public static int TIOCPKT_STOP => 0x4;

public static int TIOCSCTTY => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x20007461 : 0x540e;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERCONFIG => 0x5453;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERGETLSR => 0x5459;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERGETMULTI => 0x545a;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERGSTRUCT => 0x5458;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERGWILD => 0x5454;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERSETMULTI => 0x545b;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSERSWILD => 0x5455;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSER_TEMT => 0x1;

public static long TIOCSETD => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x8004741b : 0x5423;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSLCKTRMIOS => 0x5457;

public static long TIOCSPGRP => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x80047476 : 0x5410;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSSERIAL => 0x541f;

[PythonHidden(PlatformID.Unix)]
[SupportedOSPlatform("macos")]
public static long TIOCSSIZE => 0x80087467;

[PythonHidden(PlatformID.MacOSX)]
[SupportedOSPlatform("linux")]
public static int TIOCSSOFTCAR => 0x541a;

public static long TIOCSTI => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x80017472 : 0x5412;

public static long TIOCSWINSZ => RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 0x80087467 : 0x5414;

// *** END GENERATED CODE ***

#endregion

Expand Down