From bb1ee20964637daf55bd2f34b5518cdbed722e20 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 23 Oct 2019 13:34:40 -0400 Subject: [PATCH] Remove unused ffi prototypes, make php equivalent functions --- src/Editor.php | 2 +- src/ffi.h | 9 --------- src/functions.php | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Editor.php b/src/Editor.php index 6783f23..d1f122d 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -785,7 +785,7 @@ class Editor { { $buffer = substr($buffer, 0, -1); } - else if ($cord < 128 && $this->ffi->iscntrl($cord) === 0 && ! in_array($c, $modifiers, TRUE)) + else if (isascii($c) && ( ! iscntrl($c)) && ! in_array($c, $modifiers, TRUE)) { $buffer .= $c; } diff --git a/src/ffi.h b/src/ffi.h index 5821924..0d5c51a 100644 --- a/src/ffi.h +++ b/src/ffi.h @@ -49,15 +49,6 @@ struct termios int tcgetattr (int fd, struct termios *termios_p); int tcsetattr (int fd, int optional_actions, const struct termios *termios_p); -void cfmakeraw (struct termios *termios_p); - -// ----------------------------------------------------------------------------- -//! -// ----------------------------------------------------------------------------- -int iscntrl (int); - -ssize_t read(int, void *, size_t); - // ----------------------------------------------------------------------------- //! // ----------------------------------------------------------------------------- diff --git a/src/functions.php b/src/functions.php index 95cebcb..11d1c3b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -98,3 +98,25 @@ function ctrl_key(string $char): int // b1,100,010 (b) & b0,011,111 = b0,000,010 return ord($char) & 0x1f; } + +function isascii(string $single_char): bool +{ + if (strlen($single_char) > 1) + { + return FALSE; + } + + return ord($single_char) < 0x80; +} + +function iscntrl(string $char): bool +{ + $c = ord($char); + return isascii($char) && ( $c < 0x20 || $c === 0x7f ); +} + +function isdigit(string $char): bool +{ + $c = ord($char); + return isascii($char) && ( $c > 0x2f && $c < 0x3a ); +}