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

Comparing projects/libstatgrab/src/statgrab/statgrab.c (file contents):
Revision 1.18 by ats, Fri Feb 13 12:52:40 2004 UTC vs.
Revision 1.23 by ats, Sun Apr 4 21:59:16 2004 UTC

# Line 38 | Line 38 | typedef enum {
38          DOUBLE,
39          STRING,
40          INT,
41 +        BOOL,
42          DUPLEX
43   } stat_type;
44  
# Line 362 | Line 363 | void populate_net() {
363                                   "net", name, "tx", NULL);
364                          add_stat(LONG_LONG, &net[i].rx,
365                                   "net", name, "rx", NULL);
366 +                        add_stat(LONG_LONG, &net[i].ipackets,
367 +                                 "net", name, "ipackets", NULL);
368 +                        add_stat(LONG_LONG, &net[i].opackets,
369 +                                 "net", name, "opackets", NULL);
370 +                        add_stat(LONG_LONG, &net[i].ierrors,
371 +                                 "net", name, "ierrors", NULL);
372 +                        add_stat(LONG_LONG, &net[i].oerrors,
373 +                                 "net", name, "oerrors", NULL);
374 +                        add_stat(LONG_LONG, &net[i].collisions,
375 +                                 "net", name, "collisions", NULL);
376                          add_stat(TIME_T, &net[i].systime,
377                                   "net", name, "systime", NULL);
378                  }
# Line 374 | Line 385 | void populate_net() {
385  
386                          add_stat(INT, &iface[i].speed,
387                                   "net", name, "speed", NULL);
388 +                        add_stat(BOOL, &iface[i].up,
389 +                                 "net", name, "up", NULL);
390                          add_stat(DUPLEX, &iface[i].dup,
391                                   "net", name, "duplex", NULL);
392                  }
# Line 446 | Line 459 | void get_stats() {
459                          t->populate();
460          }
461  
462 <        qsort(stats, num_stats, sizeof *stats, stats_compare);
462 >        if (stats != NULL)
463 >                qsort(stats, num_stats, sizeof *stats, stats_compare);
464   }
465  
466   /* Print the value of a stat. */
467   void print_stat_value(const stat *s) {
468          void *v = s->stat;
469 +        long l;
470  
471          switch (s->type) {
472          case LONG_LONG:
# Line 459 | Line 474 | void print_stat_value(const stat *s) {
474                  break;
475          case TIME_T:
476                  /* FIXME option for formatted time? */
477 <                printf("%ld", *(time_t *)v);
477 >                l = *(time_t *)v;
478 >                printf("%ld", l);
479                  break;
480          case FLOAT:
481                  printf("%f", *(float *)v);
# Line 474 | Line 490 | void print_stat_value(const stat *s) {
490          case INT:
491                  printf("%d", *(int *)v);
492                  break;
493 +        case BOOL:
494 +                printf("%s", *(int *)v ? "true" : "false");
495 +                break;
496          case DUPLEX:
497 <                switch (*(duplex *) v) {
497 >                switch (*(statgrab_duplex *) v) {
498                  case FULL_DUPLEX:
499                          printf("full");
500                          break;
# Line 529 | Line 548 | void print_stats(int argc, char **argv) {
548                          else
549                                  compare = stats_compare;
550  
551 <                        s = (const stat *)bsearch(&key, stats, num_stats,
552 <                                                  sizeof *stats, compare);
551 >                        if (stats == NULL) {
552 >                                s = NULL;
553 >                        } else {
554 >                                s = (const stat *)bsearch(&key, stats,
555 >                                                          num_stats,
556 >                                                          sizeof *stats,
557 >                                                          compare);
558 >                        }
559 >
560                          if (s == NULL) {
561                                  printf("Unknown stat %s\n", name);
562                                  continue;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines