diff options
author | Burt P <pburt0@gmail.com> | 2018-10-04 20:53:07 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2018-11-04 15:02:12 -0800 |
commit | 8546e4b64bf2e05613c26d1e7f797adabe23481a (patch) | |
tree | ecc7f9db4f68e25b883ebc5e9848e3e5e49e7cac /hardinfo/vendor.c | |
parent | c98b4d5f8254882df4ddc96df406de8d45263e99 (diff) |
vendor.c: remove duplicate code, use vendor_match(), make *_name() result consistent
Following the old behavior of returning the passed-in string if not found.
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'hardinfo/vendor.c')
-rw-r--r-- | hardinfo/vendor.c | 78 |
1 files changed, 21 insertions, 57 deletions
diff --git a/hardinfo/vendor.c b/hardinfo/vendor.c index b52943ec..e5ab6951 100644 --- a/hardinfo/vendor.c +++ b/hardinfo/vendor.c @@ -330,46 +330,26 @@ const Vendor *vendor_match(const gchar *id_str, ...) { return ret; } -static const gchar *vendor_get_name_ex(const gchar * id_str, short shortest) -{ - GSList *vendor; - int found = 0; - - if (!id_str) - return NULL; +static const gchar *vendor_get_name_ex(const gchar * id_str, short shortest) { + const Vendor *v = vendor_match(id_str, NULL); - for (vendor = vendor_list; vendor; vendor = vendor->next) { - Vendor *v = (Vendor *)vendor->data; - - if (v) { - if (v->match_case) { - if (v->match_string && strstr(id_str, v->match_string)) - found = 1; - } else { - if (v->match_string && strcasestr(id_str, v->match_string)) - 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; - } - } + if (v) { + 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 as if not found (see below) */ + if (nl <= snl) + return (sl <= nl) ? id_str : v->name; + else + return (sl <= snl) ? id_str : v->name_short; + } else + return v->name; } - return id_str; /* What about const? */ + return id_str; /* Preserve an old behavior, but what about const? */ } const gchar *vendor_get_name(const gchar * id_str) { @@ -380,27 +360,11 @@ 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; - - if (!id_str) { - return NULL; - } - - for (vendor = vendor_list; vendor; vendor = vendor->next) { - Vendor *v = (Vendor *)vendor->data; - - if (v) - if (v->match_case) { - if (v->match_string && strstr(id_str, v->match_string)) - return v->url; - } else { - if (v->match_string && strcasestr(id_str, v->match_string)) - return v->url; - } +const gchar *vendor_get_url(const gchar * id_str) { + const Vendor *v = vendor_match(id_str, NULL); - } + if (v) + return v->url; return NULL; } |