60 |
|
char *name; |
61 |
|
stat_type type; |
62 |
|
void *stat; |
63 |
< |
} stat; |
63 |
> |
} stat_item; |
64 |
> |
/* AIX: |
65 |
> |
statgrab.c:63: error: 'stat' redeclared as different kind of symbol |
66 |
> |
/usr/include/sys/stat.h:320: error: previous declaration of 'stat' was here |
67 |
> |
*/ |
68 |
|
|
69 |
< |
stat *stats = NULL; |
69 |
> |
stat_item *stat_items = NULL; |
70 |
|
int num_stats = 0; |
71 |
|
int alloc_stats = 0; |
72 |
|
#define INCREMENT_STATS 64 |
90 |
|
int i; |
91 |
|
|
92 |
|
for (i = 0; i < num_stats; i++) |
93 |
< |
free(stats[i].name); |
93 |
> |
free(stat_items[i].name); |
94 |
|
num_stats = 0; |
95 |
|
} |
96 |
|
|
141 |
|
/* Stretch the stats array if necessary. */ |
142 |
|
if (num_stats >= alloc_stats) { |
143 |
|
alloc_stats += INCREMENT_STATS; |
144 |
< |
stats = realloc(stats, alloc_stats * sizeof *stats); |
145 |
< |
if (stats == NULL) |
144 |
> |
stat_items = realloc(stat_items, alloc_stats * sizeof *stat_items); |
145 |
> |
if (stat_items == NULL) |
146 |
|
die("out of memory"); |
147 |
|
} |
148 |
|
|
149 |
< |
stats[num_stats].name = name; |
150 |
< |
stats[num_stats].type = type; |
151 |
< |
stats[num_stats].stat = stat; |
149 |
> |
stat_items[num_stats].name = name; |
150 |
> |
stat_items[num_stats].type = type; |
151 |
> |
stat_items[num_stats].stat = stat; |
152 |
|
++num_stats; |
153 |
|
} |
154 |
|
|
155 |
|
/* Compare two stats by name for qsort and bsearch. */ |
156 |
|
int stats_compare(const void *a, const void *b) { |
157 |
< |
return strcmp(((stat *)a)->name, ((stat *)b)->name); |
157 |
> |
return strcmp(((stat_item *)a)->name, ((stat_item *)b)->name); |
158 |
|
} |
159 |
|
|
160 |
|
/* Compare up to the length of the key for bsearch. */ |
161 |
|
int stats_compare_prefix(const void *key, const void *item) { |
162 |
< |
const char *kn = ((stat *)key)->name; |
163 |
< |
const char *in = ((stat *)item)->name; |
162 |
> |
const char *kn = ((stat_item *)key)->name; |
163 |
> |
const char *in = ((stat_item *)item)->name; |
164 |
|
|
165 |
|
return strncmp(kn, in, strlen(kn)); |
166 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
|
495 |
< |
/* Clear and rebuild the stats array. */ |
495 |
> |
/* Clear and rebuild the stat_items array. */ |
496 |
|
void get_stats() { |
497 |
|
toplevel *t; |
498 |
|
|
503 |
|
t->populate(); |
504 |
|
} |
505 |
|
|
506 |
< |
if (stats != NULL) |
507 |
< |
qsort(stats, num_stats, sizeof *stats, stats_compare); |
506 |
> |
if (stat_items != NULL) |
507 |
> |
qsort(stat_items, num_stats, sizeof *stat_items, stats_compare); |
508 |
|
} |
509 |
|
|
510 |
< |
/* Print the value of a stat. */ |
511 |
< |
void print_stat_value(const stat *s) { |
510 |
> |
/* Print the value of a stat_item. */ |
511 |
> |
void print_stat_value(const stat_item *s) { |
512 |
|
void *v = s->stat; |
513 |
|
double fv; |
514 |
|
long lv; |
578 |
|
} |
579 |
|
|
580 |
|
/* Print the name and value of a stat. */ |
581 |
< |
void print_stat(const stat *s) { |
581 |
> |
void print_stat(const stat_item *s) { |
582 |
|
switch (display_mode) { |
583 |
|
case DISPLAY_LINUX: |
584 |
|
printf("%s = ", s->name); |
601 |
|
if (argc == optind) { |
602 |
|
/* Print all stats. */ |
603 |
|
for (i = 0; i < num_stats; i++) |
604 |
< |
print_stat(&stats[i]); |
604 |
> |
print_stat(&stat_items[i]); |
605 |
|
} else { |
606 |
|
/* Print selected stats. */ |
607 |
|
for (i = optind; i < argc; i++) { |
608 |
|
char *name = argv[i]; |
609 |
< |
stat key; |
610 |
< |
const stat *s, *end; |
609 |
> |
stat_item key; |
610 |
> |
const stat_item *s, *end; |
611 |
|
int (*compare)(const void *, const void *); |
612 |
|
|
613 |
|
key.name = name; |
616 |
|
else |
617 |
|
compare = stats_compare; |
618 |
|
|
619 |
< |
if (stats == NULL) { |
619 |
> |
if (stat_items == NULL) { |
620 |
|
s = NULL; |
621 |
|
} else { |
622 |
< |
s = (const stat *)bsearch(&key, stats, |
622 |
> |
s = (const stat_item *)bsearch(&key, stat_items, |
623 |
|
num_stats, |
624 |
< |
sizeof *stats, |
624 |
> |
sizeof *stat_items, |
625 |
|
compare); |
626 |
|
} |
627 |
|
|
631 |
|
} |
632 |
|
|
633 |
|
/* Find the range of stats the user wanted. */ |
634 |
< |
for (; s >= stats; s--) { |
634 |
> |
for (; s >= stat_items; s--) { |
635 |
|
if (compare(&key, s) != 0) |
636 |
|
break; |
637 |
|
} |
638 |
|
s++; |
639 |
< |
for (end = s; end < &stats[num_stats]; end++) { |
639 |
> |
for (end = s; end < &stat_items[num_stats]; end++) { |
640 |
|
if (compare(&key, end) != 0) |
641 |
|
break; |
642 |
|
} |