# # # Nim's Runtime Library # (c) Copyright 2015 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # import posix type Speed* = cuint Cflag* = cuint const NCCS* = when defined(macosx): 20 else: 32 when defined(linux) and defined(amd64): type Termios* {.importc: "struct termios", header: "".} = object c_iflag*: Cflag # input mode flags c_oflag*: Cflag # output mode flags c_cflag*: Cflag # control mode flags c_lflag*: Cflag # local mode flags c_line*: cuchar c_cc*: array[NCCS, cuchar] # control characters c_ispeed*: Speed c_ospeed*: Speed else: type Termios* {.importc: "struct termios", header: "".} = object c_iflag*: Cflag # input mode flags c_oflag*: Cflag # output mode flags c_cflag*: Cflag # control mode flags c_lflag*: Cflag # local mode flags c_cc*: array[NCCS, cuchar] # control characters # cc characters var VINTR* {.importc, header: "".}: cint VQUIT* {.importc, header: "".}: cint VERASE* {.importc, header: "".}: cint VKILL* {.importc, header: "".}: cint VEOF* {.importc, header: "".}: cint VTIME* {.importc, header: "".}: cint VMIN* {.importc, header: "".}: cint VSTART* {.importc, header: "".}: cint VSTOP* {.importc, header: "".}: cint VSUSP* {.importc, header: "".}: cint VEOL* {.importc, header: "".}: cint # iflag bits var IGNBRK* {.importc, header: "".}: Cflag BRKINT* {.importc, header: "".}: Cflag IGNPAR* {.importc, header: "".}: Cflag PARMRK* {.importc, header: "".}: Cflag INPCK* {.importc, header: "".}: Cflag ISTRIP* {.importc, header: "".}: Cflag INLCR* {.importc, header: "".}: Cflag IGNCR* {.importc, header: "".}: Cflag ICRNL* {.importc, header: "".}: Cflag IUCLC* {.importc, header: "".}: Cflag IXON* {.importc, header: "".}: Cflag IXANY* {.importc, header: "".}: Cflag IXOFF* {.importc, header: "".}: Cflag # oflag bits var OPOST* {.importc, header: "".}: Cflag ONLCR* {.importc, header: "".}: Cflag OCRNL* {.importc, header: "".}: Cflag ONOCR* {.importc, header: "".}: Cflag ONLRET* {.importc, header: "".}: Cflag OFILL* {.importc, header: "".}: Cflag OFDEL* {.importc, header: "".}: Cflag NLDLY* {.importc, header: "".}: Cflag NL0* {.importc, header: "".}: Cflag NL1* {.importc, header: "".}: Cflag CRDLY* {.importc, header: "".}: Cflag CR0* {.importc, header: "".}: Cflag CR1* {.importc, header: "".}: Cflag CR2* {.importc, header: "".}: Cflag CR3* {.importc, header: "".}: Cflag TABDLY* {.importc, header: "".}: Cflag TAB0* {.importc, header: "".}: Cflag TAB1* {.importc, header: "".}: Cflag TAB2* {.importc, header: "".}: Cflag TAB3* {.importc, header: "".}: Cflag BSDLY* {.importc, header: "".}: Cflag BS0* {.importc, header: "".}: Cflag BS1* {.importc, header: "".}: Cflag FFDLY* {.importc, header: "".}: Cflag FF0* {.importc, header: "".}: Cflag FF1* {.importc, header: "".}: Cflag VTDLY* {.importc, header: "".}: Cflag VT0* {.importc, header: "".}: Cflag VT1* {.importc, header: "".}: Cflag # cflag bit meaning var B0* {.importc, header: "".}: Speed B50* {.importc, header: "".}: Speed B75* {.importc, header: "".}: Speed B110* {.importc, header: "".}: Speed B134* {.importc, header: "".}: Speed B150* {.importc, header: "".}: Speed B200* {.importc, header: "".}: Speed B300* {.importc, header: "".}: Speed B600* {.importc, header: "".}: Speed B1200* {.importc, header: "".}: Speed B1800* {.importc, header: "".}: Speed B2400* {.importc, header: "".}: Speed B4800* {.importc, header: "".}: Speed B9600* {.importc, header: "".}: Speed B19200* {.importc, header: "".}: Speed B38400* {.importc, header: "".}: Speed B57600* {.importc, header: "".}: Speed B115200* {.importc, header: "".}: Speed B230400* {.importc, header: "".}: Speed B460800* {.importc, header: "".}: Speed B500000* {.importc, header: "".}: Speed B576000* {.importc, header: "".}: Speed B921600* {.importc, header: "".}: Speed B1000000* {.importc, header: "".}: Speed B1152000* {.importc, header: "".}: Speed B1500000* {.importc, header: "".}: Speed B2000000* {.importc, header: "".}: Speed B2500000* {.importc, header: "".}: Speed B3000000* {.importc, header: "".}: Speed B3500000* {.importc, header: "".}: Speed B4000000* {.importc, header: "".}: Speed EXTA* {.importc, header: "".}: Speed EXTB* {.importc, header: "".}: Speed CSIZE* {.importc, header: "".}: Cflag CS5* {.importc, header: "".}: Cflag CS6* {.importc, header: "".}: Cflag CS7* {.importc, header: "".}: Cflag CS8* {.importc, header: "".}: Cflag CSTOPB* {.importc, header: "".}: Cflag CREAD* {.importc, header: "".}: Cflag PARENB* {.importc, header: "".}: Cflag PARODD* {.importc, header: "".}: Cflag HUPCL* {.importc, header: "".}: Cflag CLOCAL* {.importc, header: "".}: Cflag # lflag bits var ISIG* {.importc, header: "".}: Cflag ICANON* {.importc, header: "".}: Cflag ECHO* {.importc, header: "".}: Cflag ECHOE* {.importc, header: "".}: Cflag ECHOK* {.importc, header: "".}: Cflag ECHONL* {.importc, header: "".}: Cflag NOFLSH* {.importc, header: "".}: Cflag TOSTOP* {.importc, header: "".}: Cflag IEXTEN* {.importc, header: "".}: Cflag # tcflow() and TCXONC use these var TCOOFF* {.importc, header: "".}: cint TCOON* {.importc, header: "".}: cint TCIOFF* {.importc, header: "".}: cint TCION* {.importc, header: "".}: cint # tcflush() and TCFLSH use these var TCIFLUSH* {.importc, header: "".}: cint TCOFLUSH* {.importc, header: "".}: cint TCIOFLUSH* {.importc, header: "".}: cint # tcsetattr uses these var TCSANOW* {.importc, header: "".}: cint TCSADRAIN* {.importc, header: "".}: cint TCSAFLUSH* {.importc, header: "".}: cint # Compare a character C to a value VAL from the `cc' array in a # `struct termios'. If VAL is _POSIX_VDISABLE, no character can match it. template cceq*(val, c): untyped = c == val and val != POSIX_VDISABLE # Return the output baud rate stored in *TERMIOS_P. proc cfGetOspeed*(termios: ptr Termios): Speed {.importc: "cfgetospeed", header: "".} # Return the input baud rate stored in *TERMIOS_P. proc cfGetIspeed*(termios: ptr Termios): Speed {.importc: "cfgetispeed", header: "".} # Set the output baud rate stored in *TERMIOS_P to SPEED. proc cfSetOspeed*(termios: ptr Termios; speed: Speed): cint {. importc: "cfsetospeed", header: "".} # Set the input baud rate stored in *TERMIOS_P to SPEED. proc cfSetIspeed*(termios: ptr Termios; speed: Speed): cint {. importc: "cfsetispeed", header: "".} # Set both the input and output baud rates in *TERMIOS_OP to SPEED. proc tcGetAttr*(fd: cint; termios: ptr Termios): cint {. importc: "tcgetattr", header: "".} # Set the state of FD to *TERMIOS_P. # Values for OPTIONAL_ACTIONS (TCSA*) are in . proc tcSetAttr*(fd: cint; optional_actions: cint; termios: ptr Termios): cint {. importc: "tcsetattr", header: "".} # Set *TERMIOS_P to indicate raw mode. proc tcSendBreak*(fd: cint; duration: cint): cint {.importc: "tcsendbreak", header: "".} # Wait for pending output to be written on FD. # # This function is a cancellation point and therefore not marked with # . proc tcDrain*(fd: cint): cint {.importc: "tcdrain", header: "".} # Flush pending data on FD. # Values for QUEUE_SELECTOR (TC{I,O,IO}FLUSH) are in . proc tcFlush*(fd: cint; queue_selector: cint): cint {.importc: "tcflush", header: "".} # Suspend or restart transmission on FD. # Values for ACTION (TC[IO]{OFF,ON}) are in . proc tcFlow*(fd: cint; action: cint): cint {.importc: "tcflow", header: "".} # Get process group ID for session leader for controlling terminal FD. # Window size ioctl. Solaris based systems have an uncommen place for this. when defined(solaris) or defined(sunos): var TIOCGWINSZ*{.importc, header: "".}: culong else: var TIOCGWINSZ*{.importc, header: "".}: culong when defined(nimHasStyleChecks): {.push styleChecks: off.} type IOctl_WinSize* = object ws_row*, ws_col*, ws_xpixel*, ws_ypixel*: cushort when defined(nimHasStyleChecks): {.pop.} proc ioctl*(fd: cint, request: culong, reply: ptr IOctl_WinSize): int {. importc: "ioctl", header: "", varargs.}