diff options
| author | Burt P <pburt0@gmail.com> | 2019-12-27 22:12:49 -0600 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-12-27 22:16:36 -0800 | 
| commit | 79d8b3c8b4f54e17b35cf82fc97af9d8be73d7dc (patch) | |
| tree | c3f08fcb3f1174fb5315b1b821d247602ed40906 | |
| parent | 9b8122e2c3378966641568f9c12ce10a6a9ec45c (diff) | |
usb: vendor tags in list
Signed-off-by: Burt P <pburt0@gmail.com>
| -rw-r--r-- | deps/sysobj_early/include/format_early.h | 3 | ||||
| -rw-r--r-- | deps/sysobj_early/src/format_early.c | 30 | ||||
| -rw-r--r-- | hardinfo/usb_util.c | 9 | ||||
| -rw-r--r-- | includes/usb_util.h | 2 | ||||
| -rw-r--r-- | modules/devices/usb.c | 7 | 
5 files changed, 48 insertions, 3 deletions
diff --git a/deps/sysobj_early/include/format_early.h b/deps/sysobj_early/include/format_early.h index 871d173f..e5524e26 100644 --- a/deps/sysobj_early/include/format_early.h +++ b/deps/sysobj_early/include/format_early.h @@ -25,6 +25,7 @@  #include <strings.h>  #include "appf.h"  #include "util_sysobj.h" +#include "vendor.h"  enum {      FMT_OPT_NONE   = 0, @@ -41,4 +42,6 @@ gchar *format_with_ansi_color(const gchar *str, const gchar *ansi_color, int fmt  void tag_vendor(gchar **str, guint offset, const gchar *vendor_str, const char *ansi_color, int fmt_opts);  gchar *vendor_match_tag(const gchar *vendor_str, int fmt_opts); +gchar *vendor_list_ribbon(const vendor_list vl_in, int fmt_opts); +  #endif diff --git a/deps/sysobj_early/src/format_early.c b/deps/sysobj_early/src/format_early.c index bc5883cc..5f191d60 100644 --- a/deps/sysobj_early/src/format_early.c +++ b/deps/sysobj_early/src/format_early.c @@ -19,7 +19,6 @@   */  #include "format_early.h" -#include "vendor.h"  #define ANSI_COLOR_RESET   "\x1b[0m" @@ -128,3 +127,32 @@ gchar *vendor_match_tag(const gchar *vendor_str, int fmt_opts) {      }      return NULL;  } + +gchar *vendor_list_ribbon(const vendor_list vl_in, int fmt_opts) { +    gchar *ret = NULL; +    vendor_list vl = g_slist_copy(vl_in); /* shallow is fine */ +    vl = vendor_list_remove_duplicates(vl); +    if (vl) { +        GSList *l = vl, *n = l ? l->next : NULL; +        /* replace each vendor with the vendor tag */ +        for(; l; l = n) { +            n = l->next; +            const Vendor *v = l->data; +            if (!v) { +                vl = g_slist_delete_link(vl, l); +                continue; +            } +            gchar *ven_tag = v->name_short ? g_strdup(v->name_short) : g_strdup(v->name); +            if(ven_tag) { +                tag_vendor(&ven_tag, 0, ven_tag, v->ansi_color, fmt_opts); +                l->data = ven_tag; +            } +        } +        /* vl is now a regular GSList of formatted vendor tag strings */ +        vl = gg_slist_remove_duplicates_custom(vl, (GCompareFunc)g_strcmp0); +        for(l = vl; l; l = l->next) +            ret = appfsp(ret, "%s", (gchar*)l->data); +    } +    g_slist_free_full(vl, g_free); +    return ret; +} diff --git a/hardinfo/usb_util.c b/hardinfo/usb_util.c index f883657c..8b73332f 100644 --- a/hardinfo/usb_util.c +++ b/hardinfo/usb_util.c @@ -58,6 +58,7 @@ usbd *usbd_new() {  void usbd_free(usbd *s) {      if (s) {          usbi_list_free(s->if_list); +        vendor_list_free(s->vendors);          g_free(s->vendor);          g_free(s->product);          g_free(s->manufacturer); @@ -517,11 +518,17 @@ static usbd *usb_get_device_list_sysfs() {  }  usbd *usb_get_device_list() { -    usbd *lst; +    usbd *lst, *l;      lst = usb_get_device_list_sysfs();      if (lst == NULL)          lst = usb_get_device_list_lsusb(); +    l = lst; +    while(l) { +        l->vendors = vendor_list_remove_duplicates_deep(vendors_match(l->vendor, l->manufacturer, NULL)); +        l = l->next; +    } +      return lst;  } diff --git a/includes/usb_util.h b/includes/usb_util.h index 045f07e4..ed752449 100644 --- a/includes/usb_util.h +++ b/includes/usb_util.h @@ -43,6 +43,8 @@ typedef struct usbd {      int speed_mbs; +    vendor_list vendors; +      gboolean user_scan; /* not scanned as root */      struct usbi *if_list; diff --git a/modules/devices/usb.c b/modules/devices/usb.c index ca4014ee..c00f3330 100644 --- a/modules/devices/usb.c +++ b/modules/devices/usb.c @@ -109,7 +109,12 @@ static void _usb_dev(const usbd *u) {      manufacturer = UNKIFNULL_AC(u->manufacturer);      device = UNKIFNULL_AC(u->device); -    name = g_strdup_printf("%s %s", u->vendor? vendor: manufacturer, u->product? product: device); +    if (u->vendors) { +        gchar *ribbon = vendor_list_ribbon(u->vendors, params.fmt_opts); +        name = g_strdup_printf("%s %s", ribbon, u->product? product: device); +    } else { +        name = g_strdup_printf("%s %s", u->vendor? vendor: manufacturer, u->product? product: device); +    }      key = g_strdup_printf("USB%03d:%03d:%03d", u->bus, u->dev, 0);      label = g_strdup_printf("%03d:%03d", u->bus, u->dev);      icon = get_usbdev_icon(u);  | 
