]> mj.ucw.cz Git - pciutils.git/blobdiff - common.c
compat/getopt.c: Fixed a typo in declaration of getopt_long()
[pciutils.git] / common.c
index 7e53157773dcfebacfc47428f647e0a9c3a0db67..8ea52fa6d7b5398d2ff4a1c90cd9faa10ca410a7 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1,7 +1,7 @@
 /*
  *     The PCI Utilities -- Common Functions
  *
- *     Copyright (c) 1997--2006 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -44,6 +44,38 @@ xrealloc(void *ptr, unsigned int howmuch)
   return p;
 }
 
+char *
+xstrdup(char *str)
+{
+  int len = strlen(str) + 1;
+  char *copy = xmalloc(len);
+  memcpy(copy, str, len);
+  return copy;
+}
+
+static void
+set_pci_method(struct pci_access *pacc, char *arg)
+{
+  char *name;
+  int i;
+
+  if (!strcmp(arg, "help"))
+    {
+      printf("Known PCI access methods:\n\n");
+      for (i=0; name = pci_get_method_name(i); i++)
+       if (name[0])
+         printf("%s\n", name);
+      exit(0);
+    }
+  else
+    {
+      i = pci_lookup_method(arg);
+      if (i < 0)
+       die("No such PCI access method: %s (see `-A help' for a list)", arg);
+      pacc->method = i;
+    }
+}
+
 static void
 set_pci_option(struct pci_access *pacc, char *arg)
 {
@@ -62,7 +94,7 @@ set_pci_option(struct pci_access *pacc, char *arg)
        die("Invalid PCI access parameter syntax: %s", arg);
       *sep++ = 0;
       if (pci_set_param(pacc, arg, sep) < 0)
-       die("Unrecognized PCI access parameter: %s", arg);
+       die("Unrecognized PCI access parameter: %s (see `-O help' for a list)", arg);
     }
 }
 
@@ -71,12 +103,6 @@ parse_generic_option(int i, struct pci_access *pacc, char *optarg)
 {
   switch (i)
     {
-#ifdef PCI_HAVE_PM_LINUX_PROC
-    case 'P':
-      pacc->method_params[PCI_ACCESS_PROC_BUS_PCI] = optarg;
-      pacc->method = PCI_ACCESS_PROC_BUS_PCI;
-      break;
-#endif
 #ifdef PCI_HAVE_PM_INTEL_CONF
     case 'H':
       if (!strcmp(optarg, "1"))
@@ -89,10 +115,13 @@ parse_generic_option(int i, struct pci_access *pacc, char *optarg)
 #endif
 #ifdef PCI_HAVE_PM_DUMP
     case 'F':
-      pacc->method_params[PCI_ACCESS_DUMP] = optarg;
+      pci_set_param(pacc, "dump.name", optarg);
       pacc->method = PCI_ACCESS_DUMP;
       break;
 #endif
+    case 'A':
+      set_pci_method(pacc, optarg);
+      break;
     case 'G':
       pacc->debugging++;
       break;