diff options
| author | Burt P <pburt0@gmail.com> | 2018-10-04 18:44:38 -0500 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2018-11-04 15:02:12 -0800 | 
| commit | c98b4d5f8254882df4ddc96df406de8d45263e99 (patch) | |
| tree | 4e3e38e61f6710e7b5080be3270eeb1d1380e72c /hardinfo/vendor.c | |
| parent | 2316b80c4322e7ab3cb248be6ba72402fa108cff (diff) | |
devices: get_motherboard(), shorten vendor if possible
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'hardinfo/vendor.c')
| -rw-r--r-- | hardinfo/vendor.c | 34 | 
1 files changed, 30 insertions, 4 deletions
diff --git a/hardinfo/vendor.c b/hardinfo/vendor.c index 7646001c..b52943ec 100644 --- a/hardinfo/vendor.c +++ b/hardinfo/vendor.c @@ -330,9 +330,10 @@ const Vendor *vendor_match(const gchar *id_str, ...) {      return ret;  } -const gchar *vendor_get_name(const gchar * id_str) +static const gchar *vendor_get_name_ex(const gchar * id_str, short shortest)  {      GSList *vendor; +    int found = 0;      if (!id_str)          return NULL; @@ -340,20 +341,45 @@ const gchar *vendor_get_name(const gchar * id_str)      for (vendor = vendor_list; vendor; vendor = vendor->next) {          Vendor *v = (Vendor *)vendor->data; -        if (v) +        if (v) {              if (v->match_case) {                  if (v->match_string && strstr(id_str, v->match_string)) -                    return v->name; +                    found = 1;              } else {                  if (v->match_string && strcasestr(id_str, v->match_string)) -                    return v->name; +                    found = 1;              } +            if (found) { +                if (shortest) { +                    int sl = strlen(id_str); +                    int nl = (v->name) ? strlen(v->name) : 0; +                    int snl = (v->name_short) ? strlen(v->name_short) : 0; +                    if (!nl) nl = 9999; +                    if (!snl) snl = 9999; +                    /* if id_str is shortest, then return null as if nothing +                     * was found */ +                    if (nl <= snl) +                        return (sl <= nl) ? NULL : v->name; +                    else +                        return (sl <= snl) ? NULL : v->name_short; +                } else +                    return v->name; +            } +        }      }      return id_str; /* What about const? */  } +const gchar *vendor_get_name(const gchar * id_str) { +    return vendor_get_name_ex(id_str, 0); +} + +const gchar *vendor_get_shortest_name(const gchar * id_str) { +    return vendor_get_name_ex(id_str, 1); +} +  const gchar *vendor_get_url(const gchar * id_str)  {      GSList *vendor;  | 
