Giter Club home page Giter Club logo

Comments (13)

edsrzf avatar edsrzf commented on August 25, 2024

Could you please run go tool cgo -godefs defs.go and paste in the output? Also let me know your target architecture. If you can do it for both 32-bit and 64-bit architectures, even better. (It might be the same as defs_linux_amd64.go in both cases, but I'm not really sure.)

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

Daves-MacBook-Air:fineline$ go tool cgo -godefs defs.go

error: 'TCGETS' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: 'OLCUC' undeclared (first use in this function)
error: 'TCSETS' undeclared (first use in this function)
error: 'VSWTC' undeclared (first use in this function)
error: 'IUCLC' undeclared (first use in this function)
error: 'TCSETSW' undeclared (first use in this function)
error: 'TCSETSF' undeclared (first use in this function)
go tool cgo: exit status 2

from fineline.

edsrzf avatar edsrzf commented on August 25, 2024

Hmmm, it appears that OS X truly doesn't have those symbols. I'll push something for you to try out pretty soon.

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

I copy/pasted the linux one into a darwin one and it builds. Don't know if that helps.

On Jun 22, 2012, at 5:46 PM, Evan Shaw wrote:

Hmmm, it appears that OS X truly doesn't have those symbols. I'll push something for you to try out pretty soon.


Reply to this email directly or view it on GitHub:
#1 (comment)

from fineline.

edsrzf avatar edsrzf commented on August 25, 2024

Copy/pasting will let you compile, but I don't think you'll get much further than that because the constants are defined differently on OS X.

I've pushed a change to separate out the POSIX stuff from the Linux-specific stuff. So now try go tool cgo -godefs defs_posix.go > defs_posix_darwin_$GOARCH.go. If that runs successfully, I think things will work.

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024
Daves-MacBook-Air:fineline dgrijalva$ git log --oneline -n1
826cf2d Implement tcgetattr and tcsetattr for Darwin and BSDs
Daves-MacBook-Air:fineline dgrijalva$ go tool cgo -godefs defs_posix.go > defs_posix_darwin_amd64.go
error: 'IUCLC' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: 'OLCUC' undeclared (first use in this function)
error: 'VSWTC' undeclared (first use in this function)
go tool cgo: exit status 2

from fineline.

edsrzf avatar edsrzf commented on August 25, 2024

Ok, looks like the first two have been removed from POSIX and the third never was in to begin with. I've pushed another commit, try again. (Thanks for bearing with me; I'm kinda working blind.)

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

That appears to have worked. Here's the generated file. amd64 is correct, right? I don't have a 32-bit mac available right now.

// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs defs_posix.go

package fineline

const (
    TIOCGWINSZ  = 0x40087468

    IGNBRK  = 0x1
    BRKINT  = 0x2
    IGNPAR  = 0x4
    PARMRK  = 0x8
    INPCK   = 0x10
    ISTRIP  = 0x20
    INLCR   = 0x40
    IGNCR   = 0x80
    ICRNL   = 0x100
    IXON    = 0x200
    IXANY   = 0x800
    IXOFF   = 0x400
    IMAXBEL = 0x2000
    IUTF8   = 0x4000

    OPOST   = 0x1
    ONLCR   = 0x2
    OCRNL   = 0x10
    ONOCR   = 0x20
    ONLRET  = 0x40
    OFILL   = 0x80
    OFDEL   = 0x20000

    CS8 = 0x300

    ISIG    = 0x80
    ICANON  = 0x100
    ECHO    = 0x8
    ECHOE   = 0x2
    ECHOK   = 0x4
    ECHONL  = 0x10
    NOFLSH  = 0x80000000
    TOSTOP  = 0x400000
    IEXTEN  = 0x400

    VINTR       = 0x8
    VQUIT       = 0x9
    VERASE      = 0x3
    VKILL       = 0x5
    VEOF        = 0x0
    VTIME       = 0x11
    VMIN        = 0x10
    VSTART      = 0xc
    VSTOP       = 0xd
    VSUSP       = 0xa
    VEOL        = 0x1
    VREPRINT    = 0x6
    VDISCARD    = 0xf
    VWERASE     = 0x4
    VLNEXT      = 0xe
    VEOL2       = 0x2

    TCSANOW     = 0x0
    TCSADRAIN   = 0x1
    TCSAFLUSH   = 0x2
)

type termios struct {
    Iflag   uint64
    Oflag   uint64
    Cflag   uint64
    Lflag   uint64
    Cc  [20]uint8
    Pad_cgo_0   [4]byte
    Ispeed  uint64
    Ospeed  uint64
}
type winsize struct {
    Row uint16
    Col uint16
    Xpixel  uint16
    Ypixel  uint16
}

from fineline.

edsrzf avatar edsrzf commented on August 25, 2024

Awesome, are you able to test it either by compiling/running shrug or just writing a simple test app? amd64 sounds right.

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

Actually, it looks like I'm still getting build errors.

Daves-MacBook-Air:fineline dgrijalva$ go build .
# github.com/edsrzf/fineline
./ansi.go:33: cannot use TCSAFLUSH (type int) as type *termios in function argument
./ansi.go:33: too many arguments in call to tcsetattr
./ansi.go:41: cannot use TCSAFLUSH (type int) as type *termios in function argument
./ansi.go:41: too many arguments in call to tcsetattr
./termios_bsd.go:15: undefined: op
./termios_bsd.go:17: constant 2152231956 overflows int
./termios_bsd.go:19: constant 2152231957 overflows int
./termios_bsd.go:21: constant 2152231958 overflows int

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

I got it to build and it works with a simple test app. I had to make a couple changes:

tcsetattr was missing an argument. I adding it back fixed that.

some of the syscall constants overflowed int. looking deeper, the library uses a uintptr, so switching from int to uint fixed it.

My patch is included. My test app is available here: https://gist.github.com/2998583


diff --git a/ioctl.go b/ioctl.go
index 9c4dc33..d1ed34d 100644
--- a/ioctl.go
+++ b/ioctl.go
@@ -10,7 +10,7 @@ func winIoctl(fd int, cmd int, win *winsize) {
    return
 }

-func ttyIoctl(fd int, cmd int, term *termios) {
+func ttyIoctl(fd int, cmd uint, term *termios) {
    _, _, _ = syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(term)))
    return
 }
diff --git a/termios_bsd.go b/termios_bsd.go
index b73008a..55ea234 100644
--- a/termios_bsd.go
+++ b/termios_bsd.go
@@ -10,8 +10,8 @@ func tcgetattr(fd int, t *termios) {
    ttyIoctl(0, syscall.TIOCGETA, t)
 }

-func tcsetattr(fd int, t *termios) {
-   var cmd int
+func tcsetattr(fd int, op int, t *termios) {
+   var cmd uint
    switch op {
    case TCSANOW:
        cmd = syscall.TIOCSETA

from fineline.

edsrzf avatar edsrzf commented on August 25, 2024

Thanks a ton for your help on this.

from fineline.

dgrijalva avatar dgrijalva commented on August 25, 2024

No prob. I've been looking for this for a while. Excited to play with it.

from fineline.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.