X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=go%2Ftermios%2Ftermios.go;fp=go%2Ftermios%2Ftermios.go;h=0000000000000000000000000000000000000000;hb=d485a5691846998897c4f8b916a09ad783de5289;hp=f3f0077d9d605373ee7ea41a6f5e3a6afb013df8;hpb=a95d80b14c57d801db6b699505ee93297f94179c;p=svn42.git diff --git a/go/termios/termios.go b/go/termios/termios.go deleted file mode 100644 index f3f0077..0000000 --- a/go/termios/termios.go +++ /dev/null @@ -1,138 +0,0 @@ -package termios - -import ( - "os"; - "syscall"; - "unsafe" - "errors" -) - -// termios types -type cc_t byte -type speed_t uint32 -type tcflag_t uint32 - -// termios constants -const ( - BRKINT = tcflag_t (0000002) - ICRNL = tcflag_t (0000400) - INPCK = tcflag_t (0000020) - ISTRIP = tcflag_t (0000040) - IXON = tcflag_t (0002000) - OPOST = tcflag_t (0000001) - CS8 = tcflag_t (0000060) - ECHO = tcflag_t (0000010) - ICANON = tcflag_t (0000002) - IEXTEN = tcflag_t (0100000) - ISIG = tcflag_t (0000001) - VTIME = tcflag_t (5) - VMIN = tcflag_t (6) -) - -const ( - B0 = speed_t(0000000) /* hang up */ - B50 = speed_t(0000001) - B75 = speed_t(0000002) - B110 = speed_t(0000003) - B134 = speed_t(0000004) - B150 = speed_t(0000005) - B200 = speed_t(0000006) - B300 = speed_t(0000007) - B600 = speed_t(0000010) - B1200 = speed_t(0000011) - B1800 = speed_t(0000012) - B2400 = speed_t(0000013) - B4800 = speed_t(0000014) - B9600 = speed_t(0000015) - B19200 = speed_t(0000016) - B38400 = speed_t(0000017) - B57600 = speed_t(0010001) - B115200 = speed_t(0010002) - B230400 = speed_t(0010003) - B460800 = speed_t(0010004) - B500000 = speed_t(0010005) - B576000 = speed_t(0010006) - B921600 = speed_t(0010007) - B1000000 = speed_t(0010010) - B1152000 = speed_t(0010011) - B1500000 = speed_t(0010012) - B2000000 = speed_t(0010013) - B2500000 = speed_t(0010014) - B3000000 = speed_t(0010015) - B3500000 = speed_t(0010016) - B4000000 = speed_t(0010017) -) - -const NCCS = 32 -type termios struct { - c_iflag, c_oflag, c_cflag, c_lflag tcflag_t; - c_line cc_t; - c_cc [NCCS]cc_t; - c_ispeed, c_ospeed speed_t -} - -// ioctl constants -const ( - TCGETS = 0x5401 - TCSETS = 0x5402 -) - -var ( - orig_termios termios; - ttyfd uintptr = 0 // STDIN_FILENO -) - -func Ttyfd(fd uintptr) { - ttyfd=fd -} - -func getTermios (dst *termios) error { - r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL, - uintptr (ttyfd), uintptr (TCGETS), - uintptr (unsafe.Pointer (dst))); - - if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 && err != nil { - return err - } - - if r1 != 0 { - // return errors.New("Error") - } - return nil -} - -func setTermios (src *termios) error { - r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL, - uintptr (ttyfd), uintptr (TCSETS), - uintptr (unsafe.Pointer (src))); - - if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 &&err != nil { - return err - } - - if r1 != 0 { - return errors.New ("Error during ioctl tcsets syscall") - } - return nil -} - -func SetRaw () (error) { - if err := getTermios (&orig_termios); err != nil { return err} - - orig_termios.c_iflag &= ^(BRKINT | ICRNL | INPCK | ISTRIP | IXON); - orig_termios.c_oflag &= ^(OPOST); - orig_termios.c_cflag |= (CS8); - orig_termios.c_lflag &= ^(ECHO | ICANON | IEXTEN | ISIG); - - orig_termios.c_cc[VMIN] = 1; - orig_termios.c_cc[VTIME] = 0; - - return setTermios(&orig_termios) -} - -func SetSpeed (speed speed_t) (error) { - if err := getTermios (&orig_termios); err != nil { return err } - orig_termios.c_ispeed = speed - orig_termios.c_ospeed = speed - return setTermios(&orig_termios) -}