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.28 by tdb, Tue Apr 6 14:53:00 2004 UTC vs.
Revision 1.33 by tdb, Mon Jan 17 16:34:26 2005 UTC

# Line 69 | Line 69 | stats_t stats;
69   char *size_conv(long long number){
70          char type[] = {'B', 'K', 'M', 'G', 'T'};
71          int x=0;
72 +        int sign=1;
73          static char string[10];
74  
75 +        if(number < 0){
76 +                sign=-1;
77 +                number=-number;
78 +        }
79 +
80          for(;x<5;x++){
81                  if( (number/1024) < (100)) {
82                          break;
# Line 78 | Line 84 | char *size_conv(long long number){
84                  number = (number/1024);
85          }
86  
87 <        snprintf(string, 10, "%lld%c", number, type[x]);        
87 >        number = number*sign;
88 >
89 >        snprintf(string, 10, "%lld%c", number, type[x]);
90          return string;
91          
92   }
# Line 152 | Line 160 | void display_headings(){
160          printw("Mem Free  :");
161  
162          /* Swap */
163 <        move(6, 21);
164 <        printw("Swap Total:");
165 <        move(7, 21);
166 <        printw("Swap Used :");
167 <        move(8, 21);
168 <        printw("Swap Free :");
163 >        move(6, 21);
164 >        printw("Swap Total:");
165 >        move(7, 21);
166 >        printw("Swap Used :");
167 >        move(8, 21);
168 >        printw("Swap Free :");
169  
170          /* VM */
171          move(6, 42);
# Line 354 | Line 362 | void display_data(){
362                  /* Network */
363                  network_stat_ptr = stats.network_io_stats;
364                  for(counter=0;counter<stats.network_io_entries;counter++){
365 <                        move(line, 42);
365 >                        move(line, 42);
366                          printw("%s", network_stat_ptr->interface_name);
367                          move(line, 62);
368                          rt = (network_stat_ptr->systime)? (network_stat_ptr->rx / network_stat_ptr->systime): network_stat_ptr->rx;
# Line 377 | Line 385 | void display_data(){
385                          move(line, 62);
386                          printw("%7s", size_conv(disk_stat_ptr->avail));
387                          move(line, 73);
388 <                        printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)));
388 >                        printw("%6.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail)));
389                          disk_stat_ptr++;
390                          line++;
391                  }
# Line 386 | Line 394 | void display_data(){
394          refresh();
395   }
396  
397 < void sig_winch_handler(int sig){
397 > void sig_winch_handler(int dummy){
398          clear();
399          display_headings();
400          display_data();
401 <        signal(SIGWINCH, sig_winch_handler);
401 >        signal(SIGWINCH, sig_winch_handler);
402   }
403  
404   int get_stats(){
# Line 416 | Line 424 | void version_num(char *progname){
424   }
425  
426   void usage(char *progname){
427 <        fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname);
428 <        fprintf(stderr, "  -d    Sets the update time in seconds\n");
427 >        fprintf(stderr, "Usage: %s [-d delay] [-v] [-h]\n\n", progname);
428 >        fprintf(stderr, "  -d    Sets the update time in seconds\n");
429          fprintf(stderr, "  -v    Prints version number\n");
430 <        fprintf(stderr, "  -h    Displays this help information.\n");
431 <        fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
432 <        exit(1);
430 >        fprintf(stderr, "  -h    Displays this help information.\n");
431 >        fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
432 >        exit(1);
433   }
434  
435   int main(int argc, char **argv){
436  
437 <        extern char *optarg;
438 <        int c;
437 >        extern char *optarg;
438 >        int c;
439  
440          time_t last_update = 0;
441  
# Line 443 | Line 451 | int main(int argc, char **argv){
451                  return 1;
452          }
453                  
454 <        while ((c = getopt(argc, argv, "vhd:")) != -1){
455 <                switch (c){
456 <                        case 'd':
457 <                                delay = atoi(optarg);
454 >        while ((c = getopt(argc, argv, "vhd:")) != -1){
455 >                switch (c){
456 >                        case 'd':
457 >                                delay = atoi(optarg);
458                                  if (delay < 1){
459                                          fprintf(stderr, "Time must be 1 second or greater\n");
460                                          exit(1);
461                                  }
462 <                                break;
462 >                                break;
463                          case 'v':
464                                  version_num(argv[0]);  
465                                  break;
# Line 460 | Line 468 | int main(int argc, char **argv){
468                                  usage(argv[0]);
469                                  return 1;
470                                  break;
471 <                }
472 <        }
471 >                }
472 >        }
473  
474          signal(SIGWINCH, sig_winch_handler);
475 <        initscr();
476 <        nonl();
477 <        cbreak();
478 <        noecho();
475 >        initscr();
476 >        nonl();
477 >        cbreak();
478 >        noecho();
479          timeout(delay * 1000);
480 <        window=newwin(0, 0, 0, 0);
480 >        window=newwin(0, 0, 0, 0);
481          clear();
482  
483          if(!get_stats()){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines