]> mj.ucw.cz Git - pciutils.git/commitdiff
Moved functions related to parameters to params.c.
authorMartin Mares <mj@ucw.cz>
Tue, 12 Feb 2008 08:41:40 +0000 (09:41 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 12 Feb 2008 08:41:40 +0000 (09:41 +0100)
lib/Makefile
lib/init.c
lib/internal.h
lib/params.c [new file with mode: 0644]

index 65483761cc1c234b0a2b4ed8ed25df964efe7ac4..49eb6fbcfb39f508e2d9023a46c5c2294fabe018 100644 (file)
@@ -3,7 +3,7 @@
 
 include config.mk
 
-OBJS=init.o access.o generic.o dump.o names.o filter.o names-hash.o names-parse.o names-net.o names-cache.o
+OBJS=init.o access.o generic.o dump.o names.o filter.o names-hash.o names-parse.o names-net.o names-cache.o params.o
 INCL=internal.h pci.h config.h header.h sysdep.h types.h
 
 PCILIB=libpci.a
@@ -63,6 +63,7 @@ $(PCILIBPC): $(PCILIBPC).in
 
 init.o: init.c $(INCL)
 access.o: access.c $(INCL)
+params.o: params.c $(INCL)
 i386-ports.o: i386-ports.c $(INCL) i386-io-hurd.h i386-io-linux.h i386-io-sunos.h i386-io-windows.h
 proc.o: proc.c $(INCL) pread.h
 sysfs.o: sysfs.c $(INCL) pread.h
index 737112e30786a277ec5722459f49e6ce514bd4da..59cb706d3580aa8ab6ff5938bc3bf51f16e47e14 100644 (file)
@@ -59,25 +59,6 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
 #endif
 };
 
-struct pci_access *
-pci_alloc(void)
-{
-  struct pci_access *a = malloc(sizeof(struct pci_access));
-  int i;
-
-  memset(a, 0, sizeof(*a));
-  pci_set_name_list_path(a, PCI_PATH_IDS_DIR "/" PCI_IDS, 0);
-#ifdef PCI_USE_DNS
-  pci_define_param(a, "net.domain", PCI_ID_DOMAIN, "DNS domain used for resolving of ID's");
-  pci_define_param(a, "net.cache_name", "~/.pciids-cache", "Name of the ID cache file");
-  a->id_lookup_mode = PCI_LOOKUP_CACHE;
-#endif
-  for(i=0; i<PCI_ACCESS_MAX; i++)
-    if (pci_methods[i] && pci_methods[i]->config)
-      pci_methods[i]->config(a);
-  return a;
-}
-
 void *
 pci_malloc(struct pci_access *a, int size)
 {
@@ -142,78 +123,23 @@ pci_null_debug(char *msg UNUSED, ...)
 {
 }
 
-char *
-pci_get_param(struct pci_access *acc, char *param)
-{
-  struct pci_param *p;
-
-  for (p=acc->params; p; p=p->next)
-    if (!strcmp(p->param, param))
-      return p->value;
-  return NULL;
-}
-
-void
-pci_define_param(struct pci_access *acc, char *param, char *value, char *help)
-{
-  struct pci_param *p = pci_malloc(acc, sizeof(*p));
-
-  p->next = acc->params;
-  acc->params = p;
-  p->param = param;
-  p->value = value;
-  p->value_malloced = 0;
-  p->help = help;
-}
-
-int
-pci_set_param_internal(struct pci_access *acc, char *param, char *value, int copy)
-{
-  struct pci_param *p;
-
-  for (p=acc->params; p; p=p->next)
-    if (!strcmp(p->param, param))
-      {
-       if (p->value_malloced)
-         pci_mfree(p->value);
-       p->value_malloced = copy;
-       if (copy)
-         p->value = pci_strdup(acc, value);
-       else
-         p->value = value;
-       return 0;
-      }
-  return -1;
-}
-
-int
-pci_set_param(struct pci_access *acc, char *param, char *value)
-{
-  return pci_set_param_internal(acc, param, value, 1);
-}
-
-static void
-pci_free_params(struct pci_access *acc)
+struct pci_access *
+pci_alloc(void)
 {
-  struct pci_param *p;
-
-  while (p = acc->params)
-    {
-      acc->params = p->next;
-      if (p->value_malloced)
-       pci_mfree(p->value);
-      pci_mfree(p);
-    }
-}
+  struct pci_access *a = malloc(sizeof(struct pci_access));
+  int i;
 
-struct pci_param *
-pci_walk_params(struct pci_access *acc, struct pci_param *prev)
-{
-  /* So far, the params form a simple linked list, but this can change in the future */
-  if (!prev)
-    return acc->params;
-  else
-    return prev->next;
+  memset(a, 0, sizeof(*a));
+  pci_set_name_list_path(a, PCI_PATH_IDS_DIR "/" PCI_IDS, 0);
+#ifdef PCI_USE_DNS
+  pci_define_param(a, "net.domain", PCI_ID_DOMAIN, "DNS domain used for resolving of ID's");
+  pci_define_param(a, "net.cache_name", "~/.pciids-cache", "Name of the ID cache file");
+  a->id_lookup_mode = PCI_LOOKUP_CACHE;
+#endif
+  for(i=0; i<PCI_ACCESS_MAX; i++)
+    if (pci_methods[i] && pci_methods[i]->config)
+      pci_methods[i]->config(a);
+  return a;
 }
 
 void
index 1f6a2f6686b370b0adbd25b8e6f106a156e972a6..fea3978d468f9c5d36467e8c3c2dd05aa01a1645 100644 (file)
@@ -38,6 +38,7 @@ int pci_link_dev(struct pci_access *, struct pci_dev *);
 
 void pci_define_param(struct pci_access *acc, char *param, char *val, char *help);
 int pci_set_param_internal(struct pci_access *acc, char *param, char *val, int copy);
+void pci_free_params(struct pci_access *acc);
 
 extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
        pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
diff --git a/lib/params.c b/lib/params.c
new file mode 100644 (file)
index 0000000..0e6edbb
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *     The PCI Library -- Parameters
+ *
+ *     Copyright (c) 2008 Martin Mares <mj@ucw.cz>
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "internal.h"
+
+char *
+pci_get_param(struct pci_access *acc, char *param)
+{
+  struct pci_param *p;
+
+  for (p=acc->params; p; p=p->next)
+    if (!strcmp(p->param, param))
+      return p->value;
+  return NULL;
+}
+
+void
+pci_define_param(struct pci_access *acc, char *param, char *value, char *help)
+{
+  struct pci_param *p = pci_malloc(acc, sizeof(*p));
+
+  p->next = acc->params;
+  acc->params = p;
+  p->param = param;
+  p->value = value;
+  p->value_malloced = 0;
+  p->help = help;
+}
+
+int
+pci_set_param_internal(struct pci_access *acc, char *param, char *value, int copy)
+{
+  struct pci_param *p;
+
+  for (p=acc->params; p; p=p->next)
+    if (!strcmp(p->param, param))
+      {
+       if (p->value_malloced)
+         pci_mfree(p->value);
+       p->value_malloced = copy;
+       if (copy)
+         p->value = pci_strdup(acc, value);
+       else
+         p->value = value;
+       return 0;
+      }
+  return -1;
+}
+
+int
+pci_set_param(struct pci_access *acc, char *param, char *value)
+{
+  return pci_set_param_internal(acc, param, value, 1);
+}
+
+void
+pci_free_params(struct pci_access *acc)
+{
+  struct pci_param *p;
+
+  while (p = acc->params)
+    {
+      acc->params = p->next;
+      if (p->value_malloced)
+       pci_mfree(p->value);
+      pci_mfree(p);
+    }
+}
+
+struct pci_param *
+pci_walk_params(struct pci_access *acc, struct pci_param *prev)
+{
+  /* So far, the params form a simple linked list, but this can change in the future */
+  if (!prev)
+    return acc->params;
+  else
+    return prev->next;
+}
+