From dc3c4b359389d1eb5c2c25568c38dcab7ba3b264 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sat, 18 Jun 2016 21:34:57 -0400 Subject: [PATCH] Remove more useless code --- Makefile | 6 ++-- main.c | 1 - rterm.c | 90 -------------------------------------------------------- rterm.h | 42 -------------------------- 4 files changed, 3 insertions(+), 136 deletions(-) delete mode 100644 rterm.c delete mode 100644 rterm.h diff --git a/Makefile b/Makefile index c87c388..89a6729 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ CFLAGS += -g LIBS = CORE = bdfe -OBJS = main.o bdf.o rterm.o -HFILES = Makefile rterm.h -CFILES = bdf.c rterm.c main.c +OBJS = main.o bdf.o +HFILES = Makefile +CFILES = bdf.c main.c all: $(CORE) diff --git a/main.c b/main.c index cdfa1d6..c7ac1e9 100644 --- a/main.c +++ b/main.c @@ -35,7 +35,6 @@ #include #include "bdf.h" -#include "rterm.h" #define DISPLAY_FONT 0x80000000 diff --git a/rterm.c b/rterm.c deleted file mode 100644 index 4414d56..0000000 --- a/rterm.c +++ /dev/null @@ -1,90 +0,0 @@ -/* BSD License - Copyright (c) 2014 Andrey Chilikin https://github.com/achilikin - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - Sets stdin to raw mode so read() can get chars one by one - without waiting for the Enter -*/ -#include -#include -#include -#include -#include -#include - -#include "rterm.h" - -static int restore = 0; - -/** restore canonical mode ar exit */ -static void mode_restore_proc(void) -{ - stdin_mode(TERM_MODE_CAN); -} - -/** set terminal mode: RAW or CANonical */ -int stdin_mode(int mode) -{ - struct termios term_attr; - - tcgetattr(STDIN_FILENO, &term_attr); - /* set the terminal to raw mode */ - if (mode == TERM_MODE_RAW) { - term_attr.c_lflag &= ~(ECHO | ICANON); - term_attr.c_cc[VMIN] = 0; - if (!restore) { - restore++; - atexit(mode_restore_proc); - } - } - else { - term_attr.c_lflag |= (ECHO | ICANON); - term_attr.c_cc[VMIN] = 1; - } - tcsetattr(STDIN_FILENO, TCSANOW, &term_attr); - - return mode; -} - -/** read stdin with timeout in ms, or -1 until a key is pressed */ -int stdin_getch(int timeout) -{ - struct pollfd polls; - polls.fd = STDIN_FILENO; - polls.events = POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI; - polls.revents = 0; - - if (poll(&polls, 1, timeout) < 0) - return -1; - - int ch = 0; - if (polls.revents) { - if (read(STDIN_FILENO, &ch, 1) < 0) - return -1; - } - - return ch; -} diff --git a/rterm.h b/rterm.h deleted file mode 100644 index d73f042..0000000 --- a/rterm.h +++ /dev/null @@ -1,42 +0,0 @@ -/* BSD License - Copyright (c) 2014 Andrey Chilikin https://github.com/achilikin - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS - BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - Sets stdin to raw mode so read() can get chars one by one - without waiting for the Enter -*/ -#ifndef __RAW_STDIN_TERM_H__ -#define __RAW_STDIN_TERM_H__ - -#define TERM_MODE_CAN 0 /*< canonical terminal mode */ -#define TERM_MODE_RAW 1 /*< raw terminal mode */ - -/** set terminal mode: RAW or CANonical */ -int stdin_mode(int mode); -/** read stdin with timeout in ms, or -1 until a key is pressed */ -int stdin_getch(int timeout); - -#endif -- 2.39.5