Separate out vendors from the product table, to reduce string duplication.

Saves ~10K.
This commit is contained in:
mycroft 2005-03-04 05:03:19 +00:00
parent 6ae9462824
commit 3839e0db1b
2 changed files with 47 additions and 62 deletions

View File

@ -1,5 +1,5 @@
#! /usr/bin/awk -f
# $NetBSD: devlist2h.awk,v 1.12 2005/02/27 15:37:33 perry Exp $
# $NetBSD: devlist2h.awk,v 1.13 2005/03/04 05:03:19 mycroft Exp $
#
# Copyright (c) 1995, 1996 Christopher G. Demetriou
# All rights reserved.
@ -175,28 +175,36 @@ END {
printf("\n") > dfile
printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
printf("const struct usb_vendor usb_vendors[] = {\n") > dfile
for (i = 1; i <= nvendors; i++) {
printf("\t{\n") > dfile
printf("\t USB_VENDOR_%s,\n", vendors[i, 1]) \
> dfile
printf("\t \"") > dfile
j = 3;
needspace = 0;
while ((i, j) in vendors) {
if (needspace)
printf(" ") > dfile
printf("%s", vendors[i, j]) > dfile
needspace = 1
j++
}
printf("\",\n") > dfile
printf("\t},\n") > dfile
}
printf("};\n") > dfile
printf("const int usb_nvendors = %d;\n", nvendors) > dfile
printf("\n") > dfile
printf("const struct usb_product usb_products[] = {\n") > dfile
for (i = 1; i <= nproducts; i++) {
printf("\t{\n") > dfile
printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
products[i, 1], products[i, 1], products[i, 2]) \
> dfile
printf("\t ") > dfile
printf("0") > dfile
printf(",\n") > dfile
vendi = vendorindex[products[i, 1]];
printf("\t \"") > dfile
j = 3;
needspace = 0;
while ((vendi, j) in vendors) {
if (needspace)
printf(" ") > dfile
printf("%s", vendors[vendi, j]) > dfile
needspace = 1
j++
}
printf("\",\n") > dfile
printf("\t \"") > dfile
j = 4;
@ -211,28 +219,9 @@ END {
printf("\",\n") > dfile
printf("\t},\n") > dfile
}
for (i = 1; i <= nvendors; i++) {
printf("\t{\n") > dfile
printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
> dfile
printf("\t USB_KNOWNDEV_NOPROD,\n") \
> dfile
printf("\t \"") > dfile
j = 3;
needspace = 0;
while ((i, j) in vendors) {
if (needspace)
printf(" ") > dfile
printf("%s", vendors[i, j]) > dfile
needspace = 1
j++
}
printf("\",\n") > dfile
printf("\t NULL,\n") > dfile
printf("\t},\n") > dfile
}
printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
printf("};\n") > dfile
printf("const int usb_nproducts = %d;\n", nproducts) > dfile
close(dfile)
close(hfile)
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb_subr.c,v 1.121 2005/03/02 11:37:27 mycroft Exp $ */
/* $NetBSD: usb_subr.c,v 1.122 2005/03/04 05:03:19 mycroft Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.121 2005/03/02 11:37:27 mycroft Exp $");
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.122 2005/03/04 05:03:19 mycroft Exp $");
#include "opt_usbverbose.h"
@ -106,13 +106,15 @@ typedef u_int16_t usb_product_id_t;
/*
* Descriptions of of known vendors and devices ("products").
*/
struct usb_knowndev {
struct usb_vendor {
usb_vendor_id_t vendor;
char *vendorname;
};
struct usb_product {
usb_vendor_id_t vendor;
usb_product_id_t product;
int flags;
char *vendorname, *productname;
char *productname;
};
#define USB_KNOWNDEV_NOPROD 0x01 /* match on vendor only */
#include <dev/usb/usbdevs_data.h>
#endif /* USBVERBOSE */
@ -212,7 +214,7 @@ usbd_devinfo_vp(usbd_device_handle dev, char *v, size_t lv, char *p, size_t lp,
usb_device_descriptor_t *udd = &dev->ddesc;
char *vendor = NULL, *product = NULL;
#ifdef USBVERBOSE
const struct usb_knowndev *kdp;
int n;
#endif
if (dev == NULL) {
@ -240,22 +242,16 @@ usbd_devinfo_vp(usbd_device_handle dev, char *v, size_t lv, char *p, size_t lp,
product = NULL;
}
#ifdef USBVERBOSE
if (vendor == NULL || product == NULL) {
for(kdp = usb_knowndevs;
kdp->vendorname != NULL;
kdp++) {
if (kdp->vendor == UGETW(udd->idVendor) &&
(kdp->product == UGETW(udd->idProduct) ||
(kdp->flags & USB_KNOWNDEV_NOPROD) != 0))
break;
}
if (kdp->vendorname != NULL) {
if (vendor == NULL)
vendor = kdp->vendorname;
if (product == NULL)
product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ?
kdp->productname : NULL;
}
if (vendor == NULL) {
for (n = 0; n < usb_nvendors; n++)
if (usb_vendors[n].vendor == UGETW(udd->idVendor))
vendor = usb_vendors[n].vendorname;
}
if (product == NULL) {
for (n = 0; n < usb_nproducts; n++)
if (usb_products[n].vendor == UGETW(udd->idVendor) &&
usb_products[n].product == UGETW(udd->idProduct))
product = usb_products[n].productname;
}
#endif
if (vendor != NULL && *vendor)