From 79bd2194539aa559078de9afb1500a2e754ee501 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sun, 13 Jul 2014 19:54:47 -0400 Subject: Added server --- util.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index c93055c..ea3ab01 100644 --- a/util.c +++ b/util.c @@ -14,18 +14,18 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Contact the author at contact@fwei.tk */ #include "strings.h" #include "util.h" #include -#include #include #include - - +#include +int out_fd; +extern int pipes[FD_SETSIZE][2]; void allLower(char* str) { for(int i=0;str[i];++i) @@ -35,21 +35,11 @@ void allLower(char* str) } void print_string(const char* str) /* print string, slowly */ { - int window_height; - int junk; - getmaxyx(stdscr, window_height, junk); int i=0; while(str[i]) { - addch(str[i]); - int cursx, cursy; - getyx(stdscr, cursy, cursx); - if(cursy==window_height) - { - scroll(stdscr); - } - usleep(SLEEP_TIME); - refresh(); + write(out_fd, &str[i], 1); + fsync(out_fd); ++i; } } @@ -66,4 +56,28 @@ void remove_punct(char* buf) } } } +void clear(void) +{ +} +void refresh(void) +{ + fsync(out_fd); +} +int getnstr(char* buf, int max) +{ + printf("reading...\n"); + memset(buf, 0, sizeof(buf)); + int back=0; + char c=0; + do { + read(pipes[out_fd][0], &c, 1); + if(c!='\n') + { + buf[back]=c; + ++back; + } + } + while(back