Ticket #1128: stty_termios_bionic.patch

File stty_termios_bionic.patch, 4.0 KB (added by hanDerPeder, 10 years ago)
  • new file stty-features.scm

    From 56d74ddbb524514de70902b39341ec41dc15074a Mon Sep 17 00:00:00 2001
    From: Peder Refsnes <peder.refsnes@gmail.com>
    Date: Tue, 3 Jun 2014 10:57:54 +0200
    Subject: [PATCH] Check for termios ispeed and ospeed
    
    The struct termios contains two fields; ispeed and ospeed, that are
    not always present (ie. the bionic c lib for android). This patch adds
    tests to see if _HAVE_STRUCT_TERMIOS_C_ISPEED and
    _HAVE_STRUCT_TERMIOS_C_OSPEED are defined using the feature-test egg.
    
    When the tests fail getters and setters will be defined that return #f.
    ---
     stty-features.scm | 10 ++++++++++
     stty.meta         |  2 +-
     stty.scm          | 37 +++++++++++++++++++++++++++----------
     stty.setup        |  4 +++-
     4 files changed, 41 insertions(+), 12 deletions(-)
     create mode 100644 stty-features.scm
    
    diff --git a/stty-features.scm b/stty-features.scm
    new file mode 100644
    index 0000000..abf0d64
    - +  
     1(use feature-test)
     2
     3#> #include <termios.h><#
     4
     5(declaration-prefix SCM)
     6(registration-prefix "")
     7
     8(define-foreign-features
     9  _HAVE_STRUCT_TERMIOS_C_ISPEED
     10  _HAVE_STRUCT_TERMIOS_C_OSPEED)
  • stty.meta

    diff --git a/stty.meta b/stty.meta
    index d6e49ff..ff7a420 100644
    a b  
    22
    33(
    44 (egg "stty.egg")
    5  (needs setup-helper foreigners)
     5 (needs setup-helper foreigners feature-test)
    66 (synopsis "stty-style interface to termios")
    77 (category io)
    88 (license "BSD")
  • stty.scm

    diff --git a/stty.scm b/stty.scm
    index 938dbc8..481c274 100644
    a b  
    8383(declare (foreign-declare "#include <termios.h>\n"))
    8484(declare (foreign-declare "typedef struct termios struct_termios;\n"))
    8585
    86 (define-foreign-record-type (term-attrs struct_termios)
    87   (constructor: make-term-attrs)
    88   (destructor: free-term-attrs)
    89   (unsigned-long c_iflag term-attrs-iflag term-attrs-iflag-set!)
    90   (unsigned-long c_oflag term-attrs-oflag term-attrs-oflag-set!)
    91   (unsigned-long c_cflag term-attrs-cflag term-attrs-cflag-set!)
    92   (unsigned-long c_lflag term-attrs-lflag term-attrs-lflag-set!)
    93   (unsigned-char (c_cc 22) term-attrs-cc term-attrs-cc-set!)
    94   (unsigned-long c_ispeed term-attrs-ispeed term-attrs-ispeed-set!)
    95   (unsigned-long c_ospeed term-attrs-ospeed term-attrs-ospeed-set!)
     86(cond-expand
     87 ((and _HAVE_STRUCT_TERMIOS_C_ISPEED _HAVE_STRUCT_TERMIOS_C_OSPEED)
     88  (define-foreign-record-type (term-attrs struct_termios)
     89    (constructor: make-term-attrs)
     90    (destructor: free-term-attrs)
     91    (unsigned-long c_iflag term-attrs-iflag term-attrs-iflag-set!)
     92    (unsigned-long c_oflag term-attrs-oflag term-attrs-oflag-set!)
     93    (unsigned-long c_cflag term-attrs-cflag term-attrs-cflag-set!)
     94    (unsigned-long c_lflag term-attrs-lflag term-attrs-lflag-set!)
     95    (unsigned-char (c_cc 22) term-attrs-cc term-attrs-cc-set!)
     96    (unsigned-long c_ispeed term-attrs-ispeed term-attrs-ispeed-set!)
     97    (unsigned-long c_ospeed term-attrs-ospeed term-attrs-ospeed-set!)
     98    )
    9699  )
     100 (else
     101  (define-foreign-record-type (term-attrs struct_termios)
     102    (constructor: make-term-attrs)
     103    (destructor: free-term-attrs)
     104    (unsigned-long c_iflag term-attrs-iflag term-attrs-iflag-set!)
     105    (unsigned-long c_oflag term-attrs-oflag term-attrs-oflag-set!)
     106    (unsigned-long c_cflag term-attrs-cflag term-attrs-cflag-set!)
     107    (unsigned-long c_lflag term-attrs-lflag term-attrs-lflag-set!)
     108    (unsigned-char (c_cc 22) term-attrs-cc term-attrs-cc-set!))
     109  (define term-attrs-ispeed      (lambda (_)  #f))
     110  (define term-attrs-ispeed-set! (lambda (_ _) #f))
     111  (define term-attrs-ospeed      (lambda (_)  #f))
     112  (define term-attrs-ospeed-set! (lambda (_ _) #f))
     113  ))
    97114
    98115;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    99116;; constants
  • stty.setup

    diff --git a/stty.setup b/stty.setup
    index f1d9fcf..8e995e5 100644
    a b  
     1(compile stty-features.scm)
     2(run (./stty-features > stty-config.scm))
    13
    2 (compile -shared -O2 -j stty stty.scm)
     4(compile -shared -O2 -j stty -X stty-config.scm stty.scm)
    35(compile -shared -O2 stty.import.scm)
    46
    57(install-extension 'stty