From 321b48f138910dbae0f2d47e7aa5bcb0eb5541a5 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 20 Nov 2003 15:03:09 +0000 Subject: new usb_class code (breaks compatibility!) --- generate_usbclass.pl | 74 ++++++++++++++++++++++++++++++++++++++-------------- ldetect.spec | 7 +++-- libldetect.h | 9 ++++++- lspcidrake.c | 27 ++++++++++++++----- 4 files changed, 89 insertions(+), 28 deletions(-) diff --git a/generate_usbclass.pl b/generate_usbclass.pl index 95ac6b8..b5c7029 100755 --- a/generate_usbclass.pl +++ b/generate_usbclass.pl @@ -2,44 +2,80 @@ print q(/* This is auto-generated from , don't modify! */ -static struct { - unsigned long id; +#define NULL 0 + +struct node { + int id; const char *name; -} classes[] = { + int nb_subnodes; + struct node *subnodes; +}; + ); +my (@l, $sub, $subsub); while (<>) { chomp; if (/^C\s+([\da-f]+)\s+(.*)/) { #- I want alphanumeric but I can't get this [:alnum:] to work :-( - ($cat, $cat_descr) = ($1, $2); - } elsif (/^\t([\da-f]+)\s+(.*)/ && defined $cat) { - ($sub, $sub_descr) = ($1, $2); - $sub =~ /^[\da-f]{2}$/ or die "bad line $.: sub category number badly formatted ($_)\n"; - push @without_prot, [ "0x$cat$sub"."00", "/* $. */ { 0x$cat$sub".qq(00, "$cat_descr|$sub_descr" },\n) ]; - } elsif (/^\t\t([\da-f]+)\s+(.*)/ && defined $cat) { - push @everything, qq(/* $. */ { 0x$cat$sub$1, "$cat_descr|$sub_descr|$2" },\n); + push @l, [ $1, $2, $sub = [] ]; + undef $subsub; + } elsif (/^\t([\da-f]+)\s+(.*)/ && defined $sub) { + my ($sub_id, $sub_descr) = ($1, $2); + $sub_id =~ /^[\da-f]{2}$/ or die "bad line $.: sub category number badly formatted ($_)\n"; + push @$sub, [ $sub_id, $sub_descr, $subsub = [] ]; + } elsif (/^\t\t([\da-f]+)\s+(.*)/ && defined $subsub) { + push @$subsub, [ $1, $2, [] ]; } elsif (/^\S/) { - undef $cat; + undef $sub; + undef $subsub; } } -foreach $l (@without_prot) { - grep { /{ $l->[0], / } @everything or push @everything, $l->[1]; +sub dump_it { + my ($l, $name, $prefix) = @_; + + my @l = sort { $a->[0] cmp $b->[0] } @$l or return; + + dump_it($_->[2], $name . '_' . $_->[0], "$prefix ") foreach @l; + + print "${prefix}static struct node $name\[] = {\n"; + foreach (@l) { + my $nb = @{$_->[2]}; + my $sub = $nb ? $name . '_' . $_->[0] : 'NULL'; + printf qq($prefix { 0x%x, "%s", $nb, $sub },\n), hex($_->[0]), $_->[1]; + } + print "$prefix};\n"; } -print sort @everything; +dump_it(\@l, "classes", ''); print ' -}; static int nb_classes = sizeof(classes) / sizeof(*classes); -extern const char *usb_class2text(unsigned long class_) { +static void lookup(const char **p, int *a_class, int kind, int nb_nodes, struct node *nodes) { int i; - for (i = 0; i < nb_classes; i++) - if (classes[i].id == class_) return classes[i].name; + for (i = 0; i < nb_nodes; i++) + if (nodes[i].id == a_class[kind]) { + p[kind] = nodes[i].name; + return lookup(p, a_class, kind + 1, nodes[i].nb_subnodes, nodes[i].subnodes); + } +} + +struct class_text { + const char *class_text; + const char *sub_text; + const char *prot_text; +}; - return ""; +extern struct class_text usb_class2text(unsigned long class_) { + const char *p[3] = { NULL, NULL, NULL }; + int a_class[3] = { (class_ >> 16) & 0xff, (class_ >> 8) & 0xff, class_ & 0xff }; + lookup(p, a_class, 0, nb_classes, classes); + { + struct class_text r = { p[0], p[1], p[2] }; + return r; + } } '; diff --git a/ldetect.spec b/ldetect.spec index c5ac080..77a9b85 100644 --- a/ldetect.spec +++ b/ldetect.spec @@ -1,6 +1,6 @@ Name: ldetect -Version: 0.4.9 -Release: 3mdk +Version: 0.5.1 +Release: 1mdk Summary: Light hardware detection library Source: %name.tar.bz2 Group: System/Libraries @@ -50,6 +50,9 @@ rm -rf $RPM_BUILD_ROOT %_libdir/* %changelog +* Thu Nov 20 2003 Pixel 0.5.1-1mdk +- new usb_class code (breaks compatibility!) + * Tue Aug 19 2003 Thierry Vignaud 0.4.9-3mdk - do full-probe by default diff --git a/libldetect.h b/libldetect.h index f407f35..3a55501 100644 --- a/libldetect.h +++ b/libldetect.h @@ -35,4 +35,11 @@ extern const char *pci_class2text(unsigned long class_); /* usb ************************************************************************/ /******************************************************************************/ extern struct pciusb_entries usb_probe(void); -extern const char *usb_class2text(unsigned long class_); + +struct usb_class_text { + const char *usb_class_text; + const char *usb_sub_text; + const char *usb_prot_text; +}; + +extern struct usb_class_text usb_class2text(unsigned long class_); diff --git a/lspcidrake.c b/lspcidrake.c index 2dd2aff..e1026a7 100644 --- a/lspcidrake.c +++ b/lspcidrake.c @@ -5,7 +5,7 @@ static int verboze = 0; -static void printit(struct pciusb_entries entries, const char *(find_class)(unsigned long )) { +static void printit(struct pciusb_entries entries, void print_class(unsigned long )) { unsigned int i; for (i = 0; i < entries.nb; i++) { struct pciusb_entry *e = &entries.entries[i]; @@ -14,9 +14,7 @@ static void printit(struct pciusb_entries entries, const char *(find_class)(unsi printf(e->text); else printf("unknown (%04x/%04x/%04x/%04x)", e->vendor, e->device, e->subvendor, e->subdevice); if (e->class_) { - const char *class_ = find_class(e->class_); - if (strcmp(class_, "NOT_DEFINED") != 0) - printf(" [%s]", class_); + print_class(e->class_); } if (verboze && e->text) { printf(" (vendor:%04x device:%04x", e->vendor, e->device); @@ -29,6 +27,23 @@ static void printit(struct pciusb_entries entries, const char *(find_class)(unsi pciusb_free(&entries); } +static void print_pci_class(unsigned long class_) { + const char *s = pci_class2text(class_); + if (strcmp(s, "NOT_DEFINED") != 0) + printf(" [%s]", s); +} + +static void print_usb_class(unsigned long class_) { + struct usb_class_text s = usb_class2text(class_); + if (s.usb_class_text) { + printf(" ["); + printf("%s", s.usb_class_text); + if (s.usb_sub_text) printf("|%s", s.usb_sub_text); + if (s.usb_prot_text) printf("|%s", s.usb_prot_text); + printf("]"); + } +} + int main(int argc, char **argv) { char ** ptr = argv; @@ -51,7 +66,7 @@ int main(int argc, char **argv) { ptr++; } - printit(pci_probe(), pci_class2text); - printit(usb_probe(), usb_class2text); + printit(pci_probe(), print_pci_class); + printit(usb_probe(), print_usb_class); return 0; } -- cgit v1.2.1