X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ls-kernel.c;h=78b70f19e1f5eeef68a901b5f59476d2bae3f5c0;hb=42502a496786c94c6f8c246eab08f3f0c8f7db49;hp=15aa46ac083da890f5572998b2d9c989b411b546;hpb=17ec7e70ea71a3ccbccf9f3b9cfe846eb1200e0d;p=pciutils.git diff --git a/ls-kernel.c b/ls-kernel.c index 15aa46a..78b70f1 100644 --- a/ls-kernel.c +++ b/ls-kernel.c @@ -196,19 +196,16 @@ match_pcimap(struct device *d, struct pcimap_entry *e) static const char *next_module(struct device *d) { - static struct pcimap_entry *current, *last_printed; + static struct pcimap_entry *current; if (!current) - { - current = pcimap_head; - last_printed = NULL; - } + current = pcimap_head; else current = current->next; while (current) { - if (match_pcimap(d, current) && (!last_printed || strcmp(last_printed->module, current->module))) + if (match_pcimap(d, current)) return current->module; current = current->next; } @@ -257,6 +254,25 @@ find_driver(struct device *d, char *buf) return buf; } +static const char * +next_module_filtered(struct device *d) +{ + static char prev_module[256]; + const char *module; + + while (module = next_module(d)) + { + if (strcmp(module, prev_module)) + { + strncpy(prev_module, module, sizeof(prev_module)); + prev_module[sizeof(prev_module) - 1] = 0; + return module; + } + } + prev_module[0] = 0; + return NULL; +} + void show_kernel(struct device *d) { @@ -270,7 +286,7 @@ show_kernel(struct device *d) return; int cnt = 0; - while (module = next_module(d)) + while (module = next_module_filtered(d)) printf("%s %s", (cnt++ ? "," : "\tKernel modules:"), module); if (cnt) putchar('\n'); @@ -288,7 +304,7 @@ show_kernel_machine(struct device *d) if (!show_kernel_init()) return; - while (module = next_module(d)) + while (module = next_module_filtered(d)) printf("Module:\t%s\n", module); }