diff options
author | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:29:39 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:29:39 +0000 |
commit | 76082a819319e45ae980987e3be5c1cbf6964b60 (patch) | |
tree | a6f05d6d946e0b3c84937c1444f063b6210975ba /perl-install/c | |
parent | fe68b2291cc8f8c096bc082cfcacfad1a7e42e87 (diff) | |
download | drakx-76082a819319e45ae980987e3be5c1cbf6964b60.tar drakx-76082a819319e45ae980987e3be5c1cbf6964b60.tar.gz drakx-76082a819319e45ae980987e3be5c1cbf6964b60.tar.bz2 drakx-76082a819319e45ae980987e3be5c1cbf6964b60.tar.xz drakx-76082a819319e45ae980987e3be5c1cbf6964b60.zip |
use a proper interface between C (ldetect) & perl world, using XS
create directly the hash in XS instead of instead of sprintf()ing it
into a string which was then parsed in perl in order to actually create
the hash
this also simplifies adding further fields
Diffstat (limited to 'perl-install/c')
-rwxr-xr-x | perl-install/c/stuff.xs.pl | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 095d92ffc..42dc7841d 100755 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -95,6 +95,18 @@ void log_perror(const char *msg) { log_message("%s: %s", msg, strerror(errno)); } +HV* common_pciusb_hash_init(struct pciusb_entry *e) { + HV *rh = (HV *)sv_2mortal((SV *)newHV()); + hv_store(rh, "vendor", 6, newSVnv(e->vendor), 0); + hv_store(rh, "subvendor", 9, newSVnv(e->subvendor), 0); + hv_store(rh, "id", 2, newSVnv(e->device), 0); + hv_store(rh, "subid", 5, newSVnv(e->subdevice), 0); + hv_store(rh, "driver", 6, newSVpv(e->module ? e->module : "unknown", 0), 0); + hv_store(rh, "description", 11, newSVpv(e->text, 0), 0); + hv_store(rh, "pci_bus", 7, newSVnv(e->pci_bus), 0); + hv_store(rh, "pci_device", 10, newSVnv(e->pci_device), 0); + return rh; +} '; @@ -268,11 +280,14 @@ pci_probe() EXTEND(SP, entries.nb); for (i = 0; i < entries.nb; i++) { struct pciusb_entry *e = &entries.entries[i]; - snprintf(buf, sizeof(buf), "%04x\t%04x\t%04x\t%04x\t%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\t%s\t%s", - e->vendor, e->device, e->subvendor, e->subdevice, e->pci_domain, e->pci_bus, - e->pci_device, e->pci_function, e->pci_revision, e->is_pciexpress, - pci_class2text(e->class_id), e->class, e->module ? e->module : "unknown", e->text); - PUSHs(sv_2mortal(newSVpv(buf, 0))); + HV * rh = common_pciusb_hash_init(e); + hv_store(rh, "pci_domain", 10, newSVnv(e->pci_domain), 0); + hv_store(rh, "pci_function", 12, newSVnv(e->pci_function), 0); + hv_store(rh, "pci_revision", 12, newSVnv(e->pci_revision), 0); + hv_store(rh, "is_pciexpress", 13, newSVnv(e->is_pciexpress), 0); + hv_store(rh, "nice_media_type", 15, newSVpv(e->class, 0), 0); + hv_store(rh, "media_type", 10, newSVpv(pci_class2text(e->class_id), 0), 0); + PUSHs(newRV((SV *)rh)); } pciusb_free(&entries); @@ -287,11 +302,10 @@ usb_probe() for (i = 0; i < entries.nb; i++) { struct pciusb_entry *e = &entries.entries[i]; struct usb_class_text class_text = usb_class2text(e->class_id); - snprintf(buf, sizeof(buf), "%04x\t%04x\t%s|%s|%s\t%s\t%s\t%d\t%d\t%d", - e->vendor, e->device, class_text.usb_class_text, class_text.usb_sub_text, - class_text.usb_prot_text, e->module ? e->module : "unknown", e->text, - e->pci_bus, e->pci_device, e->usb_port); - PUSHs(sv_2mortal(newSVpv(buf, 0))); + snprintf(buf, sizeof(buf), "%s|%s|%s", class_text.usb_class_text, class_text.usb_sub_text, class_text.usb_prot_text); + HV * rh = common_pciusb_hash_init(e); + hv_store(rh, "usb_port", 8, newSVnv(e->usb_port), 0); + PUSHs(newRV((SV *)rh)); } pciusb_free(&entries); @@ -307,9 +321,10 @@ dmi_probe() EXTEND(SP, entries.nb); for (i = 0; i < entries.nb; i++) { - snprintf(buf, sizeof(buf), "%s\t%s", - entries.entries[i].module, entries.entries[i].constraints); - PUSHs(sv_2mortal(newSVpv(buf, 0))); + HV * rh = (HV *)sv_2mortal((SV *)newHV()); + hv_store(rh, "driver", 6, newSVpv(entries.entries[i].module, 0), 0); + hv_store(rh, "description", 11, newSVpv(entries.entries[i].constraints, 0), 0); + PUSHs(newRV((SV *)rh)); } dmi_entries_free(entries); |