--- projects/libstatgrab/src/saidar/saidar.c 2003/10/22 13:07:22 1.13 +++ projects/libstatgrab/src/saidar/saidar.c 2003/11/07 18:38:48 1.17 @@ -428,14 +428,11 @@ int main(int argc, char **argv){ extern int optind; int c; + time_t last_update = 0; + WINDOW *window; - int stdin_fileno; - fd_set infds; - struct timeval timeout; - extern int errno; - char ch; int delay=2; #ifdef ALLBSD @@ -449,7 +446,7 @@ int main(int argc, char **argv){ } #endif - while ((c = getopt(argc, argv, "vhd:")) != EOF){ + while ((c = getopt(argc, argv, "vhd:")) != -1){ switch (c){ case 'd': delay = atoi(optarg); @@ -476,6 +473,7 @@ int main(int argc, char **argv){ nonl(); cbreak(); noecho(); + timeout(delay * 1000); window=newwin(0, 0, 0, 0); clear(); @@ -486,38 +484,26 @@ int main(int argc, char **argv){ } display_headings(); - stdin_fileno=fileno(stdin); for(;;){ + time_t now; + int ch = getch(); - FD_ZERO(&infds); - FD_SET(stdin_fileno, &infds); - timeout.tv_sec = delay; - timeout.tv_usec = 0; - - if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){ - if(errno!=EINTR){ - perror("select failed"); - exit(1); - } + if (ch == 'q'){ + endwin(); + return 0; } - if(FD_ISSET(stdin_fileno, &infds)){ - ch=getch(); - if (ch == 'q'){ - endwin(); - return 0; - } + /* To keep the numbers slightly accurate we do not want them + * updating more frequently than once a second. + */ + now = time(NULL); + if ((now - last_update) >= 1) { + get_stats(); } + last_update = now; - get_stats(); - display_data(); - - /* To keep the numbers slightly accurate we do not want them updating more - * frequently than once a second. - */ - sleep(1); } endwin();