ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/saidar/saidar.c
(Generate patch)

Comparing projects/libstatgrab/src/saidar/saidar.c (file contents):
Revision 1.13 by tdb, Wed Oct 22 13:07:22 2003 UTC vs.
Revision 1.19 by tdb, Thu Dec 11 14:27:08 2003 UTC

# Line 428 | Line 428 | int main(int argc, char **argv){
428          extern int optind;
429          int c;
430  
431 +        time_t last_update = 0;
432 +
433          WINDOW *window;
434  
433        int stdin_fileno;
434        fd_set infds;
435        struct timeval timeout;
436
435          extern int errno;
438        char ch;
436  
437          int delay=2;
438   #ifdef ALLBSD
# Line 449 | Line 446 | int main(int argc, char **argv){
446          }
447   #endif
448                  
449 <        while ((c = getopt(argc, argv, "vhd:")) != EOF){
449 >        while ((c = getopt(argc, argv, "vhd:")) != -1){
450                  switch (c){
451                          case 'd':
452                                  delay = atoi(optarg);
# Line 457 | Line 454 | int main(int argc, char **argv){
454                                          fprintf(stderr, "Time must be 1 second or greater\n");
455                                          exit(1);
456                                  }
460                                delay--;
457                                  break;
458                          case 'v':
459                                  version_num(argv[0]);  
# Line 467 | Line 463 | int main(int argc, char **argv){
463                                  usage(argv[0]);
464                                  return 1;
465                                  break;
470                                
466                  }
467          }
468  
# Line 476 | Line 471 | int main(int argc, char **argv){
471          nonl();
472          cbreak();
473          noecho();
474 +        timeout(delay * 1000);
475          window=newwin(0, 0, 0, 0);
476          clear();
477  
# Line 486 | Line 482 | int main(int argc, char **argv){
482          }
483  
484          display_headings();
489        stdin_fileno=fileno(stdin);
485  
486          for(;;){
487 +                time_t now;
488 +                int ch = getch();
489  
490 <                FD_ZERO(&infds);
491 <                FD_SET(stdin_fileno, &infds);
495 <                timeout.tv_sec = delay;
496 <                timeout.tv_usec = 0;
497 <                
498 <                if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){
499 <                        if(errno!=EINTR){
500 <                                perror("select failed");
501 <                                exit(1);
502 <                        }
490 >                if (ch == 'q'){
491 >                        break;
492                  }
493  
494 <                if(FD_ISSET(stdin_fileno, &infds)){
495 <                        ch=getch();
496 <                        if (ch == 'q'){
497 <                                endwin();
498 <                                return 0;
499 <                        }
494 >                /* To keep the numbers slightly accurate we do not want them
495 >                 * updating more frequently than once a second.
496 >                 */
497 >                now = time(NULL);
498 >                if ((now - last_update) >= 1) {
499 >                        get_stats();
500                  }
501 +                last_update = now;
502  
513                get_stats();
514
503                  display_data();
516
517                /* To keep the numbers slightly accurate we do not want them updating more
518                 * frequently than once a second.
519                 */
520                sleep(1);
504          }      
505  
506          endwin();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines