summaryrefslogtreecommitdiff
path: root/deps
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-12-27 22:12:49 -0600
committerLeandro A. F. Pereira <leandro@hardinfo.org>2019-12-27 22:16:36 -0800
commit79d8b3c8b4f54e17b35cf82fc97af9d8be73d7dc (patch)
treec3f08fcb3f1174fb5315b1b821d247602ed40906 /deps
parent9b8122e2c3378966641568f9c12ce10a6a9ec45c (diff)
usb: vendor tags in list
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'deps')
-rw-r--r--deps/sysobj_early/include/format_early.h3
-rw-r--r--deps/sysobj_early/src/format_early.c30
2 files changed, 32 insertions, 1 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;
+}