From 8a04b833b6fa929b7e86fcdbef6304e8f4c55dcc Mon Sep 17 00:00:00 2001 From: toni Date: Wed, 30 Nov 2016 18:39:07 +0100 Subject: dummyshell --- dummyshell.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dummyshell.c (limited to 'dummyshell.c') diff --git a/dummyshell.c b/dummyshell.c new file mode 100644 index 0000000..177423a --- /dev/null +++ b/dummyshell.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include + + +static const char txtheader[] = + "**************\n" + "* dummyshell *\n" + "**************\n"; + + +int main(int argc, char** argv) +{ + struct timeval tv; + tv.tv_sec = 1; + tv.tv_usec = 0; + + int flags = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK); + + static struct termios oldt, newt; + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + + printf("%s\n", txtheader); + fd_set fds; + time_t start = time(NULL); + time_t cur; + while (1) { + cur = time(NULL); + double diff = difftime(cur, start); + printf("\r( %0.fs ) [PRESS ANY KEY TO QUIT] ", diff); + fflush(stdout); + fflush(stdin); + FD_ZERO(&fds); + FD_SET(STDIN_FILENO, &fds); + int ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv); + if (ret == 0) { + tv.tv_sec = 1; + tv.tv_usec = 0; + } else { + printf("quit in 3 .. "); + fflush(stdout); + sleep(1); + printf("2 .. "); + fflush(stdout); + sleep(1); + printf("1 .. "); + fflush(stdout); + sleep(1); + printf("\n"); + break; + } + if (FD_ISSET(STDIN_FILENO,&fds)) break; + } + while (getchar() != EOF) {} + + tcsetattr( STDIN_FILENO, TCSANOW, &oldt); + + return 0; +} -- cgit v1.2.3