From e06f9e0cc79429ae0c2d55e7964d3945d7d485f7 Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Wed, 24 Feb 2021 20:47:44 -0800 Subject: [PATCH] Updated libgetch --- src/Console/Resources/getch.c | 79 +++++++++++++----------------- src/Console/Resources/libgetch.so | Bin 17264 -> 16792 bytes 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/src/Console/Resources/getch.c b/src/Console/Resources/getch.c index 54a6105..ac71127 100644 --- a/src/Console/Resources/getch.c +++ b/src/Console/Resources/getch.c @@ -1,3 +1,9 @@ +/*********************************************************************** + * This Source Code Form is subject to the terms of the Mozilla Public * + * License, v. 2.0. If a copy of the MPL was not distributed with this * + * file, You can obtain one at http://mozilla.org/MPL/2.0/. * + ***********************************************************************/ + #include #include #include @@ -7,34 +13,31 @@ #include #include -// #define FKEY(k) ((k) >= KEY_F1 && (k) <= KEY_F10) || (k) == KEY_F12 || (k) == KEY_F11 +#define FKEY(k) ((k) >= KEY_F1 && (k) <= KEY_F10) || (k) == KEY_F12 || (k) == KEY_F11 #define NOTNUMPAD(k) ((k) >= KEY_HOME && (k) <= KEY_DELETE) #define EVENT_DEVICE_GLOB "/dev/input/by-path/*-event-kbd" static struct termios oldTermAttributes; -static void setRawMode(void); -static void setNormalMode(void); - -inline static int discardRead(unsigned int length) +static int discardRead(unsigned int length) { char buffer[length]; - ssize_t bytes_read; + ssize_t bytesRead; int flags = fcntl(STDIN_FILENO, F_GETFL); fcntl(STDIN_FILENO, F_SETFL, flags|O_NONBLOCK); - if( (bytes_read = fread(buffer, sizeof(char), length, stdin)) == -1) { + if( (bytesRead = fread(buffer, sizeof(char), length, stdin)) == -1) { perror("discardRead"); } fcntl(STDIN_FILENO, F_SETFL, flags); - return (int)bytes_read; + return (int)bytesRead; } -int getEventDevice(const char * device) +static int getEventDevice(const char * device) { glob_t search; @@ -70,28 +73,33 @@ int getEventDevice(const char * device) return -1; } -unsigned short getScanCode() +static unsigned short getScanCode() { - struct input_event inputEvent[5]; - int fd; + struct input_event inputEvent[3]; + int eventDevice; const char device[FILENAME_MAX]; - if(-1 == getEventDevice(device)) { + if(getEventDevice(device) == -1) { + perror("getEventDevice"); return KEY_RESERVED; } - if( (fd = open(device, O_RDONLY)) == -1 ) { + if( ( eventDevice = open(device, O_RDONLY)) == -1 ) { + perror("open"); return KEY_RESERVED; }; - if( read(fd, &inputEvent, sizeof (inputEvent)) == -1 ) { + + + if( read(eventDevice, &inputEvent, sizeof(inputEvent)) == -1) { + close(eventDevice); return KEY_RESERVED; } - close(fd); + close(eventDevice); - for(int i = 0; i<=5; i++) { - if(inputEvent[i].type == EV_KEY) { + for(int i = 0;i<3;i++) { + if(inputEvent[i].type == EV_KEY && inputEvent[i].code != KEY_ENTER) { return inputEvent[i].code; } } @@ -99,37 +107,16 @@ unsigned short getScanCode() return KEY_RESERVED; } -#pragma clang diagnostic push -#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions" -inline static char *reverseString(char *str) -{ - char *p1, *p2; - - if (! str || ! *str) - return str; - for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) - { - *p1 ^= *p2; - *p2 ^= *p1; - *p1 ^= *p2; - } - return str; -} -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma ide diagnostic ignored "bugprone-reserved-identifier" inline static void pushStdin(int c) { ungetc(c, stdin); } -#pragma clang diagnostic pop -inline static void setNormalMode(void) +static void setNormalMode(void) { tcsetattr(STDIN_FILENO, TCSANOW, &oldTermAttributes); } -inline static void setRawMode(void) +static void setRawMode(void) { tcgetattr(STDIN_FILENO, &oldTermAttributes); @@ -140,7 +127,7 @@ inline static void setRawMode(void) } -unsigned short resolveScanCode(unsigned short key) +static unsigned short resolveScanCode(unsigned short key) { switch(key) { case KEY_DOWN: return KEY_KP2; @@ -157,16 +144,15 @@ unsigned short resolveScanCode(unsigned short key) }; } -int readKey(void) { +static int readKey(void) { - unsigned short scanCode; int key = getchar(); if (key == 27) { - scanCode = getScanCode(); + unsigned short scanCode = getScanCode(); - if (scanCode == KEY_ESC) { + if (scanCode == KEY_ESC || scanCode == KEY_RESERVED) { return 27; } @@ -219,6 +205,7 @@ int readKey(void) { } pushStdin(scanCode); + return returnResult; } diff --git a/src/Console/Resources/libgetch.so b/src/Console/Resources/libgetch.so index 90d8939257245cb6ef4f0a8d9e998f299d5c2899..886aca96e3c846fb87143e52dcac58b210e627b9 100755 GIT binary patch delta 3608 zcmai14Qx}_6~6a5j^hv~abm|#Nt-yKG(f>l3JIY&F#)fSiLQZ(iEa%9K~fMc36n#M zXcnjm)H5zg4jO1fo7vDBru{_AIuL(NiUdUi8a544F}k#3k`Za=Fhquh~RwOvb#*H?{Ow6Y1?T>A=GA1z>eUk2~$j#Hb<<@Gb?2?d;(&;|fr!%r_fk|uz&CYPy5HeL7XlI6tHe_TKPDyc$ zH3c+9jAWx2JVr56+axxJPJ=D7X4!U3V(s)9*kxe5C$ahTxYb2(fQ?ULoddjVljXO$ zD|qKm=P=gN&GaJ2{7b!z$uV=ifSU1;Q;wQf!$dNu^m(1k&&gLFgd7-Po<2Z^GSZS$yyQRqcP#SXf{nF%SIS|3fe_`$-$Ge( z)PDj>qES(l#0E6y%tO$5qY>D^TifZ)yj}bpS@NIQ^v-=nL9~+D7$uq!U3p552CtnF z87)W7C$ngh*6AP?Tu!V&wfZX>fcGl^qvN;ze~d_(%RCM;jCC z@E?VW7lRX_BjLw-8wBJ$AN9eS}ExTa2aCRkjMcz5uhD2U3N7K}K zU@hYngL14Z`FF9f^NIafNqAflVf_1$Qi<(i7Gf>89_M6tx;p2Bh;$u-fB3X$HQy%T z>reUqRm?aRi^CpOeNV`OiCjjA1OGxO5yPdKK!reQL4FRm6x|5=eAht?0+!w09);YA z&g+Kd$gs=@Wj-tqjhJMfkY_hwSvkj8OL&~OFB6Xc!|xj@zoO8z|L=FZFszQn!>7fN zQqD_nzm7Glla-^-kK;tMj1!H2mD=X;Xl|rq0(mq#LmXXhG&mtgu41L9;M1+2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