diff options
author | Burt P <pburt0@gmail.com> | 2019-07-13 10:08:36 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-07-29 19:44:59 -0700 |
commit | 0dca7a1e165cdffa0065455b377d2658f33f4ea2 (patch) | |
tree | 47b9cbefc77b443881b28eb8c910bb8615cb8e2d | |
parent | 4cfbf4907fa8221b7d8fcd7aa74ffd1d45691ef6 (diff) |
vendor.ids update and vendor.{h,c} improvements from sysobj version
* more fields in struct Vendor.
* match_case -> match_rule and new match rule "exact". match_rule
remains compatible with match_case for old conf format.
* matches must be "whole word" matches so "Harmony" no longer hits
for "ARM".
* Parts outside of () are checked first, so "Foo (formerly Barly)"
matches Foo before Barly, even though Barly is longer and would
otherwise match first.
* vendor_list type (a blessed GSList*) and helper functions to manage
it.
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | data/vendor.ids | 282 | ||||
-rw-r--r-- | deps/sysobj_early/include/gg_slist.h | 30 | ||||
-rw-r--r-- | deps/sysobj_early/include/strstr_word.h | 30 | ||||
-rw-r--r-- | deps/sysobj_early/src/gg_slist.c | 49 | ||||
-rw-r--r-- | deps/sysobj_early/src/strstr_word.c | 64 | ||||
-rw-r--r-- | hardinfo/vendor.c | 355 | ||||
-rw-r--r-- | includes/vendor.h | 24 |
8 files changed, 725 insertions, 118 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fd2542e..8bbf301c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/includes ${CMAKE_SOURCE_DIR}/includes/${HARDINFO_ARCH} ${CMAKE_SOURCE_DIR}/deps/uber-graph + ${CMAKE_SOURCE_DIR}/deps/sysobj_early/include ${CMAKE_BINARY_DIR} ${GTK_INCLUDE_DIRS} ${LIBSOUP_INCLUDE_DIRS} @@ -212,6 +213,12 @@ foreach (_module ${HARDINFO_MODULES}) set_target_properties(${_module} PROPERTIES PREFIX "") endforeach() +add_library(sysobj_early STATIC + deps/sysobj_early/src/gg_slist.c + deps/sysobj_early/src/strstr_word.c +) +set_target_properties(sysobj_early PROPERTIES COMPILE_FLAGS "-std=c99 -Wall -Wextra -Wno-parentheses -Wno-unused-function") + if (HARDINFO_GTK3) add_library(uber-graph STATIC deps/uber-graph/g-ring.c @@ -267,6 +274,7 @@ add_executable(hardinfo shell/loadgraph-uber.c ) target_link_libraries(hardinfo + sysobj_early uber-graph ${GTK_LIBRARIES} ${LIBSOUP_LIBRARIES} @@ -302,6 +310,7 @@ add_executable(hardinfo shell/loadgraph.c ) target_link_libraries(hardinfo + sysobj_early ${GTK_LIBRARIES} ${LIBSOUP_LIBRARIES} m diff --git a/data/vendor.ids b/data/vendor.ids index aefbc5ae..d57940ff 100644 --- a/data/vendor.ids +++ b/data/vendor.ids @@ -6,6 +6,8 @@ # name_short <shorter name> # url <url> # url_support <url> +# wikipedia [language:]<article title>[#section] +# note <short note> # ansi_color n[;n][...] # [match_string|match_string_case|match_string_exact] <match> # ... @@ -21,14 +23,16 @@ name Lenovo Group name_short Lenovo url www.lenovo.com url_support support.lenovo.com + wikipedia Lenovo ansi_color 0;97;41 match_string lenovo -# EDID vendor code: LEN + note EDID vendor: LEN match_string_exact LEN name ASUSTeK Computer name_short ASUS url www.asus.com + wikipedia Asus ansi_color 0;30;47 match_string ASUSTek match_string ASUS @@ -37,6 +41,7 @@ name ASUSTeK Computer name Advanced Micro Devices name_short AMD url www.amd.com + wikipedia Advanced Micro Devices ansi_color 0;97;41 match_string Advanced Micro Devices match_string_case AMD @@ -45,6 +50,7 @@ name Advanced Micro Devices name Advanced Micro Devices (formerly ATI) name_short AMD/ATI url www.amd.com + wikipedia ATI Technologies ansi_color 0;97;41 match_string ATI Technologies match_string Advanced Micro Devices, Inc. [AMD/ATI] @@ -54,23 +60,36 @@ name Advanced Micro Devices (formerly ATI) name nVidia Corporation name_short nVidia url www.nvidia.com + wikipedia Nvidia ansi_color 0;97;42 match_string nVidia name G.Skill International Enterprise name_short G.Skill url www.gskill.com + wikipedia G.Skill ansi_color 0;31;107 match_string G.Skill match_string G-Skill + match_string G Skill + +name XFX Pine Group + name_short XFX + url www.xfxforce.com + wikipedia XFX + ansi_color 0;30;42 + match_string_case XFX name 3Com url www.3com.com + wikipedia 3Com + ansi_color 0;97;40 match_string 3Com name Intel Corporation name_short Intel url www.intel.com + wikipedia Intel Corporation ansi_color 0;97;44 match_string Intel @@ -88,7 +107,7 @@ name NEC Corporation name_short NEC url www.nec.com ansi_color 0;94;107 -# EDID vendor code: NEC + note EDID vendor: NEC match_string_case NEC name Realtek Semiconductor @@ -103,22 +122,25 @@ name Toshiba Corporation url www.toshiba.com ansi_color 0;91;47 match_string Toshiba -# EDID vendor code: TSB + note EDID vendor: TSB match_string_exact TSB name Vizio -# EDID vendor code: VIZ + name_short VIZIO + ansi_color 0;30;107 + note EDID vendor: VIZ match_string_exact VIZ name ViewSonic Corporation name_short ViewSonic url www.viewsonic.com ansi_color 0;35;103 -# EDID vendor code: VSC + note EDID vendor: VSC match_string_exact VSC name LITE-ON url www.liteonit.com + ansi_color 0;97;104 match_string_case LITE-ON name Maxtor @@ -129,13 +151,13 @@ name Samsung url www.samsung.com ansi_color 0;47;30 match_string Samsung -# EDID vendor code: SAM + note EDID vendor: SAM match_string_exact SAM name Pioneer url www.pioneer-eur.com match_string Pioneer -# EDID vendor code: PIO + note EDID vendor: PIO match_string_exact PIO name Plextor @@ -155,13 +177,19 @@ name LG Electronics match_string Lucky-Goldstar match_string_case LG +name LG Electronics (formerly Goldstar) + name_short LG (Goldstar) + url www.lge.com + ansi_color 0;97;41 + match_string Goldstar + name LG Display name_short LG Display url www.lgdisplay.com ansi_color 0;97;41 match_string LG Display match_string LG.Philips -# EDID vendor code: LGD + note EDID vendor: LGD match_string_exact LGD name Hitachi-LG Data Storage @@ -169,12 +197,18 @@ name Hitachi-LG Data Storage url http://hlds.co.kr match_string_case HL-DT-ST +name Hitachi Global Storage Technologies + name_short HGST + url hgst.com + ansi_color 0;97;40 + match_string_case HGST + name Hitachi name_short HITACHI url www.hitachi.com ansi_color 0;30;47 match_string Hitachi -# EDID vendor code: HTC + note EDID vendor: HTC match_string_exact HTC name Lexmark @@ -185,10 +219,47 @@ name Creative Labs url www.creative.com match_string Creative Labs -name Conexant - url www.brooktree.com +name NXP Semiconductors + name_short NXP + url www.nxp.com + match_string_case NXP + +name Synaptics (formerly Brooktree) + name_short Synaptics (Brooktree) + url www.synaptics.com match_string Brooktree +name Synaptics (formerly Conexant Systems) + name_short Synaptics (Conexant) + url www.synaptics.com + match_string Conexant + +name Synaptics + url www.synaptics.com + match_string Synaptics + +name TDK-Micronas + url www.micronas.com + match_string Micronas + +name Apacer Technology + name_short Apacer + match_string Apacer + +name Bright Micron Technology + name_short BMT + match_string Bright Micron + +name HT Micron + match_string HT Micron + +name Intellitech + match_string Intellitech + +name Harmony Semiconductor + name_short Harmony + match_string Harmony + name Atheros Communications url www.atheros.com match_string Atheros @@ -198,7 +269,7 @@ name Panasonic Industry Company url www.panasonic.com ansi_color 0;30;107 match_string MATSHITA -# EDID vendor code: MEI + note EDID vendor: MEI match_string_exact MEI name Silicon Image @@ -217,7 +288,7 @@ name Apple Computer url www.apple.com ansi_color 0;97;100 match_string Apple -# EDID vendor code: APP + note EDID vendor: APP match_string_exact APP name International Business Machines Corporation @@ -233,7 +304,7 @@ name Dell Computer match_string Dell # Dell PowerEdge/PowerVault controller SCSI vendor match_string PE/PV -# EDID vendor code: DEL + note EDID vendor: DEL match_string_exact DEL name Logitech International @@ -243,7 +314,9 @@ name Logitech International match_string Logitech name Fujitsu + name_short FUJITSU url www.fujitsu.com + ansi_color 0;31;107 match_string FUJITSU name Sony @@ -252,7 +325,7 @@ name Sony ansi_color 0;30;107 match_string Sony # match_string_case CDU -# EDID vendor code: SNY + note EDID vendor: SNY match_string_exact SNY name SanDisk @@ -306,14 +379,16 @@ name Koninklijke Philips name_short PHILIPS url www.philips.com match_string Philips -# EDID vendor code: PHL + ansi_color 0;30;107 + match_string Philips + note EDID vendor: PHL match_string_exact PHL name Sharp Corporation name_short SHARP ansi_color 0;31;107 match_string Sharp -# EDID vendor code: SHP + note EDID vendor: SHP match_string_exact SHP name Ralink Technology @@ -332,9 +407,11 @@ name Hewlett-Packard url www.hp.com ansi_color 0;97;46 match_string Hewlett-Packard -# EDID vendor code: HWP - match_string_exact HWP match_string_case HP + note EDID vendor: HWP + match_string_exact HWP + note SCSI vendor: hp + match_string_exact hp name TEAC Corporation name_short TEAC @@ -363,9 +440,13 @@ name Canon name A4tech url www.a4tech.com + wikipedia A4Tech + ansi_color 0;33;40 match_string A4Tech -name Alcor +name Alcor Life Extension Foundation +# Makes devices? + name_short Alcor url www.alcor.org match_string ALCOR @@ -379,14 +460,21 @@ name Ours Technology name BenQ url www.benq.com + ansi_color 0;35;107 match_string BENQ +name Holtek Semiconductor + name_short Holtek + url www.holtek.com + ansi_color 0;34;107 + match_string Holtek + name Acer name_short acer url www.acer.com ansi_color 0;32;107 match_string Acer -# EDID vendor code: ACR + note EDID vendor: ACR match_string_exact ACR name Quantum @@ -403,6 +491,20 @@ name Chicony url www.chicony.com.tw match_string Chicony +name Phison Electronics Corporation + name_short Phison + url www.phison.com + wikipedia Phison + ansi_color 0;33;44 + match_string Phison + +name Corsair Components + name_short Corsair + url www.corsair.com + wikipedia Corsair Components + ansi_color 0;30;43 + match_string Corsair + name Genius url www.genius.ru match_string Genius @@ -434,6 +536,8 @@ name Crucial (Micron) name Toshiba Samsung Storage Technology name_short TSST url www.tsst.co.kr + wikipedia Toshiba Samsung Storage Technology + ansi_color 0;34;107 match_string_case TSST name Seagate Technology @@ -505,7 +609,7 @@ name Synopsys match_string Synopsys name Raspberry Pi Foundation - name_short RaspberryPi + name_short Raspberry Pi url www.raspberrypi.org ansi_color 0;97;42 match_string RaspberryPi @@ -517,12 +621,42 @@ name Embest Technology ansi_color 0;96;44 match_string Embest +# JEDEC mfgr [1][78] name Transcend Information name_short Transcend url transcend-info.com ansi_color 0;31;47 + match_string Transcend Information + # More likely this one is T. Information than T. Technology match_string Transcend +# JEDEC mfgr [7][105] +name Transcend Technology + name_short Transcend + match_string Transcend Technology + +# JEDEC mfgr [0][64] +name Infineon Technologies + name_short infineon + url www.infineon.com + wikipedia Infineon Technologies + ansi_color 0;34;107 + match_string Infineon + +name Cypress Semiconductor + name_short Cypress + url cypress.com + wikipedia Cypress Semiconductor + ansi_color 0;36;107 + match_string Cypress + +name Renesas Electronics + name_short Renesas + url www.renesas.com + wikipedia Renesas Electronics + ansi_color 0;97;44 + match_string Renesas + name ADATA Technology name_short ADATA ansi_color 0;34;47 @@ -555,11 +689,39 @@ name Elitegroup Computer Systems ansi_color 0;36;41 match_string_case ECS -name SANYO + +name Sanyo Electric name_short SANYO url www.sanyo.com match_string SANYO +name Cambridge Silicon Radio + name_short CSR + url www.csr.com + wikipedia Cambridge Silicon Radio + ansi_color 0;34;107 + match_string Cambridge Silicon Radio + +name Suprema + url www.supremainc.com + ansi_color 0;31;107 + match_string suprema + +name Patriot Memory + name_short Patriot + url www.patriotmemory.com + wikipedia Patriot Memory + ansi_color 0;97;44 + match_string Patriot Memory + +name SK Hynix + name_short SK hynix + url www.skhynix.com + wikipedia SK Hynix + ansi_color 0;31;43 + match_string Hynix + match_string Hyundai + # # BIOS manufacturers # @@ -614,6 +776,7 @@ name Canonical name Ubuntu url www.ubuntu.com + url_support www.ubuntu.com/support/community-support ansi_color 0;97;45 match_string ubuntu @@ -623,6 +786,46 @@ name Arch Linux ansi_color 0;36;107 match_string arch linux +name Red Hat + url www.redhat.com + ansi_color 0;31;40 + match_string Red Hat + +name Sun Microsystems + name_short Sun + wikipedia Sun Microsystems + match_string Sun Microsystems + +name Oracle Corporation + name_short Oracle + url www.oracle.com + ansi_color 0;97;41 + match_string Oracle + +name Oracle Corporation (formerly InnoTek Systemberatung) + name_short Oracle (InnoTek) + url www.virtualbox.org/wiki/innotek + url_support www.virtualbox.org + ansi_color 0;97;41 + match_string InnoTek + match_string VirtualBox + match_string_case VBOX + +name Slackware + url www.slackware.com + ansi_color 0;30;107 + match_string Slackware + +name KDE + url www.kde.org + wikipedia KDE + ansi_color 0;97;104 + match_string_case KDE + +name CDEmu + url cdemu.sourceforge.io + match_string CDEmu + # # x86 vendor strings # @@ -630,7 +833,9 @@ name Arch Linux name Advanced Micro Devices name_short AMD url www.amd.com + wikipedia Advanced Micro Devices ansi_color 0;97;41 + note x86 processor vendor ID match_string AMDisbetter! match_string AuthenticAMD @@ -639,57 +844,84 @@ name Intel Corporation url www.intel.com url_support ark.intel.com ansi_color 0;97;44 + note x86 processor vendor ID match_string GenuineIntel +name Chengdu Haiguang Integrated Circuit Design + name_short Hygon + ansi_color 0;97;104 + match_string Hygon + match_string Higon + note x86 processor vendor ID + match_string HygonGenuine + name VIA Technologies name_short VIA url www.via.tw ansi_color 0;36;107 + note x86 processor vendor ID match_string VIA VIA VIA name VIA (formerly Centaur Technology) name_short VIA (Centaur) url www.via.tw ansi_color 0;36;107 + note x86 processor vendor ID match_string CentaurHauls name VIA (formerly Cyrix) name_short VIA (Cyrix) url www.via.tw ansi_color 0;36;107 + note x86 processor vendor ID match_string CyrixInstead name Transmeta Corporation name_short Transmeta + note x86 processor vendor ID match_string TransmetaCPU match_string GenuineTMx86 name National Semiconductor name_short NSC + note x86 processor vendor ID match_string Geode by NSC name NexGen + note x86 processor vendor ID match_string NexGenDriven name Rise Technology name_short Rise + note x86 processor vendor ID match_string RiseRiseRise name Silicon Integrated Systems name_short SIS + note x86 processor vendor ID match_string SiS SiS SiS name United Microelectronics Corporation name_short UMC + note x86 processor vendor ID match_string UMC UMC UMC name DMP Electronics + note x86 processor vendor ID match_string Vortex86 SoC # # x86 VM vendor strings # +name VMware + url www.vmware.com + wikipedia VMware + ansi_color 0;90;47 + match_string VMware + note x86 VM vendor string + match_string VMwareVMware + name KVM url www.linux-kvm.org match_string KVMKVMKVM @@ -702,10 +934,6 @@ name Parallels url www.parallels.com match_string lrpepyh vr -name VMware - url www.vmware.com - match_string VMwareVMware - name Xen HVM url www.xenproject.org match_string XenVMMXenVMM diff --git a/deps/sysobj_early/include/gg_slist.h b/deps/sysobj_early/include/gg_slist.h new file mode 100644 index 00000000..255465ee --- /dev/null +++ b/deps/sysobj_early/include/gg_slist.h @@ -0,0 +1,30 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef _GG_SLIST_H_ +#define _GG_SLIST_H_ + +#include <glib.h> + +GSList *gg_slist_remove_null(GSList *sl); +GSList *gg_slist_remove_duplicates(GSList *sl); /* by pointer */ +GSList *gg_slist_remove_duplicates_custom(GSList *sl, GCompareFunc func); + +#endif diff --git a/deps/sysobj_early/include/strstr_word.h b/deps/sysobj_early/include/strstr_word.h new file mode 100644 index 00000000..f607b2ed --- /dev/null +++ b/deps/sysobj_early/include/strstr_word.h @@ -0,0 +1,30 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* versions of strstr() and strcasestr() where the match must be preceded and + * succeded by a non-alpha-numeric character. */ + +#ifndef __STRSTR_WORD_H__ +#define __STRSTR_WORD_H__ + +char *strstr_word(const char *haystack, const char *needle); +char *strcasestr_word(const char *haystack, const char *needle); + +#endif diff --git a/deps/sysobj_early/src/gg_slist.c b/deps/sysobj_early/src/gg_slist.c new file mode 100644 index 00000000..595dbc46 --- /dev/null +++ b/deps/sysobj_early/src/gg_slist.c @@ -0,0 +1,49 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <glib.h> + +GSList *gg_slist_remove_duplicates(GSList *sl) { + for (GSList *l = sl; l; l = l->next) { + GSList *d = NULL; + while(d = g_slist_find(l->next, l->data) ) + sl = g_slist_delete_link(sl, d); + } + return sl; +} + +GSList *gg_slist_remove_duplicates_custom(GSList *sl, GCompareFunc func) { + for (GSList *l = sl; l; l = l->next) { + GSList *d = NULL; + while(d = g_slist_find_custom(l->next, l->data, func) ) + sl = g_slist_delete_link(sl, d); + } + return sl; +} + +GSList *gg_slist_remove_null(GSList *sl) { + GSList *n = sl ? sl->next : NULL; + for (GSList *l = sl; l; l = n) { + n = l->next; + if (l->data == NULL) + sl = g_slist_delete_link(sl, l); + } + return sl; +} diff --git a/deps/sysobj_early/src/strstr_word.c b/deps/sysobj_early/src/strstr_word.c new file mode 100644 index 00000000..b12f01a2 --- /dev/null +++ b/deps/sysobj_early/src/strstr_word.c @@ -0,0 +1,64 @@ +/* + * sysobj - https://github.com/bp0/verbose-spork + * Copyright (C) 2018 Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* versions of strstr() and strcasestr() where the match must be preceded and + * succeded by a non-alpha-numeric character. */ + +#define _GNU_SOURCE +#include <string.h> +#include <ctype.h> + +char *strstr_word(const char *haystack, const char *needle) { + if (!haystack || !needle) + return NULL; + + char *c; + const char *p = haystack; + size_t l = strlen(needle); + while(c = strstr(p, needle)) { + const char *before = (c == haystack) ? NULL : c-1; + const char *after = c + l; + int ok = 1; + if (isalnum(*after)) ok = 0; + if (before && isalnum(*before)) ok = 0; + if (ok) return c; + p++; + } + return NULL; +} + +char *strcasestr_word(const char *haystack, const char *needle) { + if (!haystack || !needle) + return NULL; + + char *c; + const char *p = haystack; + size_t l = strlen(needle); + while(c = strcasestr(p, needle)) { + const char *before = (c == haystack) ? NULL : c-1; + const char *after = c + l; + int ok = 1; + if (isalnum(*after)) ok = 0; + if (before && isalnum(*before)) ok = 0; + if (ok) return c; + p++; + } + return NULL; +} diff --git a/hardinfo/vendor.c b/hardinfo/vendor.c index 9cc3a8e4..bd2642d8 100644 --- a/hardinfo/vendor.c +++ b/hardinfo/vendor.c @@ -25,9 +25,13 @@ #include "syncmanager.h" #include "config.h" #include "hardinfo.h" +#include "strstr_word.h" -/* { match_string, match_case, name, url } */ -static Vendor vendors[] = { +#include "dt_util.h" /* for appf() */ +#define SEQ(a,b) (g_strcmp0(a,b) == 0) + +/* { match_string, match_rule, name, url } */ +static Vendor vendors_builtin[] = { /* BIOS manufacturers */ { "American Megatrends", 0, "American Megatrends", "www.ami.com"}, { "Award", 0, "Award Software International", "www.award-bios.com"}, @@ -55,12 +59,15 @@ static Vendor vendors[] = { { "XenVMMXenVMM", 0, "Xen HVM", "" }, }; -static GSList *vendor_list = NULL; +#define ven_msg(msg, ...) fprintf (stderr, "[%s] " msg "\n", __FUNCTION__, ##__VA_ARGS__) /**/ +#define ven_msg_debug(msg, ...) DEBUG(msg, __VA_ARGS__) + +static vendor_list vendors = NULL; +const vendor_list get_vendors_list() { return vendors; } /* sort the vendor list by length of match_string, * LONGEST first */ -gint vendor_sort (gconstpointer a, gconstpointer b) { - const Vendor *ap = a, *bp = b; +int vendor_sort (const Vendor *ap, const Vendor *bp) { int la = 0, lb = 0; if (ap && ap->match_string) la = strlen(ap->match_string); if (bp && bp->match_string) lb = strlen(bp->match_string); @@ -70,34 +77,34 @@ gint vendor_sort (gconstpointer a, gconstpointer b) { } static int read_from_vendor_conf(const char *path) { - GKeyFile *vendors; + GKeyFile *vendors_file; gchar *tmp; gint num_vendors, i, count = 0; /* num_vendors is file-reported, count is actual */ DEBUG("using vendor.conf format loader for %s", path); - vendors = g_key_file_new(); - if (g_key_file_load_from_file(vendors, path, 0, NULL)) { - num_vendors = g_key_file_get_integer(vendors, "vendors", "number", NULL); + vendors_file = g_key_file_new(); + if (g_key_file_load_from_file(vendors_file, path, 0, NULL)) { + num_vendors = g_key_file_get_integer(vendors_file, "vendors", "number", NULL); for (i = num_vendors - 1; i >= 0; i--) { Vendor *v = g_new0(Vendor, 1); tmp = g_strdup_printf("vendor%d", i); - v->match_string = g_key_file_get_string(vendors, tmp, "match_string", NULL); + v->match_string = g_key_file_get_string(vendors_file, tmp, "match_string", NULL); if (v->match_string == NULL) { /* try old name */ - v->match_string = g_key_file_get_string(vendors, tmp, "id", NULL); + v->match_string = g_key_file_get_string(vendors_file, tmp, "id", NULL); } if (v->match_string) { - v->match_case = g_key_file_get_integer(vendors, tmp, "match_case", NULL); - v->name = g_key_file_get_string(vendors, tmp, "name", NULL); - v->name_short = g_key_file_get_string(vendors, tmp, "name_short", NULL); - v->url = g_key_file_get_string(vendors, tmp, "url", NULL); - v->url_support = g_key_file_get_string(vendors, tmp, "url_support", NULL); + v->match_rule = g_key_file_get_integer(vendors_file, tmp, "match_case", NULL); + v->name = g_key_file_get_string(vendors_file, tmp, "name", NULL); + v->name_short = g_key_file_get_string(vendors_file, tmp, "name_short", NULL); + v->url = g_key_file_get_string(vendors_file, tmp, "url", NULL); + v->url_support = g_key_file_get_string(vendors_file, tmp, "url_support", NULL); - vendor_list = g_slist_prepend(vendor_list, v); + vendors = g_slist_prepend(vendors, v); count++; } else { /* don't add if match_string is null */ @@ -106,36 +113,52 @@ static int read_from_vendor_conf(const char *path) { g_free(tmp); } - g_key_file_free(vendors); + g_key_file_free(vendors_file); DEBUG("... found %d match strings", count); return count; } - g_key_file_free(vendors); + g_key_file_free(vendors_file); return 0; } static int read_from_vendor_ids(const char *path) { #define VEN_BUFF_SIZE 128 #define VEN_FFWD() while(isspace((unsigned char)*p)) p++; -#define VEN_CHK(TOK) (strncmp(p, TOK, tl = strlen(TOK)) == 0) +#define VEN_CHK(TOK) (strncmp(p, TOK, tl = strlen(TOK)) == 0 && (ok = 1)) char buff[VEN_BUFF_SIZE] = ""; - char name[VEN_BUFF_SIZE] = ""; - char name_short[VEN_BUFF_SIZE] = ""; - char url[VEN_BUFF_SIZE] = ""; - char url_support[VEN_BUFF_SIZE] = ""; + + char vars[7][VEN_BUFF_SIZE]; + char *name = vars[0]; + char *name_short = vars[1]; + char *url = vars[2]; + char *url_support = vars[3]; + char *wikipedia = vars[4]; + char *note = vars[5]; + char *ansi_color = vars[6]; + int count = 0; FILE *fd; char *p, *b; - int tl; + int tl, line = -1, ok = 0; - DEBUG("using vendor.ids format loader for %s", path); + ven_msg_debug("using vendor.ids format loader for %s", path); fd = fopen(path, "r"); if (!fd) return 0; while (fgets(buff, VEN_BUFF_SIZE, fd)) { + ok = 0; + line++; + b = strchr(buff, '\n'); - if (b) *b = 0; + if (b) + *b = 0; + else + ven_msg("%s:%d: line longer than VEN_BUFF_SIZE (%lu)", path, line, (unsigned long)VEN_BUFF_SIZE); + + b = strchr(buff, '#'); + if (b) *b = 0; /* line ends at comment */ + p = buff; VEN_FFWD(); if (VEN_CHK("name ")) { @@ -143,6 +166,9 @@ static int read_from_vendor_ids(const char *path) { strcpy(name_short, ""); strcpy(url, ""); strcpy(url_support, ""); + strcpy(wikipedia, ""); + strcpy(note, ""); + strcpy(ansi_color, ""); } if (VEN_CHK("name_short ")) strncpy(name_short, p + tl, VEN_BUFF_SIZE - 1); @@ -150,40 +176,78 @@ static int read_from_vendor_ids(const char *path) { strncpy(url, p + tl, VEN_BUFF_SIZE - 1); if (VEN_CHK("url_support ")) strncpy(url_support, p + tl, VEN_BUFF_SIZE - 1); + if (VEN_CHK("wikipedia ")) + strncpy(wikipedia, p + tl, VEN_BUFF_SIZE - 1); + if (VEN_CHK("note ")) + strncpy(note, p + tl, VEN_BUFF_SIZE - 1); + if (VEN_CHK("ansi_color ")) + strncpy(ansi_color, p + tl, VEN_BUFF_SIZE - 1); + +#define dup_if_not_empty(s) (strlen(s) ? g_strdup(s) : NULL) if (VEN_CHK("match_string ")) { Vendor *v = g_new0(Vendor, 1); - v->match_string = strdup(p+tl); - v->match_case = 0; - v->name = strdup(name); - v->name_short = strdup(name_short); - v->url = strdup(url); - v->url_support = strdup(url_support); - vendor_list = g_slist_prepend(vendor_list, v); + v->file_line = line; + v->match_string = g_strdup(p+tl); + v->ms_length = strlen(v->match_string); + v->match_rule = 0; + v->name = g_strdup(name); + v->name_short = dup_if_not_empty(name_short); + v->url = dup_if_not_empty(url); + v->url_support = dup_if_not_empty(url_support); + v->wikipedia = dup_if_not_empty(wikipedia); + v->note = dup_if_not_empty(note); + v->ansi_color = dup_if_not_empty(ansi_color); + vendors = g_slist_prepend(vendors, v); count++; } if (VEN_CHK("match_string_case ")) { Vendor *v = g_new0(Vendor, 1); - v->match_string = strdup(p+tl); - v->match_case = 1; - v->name = strdup(name); - v->name_short = strdup(name_short); - v->url = strdup(url); - v->url_support = strdup(url_support); - vendor_list = g_slist_prepend(vendor_list, v); + v->file_line = line; + v->match_string = g_strdup(p+tl); + v->ms_length = strlen(v->match_string); + v->match_rule = 1; + v->name = g_strdup(name); + v->name_short = dup_if_not_empty(name_short); + v->url = dup_if_not_empty(url); + v->url_support = dup_if_not_empty(url_support); + v->wikipedia = dup_if_not_empty(wikipedia); + v->note = dup_if_not_empty(note); + v->ansi_color = dup_if_not_empty(ansi_color); + vendors = g_slist_prepend(vendors, v); + count++; + } + + if (VEN_CHK("match_string_exact ")) { + Vendor *v = g_new0(Vendor, 1); + v->file_line = line; + v->match_string = g_strdup(p+tl); + v->ms_length = strlen(v->match_string); + v->match_rule = 2; + v->name = g_strdup(name); + v->name_short = dup_if_not_empty(name_short); + v->url = dup_if_not_empty(url); + v->url_support = dup_if_not_empty(url_support); + v->wikipedia = dup_if_not_empty(wikipedia); + v->note = dup_if_not_empty(note); + v->ansi_color = dup_if_not_empty(ansi_color); + vendors = g_slist_prepend(vendors, v); count++; } + + g_strstrip(buff); + if (!ok && *buff != 0) + ven_msg("unrecognised item at %s:%d, %s", path, line, p); } fclose(fd); - DEBUG("... found %d match strings", count); + ven_msg_debug("... found %d match strings", count); return count; } - void vendor_init(void) { gchar *path; @@ -195,7 +259,7 @@ void vendor_init(void) }; /* already initialized */ - if (vendor_list) return; + if (vendors) return; DEBUG("initializing vendor list"); sync_manager_add_entry(&se); @@ -239,15 +303,15 @@ void vendor_init(void) DEBUG("vendor data not found, using internal database"); - for (i = G_N_ELEMENTS(vendors) - 1; i >= 0; i--) { - vendor_list = g_slist_prepend(vendor_list, (gpointer) &vendors[i]); + for (i = G_N_ELEMENTS(vendors_builtin) - 1; i >= 0; i--) { + vendors = g_slist_prepend(vendors, (gpointer) &vendors_builtin[i]); } } /* sort the vendor list by length of match string so that short strings are * less likely to incorrectly match. * example: ST matches ASUSTeK but SEAGATE is not ASUS */ - vendor_list = g_slist_sort(vendor_list, &vendor_sort); + vendors = g_slist_sort(vendors, (GCompareFunc)vendor_sort); /* free search location strings */ n = 0; @@ -258,43 +322,39 @@ void vendor_init(void) } void vendor_cleanup() { - DEBUG("cleanup vendor list"); - g_slist_free_full(vendor_list, (void (*)(void *))&vendor_free); + ven_msg_debug("cleanup vendor list"); + g_slist_free_full(vendors, (GDestroyNotify)vendor_free); } void vendor_free(Vendor *v) { if (v) { - free(v->name); - free(v->name_short); - free(v->url); - free(v->url_support); - free(v->match_string); - free(v); + g_free(v->name); + g_free(v->name_short); + g_free(v->url); + g_free(v->url_support); + g_free(v->ansi_color); + g_free(v->match_string); + g_free(v); } } const Vendor *vendor_match(const gchar *id_str, ...) { + Vendor *ret = NULL; va_list ap, ap2; - GSList *vlp; gchar *tmp = NULL, *p = NULL; int tl = 0, c = 0; - Vendor *ret = NULL; if (id_str) { c++; tl += strlen(id_str); - tmp = g_malloc0(tl + c + 1); - strcat(tmp, id_str); - strcat(tmp, " "); + tmp = appf(tmp, "%s", id_str); va_start(ap, id_str); p = va_arg(ap, gchar*); while(p) { c++; tl += strlen(p); - tmp = g_realloc(tmp, tl + c + 1); /* strings, spaces, null */ - strcat(tmp, p); - strcat(tmp, " "); + tmp = appf(tmp, "%s", p); p = va_arg(ap, gchar*); } va_end(ap); @@ -302,31 +362,11 @@ const Vendor *vendor_match(const gchar *id_str, ...) { if (!c || tl == 0) return NULL; - DEBUG("full id_str: %s", tmp); - - for (vlp = vendor_list; vlp; vlp = vlp->next) { - Vendor *v = (Vendor *)vlp->data; - - if (v) - if (v->match_case) { - if (v->match_string && strstr(tmp, v->match_string)) { - ret = v; - break; - } - } else { - if (v->match_string && strcasestr(tmp, v->match_string)) { - ret = v; - break; - } - } + vendor_list vl = vendors_match_core(tmp, 1); + if (vl) { + ret = (Vendor*)vl->data; + vendor_list_free(vl); } - - if (ret) - DEBUG("ret: match_string: %s -- case: %s -- name: %s", ret->match_string, (ret->match_case ? "yes" : "no"), ret->name); - else - DEBUG("ret: not found"); - - g_free(tmp); return ret; } @@ -408,3 +448,144 @@ gchar *vendor_get_link_from_vendor(const Vendor *v) return g_strdup_printf("%s (%s)", v->name, v->url); } + +vendor_list vendor_list_concat_va(int count, vendor_list vl, ...) { + vendor_list ret = vl, p = NULL; + va_list ap; + va_start(ap, vl); + if (count > 0) { + count--; /* includes vl */ + while (count) { + p = va_arg(ap, vendor_list); + ret = g_slist_concat(ret, p); + count--; + } + } else { + p = va_arg(ap, vendor_list); + while (p) { + ret = g_slist_concat(ret, p); + p = va_arg(ap, vendor_list); + } + } + va_end(ap); + return ret; +} + +vendor_list vendor_list_remove_duplicates_deep(vendor_list vl) { + /* vendor_list is GSList* */ + GSList *tvl = vl; + GSList *evl = NULL; + while(tvl) { + const Vendor *tv = tvl->data; + evl = tvl->next; + while(evl) { + const Vendor *ev = evl->data; + if ( SEQ(ev->name, tv->name) + && SEQ(ev->name_short, tv->name_short) + && SEQ(ev->ansi_color, tv->ansi_color) + && SEQ(ev->url, tv->url) + && SEQ(ev->url_support, tv->url_support) + && SEQ(ev->wikipedia, tv->wikipedia) + ) { + GSList *next = evl->next; + vl = g_slist_delete_link(vl, evl); + evl = next; + } else + evl = evl->next; + } + tvl = tvl->next; + } + return vl; +} + +vendor_list vendors_match(const gchar *id_str, ...) { + va_list ap, ap2; + gchar *tmp = NULL, *p = NULL; + int tl = 0, c = 0; + + if (id_str) { + c++; + tl += strlen(id_str); + tmp = appf(tmp, "%s", id_str); + + va_start(ap, id_str); + p = va_arg(ap, gchar*); + while(p) { + c++; + tl += strlen(p); + tmp = appf(tmp, "%s", p); + p = va_arg(ap, gchar*); + } + va_end(ap); + } + if (!c || tl == 0) + return NULL; + + return vendors_match_core(tmp, -1); +} + +vendor_list vendors_match_core(const gchar *str, int limit) { + gchar *p = NULL; + GSList *vlp; + int found = 0; + vendor_list ret = NULL; + + /* first pass (passes[1]): ignore text in (), + * like (formerly ...) or (nee ...) + * second pass (passes[0]): full text */ + gchar *passes[2] = { g_strdup(str), g_strdup(str) }; + int pass = 1; p = passes[1]; + while(p = strchr(p, '(') ) { + pass = 2; p++; + while(*p && *p != ')') { *p = ' '; p++; } + } + + for (; pass > 0; pass--) { + for (vlp = vendors; vlp; vlp = vlp->next) { + //sysobj_stats.ven_iter++; + Vendor *v = (Vendor *)vlp->data; + char *m = NULL, *s = NULL; + + if (!v) continue; + if (!v->match_string) continue; + + switch(v->match_rule) { + case 0: + if (m = strcasestr_word(passes[pass-1], v->match_string) ) { + /* clear so it doesn't match again */ + for(s = m; s < m + v->ms_length; s++) *s = ' '; + /* add to return list */ + ret = vendor_list_append(ret, v); + found++; + if (limit > 0 && found >= limit) + goto vendors_match_core_finish; + } + break; + case 1: /* match case */ + if (m = strstr_word(passes[pass-1], v->match_string) ) { + /* clear so it doesn't match again */ + for(s = m; s < m + v->ms_length; s++) *s = ' '; + /* add to return list */ + ret = vendor_list_append(ret, v); + found++; + if (limit > 0 && found >= limit) + goto vendors_match_core_finish; + } + break; + case 2: /* match exact */ + if (SEQ(passes[pass-1], v->match_string) ) { + ret = vendor_list_append(ret, v); + found++; + goto vendors_match_core_finish; /* no way for any other match to happen */ + } + break; + } + } + } + +vendors_match_core_finish: + + g_free(passes[0]); + g_free(passes[1]); + return ret; +} diff --git a/includes/vendor.h b/includes/vendor.h index 683e7d8a..f7d02998 100644 --- a/includes/vendor.h +++ b/includes/vendor.h @@ -18,16 +18,30 @@ #ifndef __VENDOR_H__ #define __VENDOR_H__ +#include "gg_slist.h" -typedef struct _Vendor Vendor; -struct _Vendor { +typedef GSList* vendor_list; +#define vendor_list_append(vl, v) g_slist_append(vl, (Vendor*)v) +#define vendor_list_concat(vl, ext) g_slist_concat(vl, ext) +vendor_list vendor_list_concat_va(int count, vendor_list vl, ...); /* count = -1 for NULL terminated list */ +#define vendor_list_free(vl) g_slist_free(vl) +#define vendor_list_remove_duplicates(vl) gg_slist_remove_duplicates(vl) +vendor_list vendor_list_remove_duplicates_deep(vendor_list vl); + +typedef struct { char *match_string; - int match_case; /* 0 = ignore case, 1 = match case */ + int match_rule; /* 0 = ignore case, 1 = match case, 2 = exact */ char *name; char *name_short; char *url; char *url_support; -}; + char *wikipedia; /* wikipedia page title (assumes en:, otherwise include langauge), usually more informative than the vendor's page */ + char *note; /* a short stored comment */ + char *ansi_color; + + unsigned long file_line; + unsigned long ms_length; +} Vendor; void vendor_init(void); void vendor_cleanup(void); @@ -39,4 +53,6 @@ gchar *vendor_get_link(const gchar *id_str); gchar *vendor_get_link_from_vendor(const Vendor *v); void vendor_free(Vendor *v); +vendor_list vendors_match_core(const gchar *str, int limit); + #endif /* __VENDOR_H__ */ |