[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#166675: discover: format string should support device id



tags 166675 + patch
thanks

> I suggest implementing this using %i for device ID, and %I for
> vendor ID.  This way one could ask for '%I:%i', and compare this
> value against the output from lspci -n.

Hm, that was easier said that done.  The implementation of discover1
wasn't very extendable.  Several incompatible structs, one for each
device "type".

Anyway, this patch add ID printing support for types bridge, ethernet,
sound, usb, video and isdn.  It is tested and works at least on my
laptop.

OK to commit?

Index: discover/discover.c
===================================================================
RCS file: /cvsroot/pkg-discover/discover1/discover/discover.c,v
retrieving revision 1.5
diff -u -3 -p -u -r1.5 discover.c
--- discover/discover.c	16 Jun 2004 18:28:22 -0000	1.5
+++ discover/discover.c	19 Jun 2004 22:39:50 -0000
@@ -34,7 +34,7 @@
 
 static void error(int status, int errnum, const char *format, ...);
 static void output(FILE *stream, char *format, char *vendor, char *model,
-                   char *module, char *device, char *server);
+                   char *module, char *device, char *server, char *id);
 static void process_bus_list(char *list, int value);
 static char *return_xserver(char *string);
 static char *return_xdriver(char *string);
@@ -295,8 +295,10 @@ main (int argc, char **argv)
         bridge = bridge_detect(bus);
         for (bridge_item = bridge; bridge_item;
              bridge_item = bridge_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", bridge_item->long_id);
             output(stdout, format, bridge_item->vendor, bridge_item->model,
-                   bridge_item->module, NULL, NULL);
+                   bridge_item->module, NULL, NULL, idstr);
         }
     }
     if (device & DEVICE_CDROM) {
@@ -304,21 +306,23 @@ main (int argc, char **argv)
         for (cdrom_item = cdrom; cdrom_item;
              cdrom_item = cdrom_item->next) {
             output(stdout, format, cdrom_item->vendor, cdrom_item->model,
-                   cdrom_item->module, cdrom_item->device, NULL);
+                   cdrom_item->module, cdrom_item->device, NULL, NULL);
         }
     }
     if (device & DEVICE_ETHERNET) {
         eth = ethernet_detect(bus);
         for (eth_item = eth; eth_item; eth_item = eth_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", eth_item->long_id);
             output(stdout, format, eth_item->vendor, eth_item->model,
-                   eth_item->module, NULL, NULL);
+                   eth_item->module, NULL, NULL, idstr);
         }
     }
     if (device & DEVICE_IDE) {
         ide = ideinterface_detect(bus);
         for (ide_item = ide; ide_item; ide_item = ide_item->next) {
             output(stdout, format, ide_item->vendor, ide_item->model,
-                   ide_item->module, NULL, NULL);
+                   ide_item->module, NULL, NULL, NULL);
         }
     }
     if (device & DEVICE_SCSI) {
@@ -355,30 +359,36 @@ main (int argc, char **argv)
 
         for (scsi_item = scsi; scsi_item; scsi_item = scsi_item->next) {
             output(stdout, format, scsi_item->vendor, scsi_item->model,
-                   scsi_item->module, NULL, NULL);
+                   scsi_item->module, NULL, NULL, NULL);
         }
     }
     if (device & DEVICE_SOUND) {
         sound = soundcard_detect(bus);
         for (sound_item = sound; sound_item;
              sound_item = sound_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", sound_item->long_id);
             output(stdout, format, sound_item->vendor, sound_item->model,
-                   sound_item->module, NULL, NULL);
+                   sound_item->module, NULL, NULL, idstr);
         }
     }
     if (device & DEVICE_USB) {
         usb = usbinterface_detect(bus);
         for (usb_item = usb; usb_item; usb_item = usb_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", usb_item->long_id);
             output(stdout, format, usb_item->vendor, usb_item->model,
-                   usb_item->module, NULL, NULL);
+                   usb_item->module, NULL, NULL, idstr);
         }
     }
     if (device & DEVICE_VIDEO) {
         video = video_detect(bus);
         for (video_item = video; video_item;
              video_item = video_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", video_item->long_id);
             output(stdout, format, video_item->vendor, video_item->model,
-                   NULL, NULL, video_item->server);
+                   NULL, NULL, video_item->server, idstr);
         }
     }
     if (device & DEVICE_DISK) {
@@ -386,15 +396,17 @@ main (int argc, char **argv)
         for (disk_item = disk; disk_item;
              disk_item = disk_item->next) {
             output(stdout, format, disk_item->vendor, disk_item->model,
-                   NULL, disk_item->device, NULL);
+                   NULL, disk_item->device, NULL, NULL);
         }
     }
     if (device & DEVICE_ISDN) {
         isdn = isdn_detect(bus);
         for (isdn_item = isdn; isdn_item;
              isdn_item = isdn_item->next) {
+            char idstr[128];
+            sprintf(&idstr[0], "%lx", isdn_item->long_id);
             output(stdout, format, isdn_item->vendor, isdn_item->model,
-                   isdn_item->module, NULL, NULL);
+                   isdn_item->module, NULL, NULL, idstr);
         }
     }
 
@@ -429,7 +441,7 @@ error(int status, int errnum, const char
 /* Generate output as defined by FORMAT. */
 static void
 output(FILE *stream, char *format, char *vendor, char *model, char *module,
-       char *device, char *server)
+       char *device, char *server, char *id)
 {
     char *xserver, *xdriver;
     int i;
@@ -470,6 +482,11 @@ output(FILE *stream, char *format, char 
                   xdriver = return_xdriver(server);
                   if (xdriver) {
                       fputs(xdriver, stream);
+                  }
+                  break;
+              case 'i':
+                  if (id) {
+                      fputs(id, stream);
                   }
                   break;
               default:



Reply to: