From c26ccaba3d96aa9b463ac27cc6f02d2b4e30b979 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Thu, 5 Jun 2014 22:18:28 +0100 Subject: [PATCH] util: allow conversion from strtab to htsmsg (suitable for idnode enum) --- src/hts_strtab.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hts_strtab.h b/src/hts_strtab.h index 38d47bcc..8024f991 100644 --- a/src/hts_strtab.h +++ b/src/hts_strtab.h @@ -19,6 +19,8 @@ #ifndef STRTAB_H_ #define STRTAB_H_ +#include "htsmsg.h" + #include struct strtab { @@ -77,4 +79,20 @@ val2str0(int val, const struct strtab tab[], int l) #define val2str(val, tab) val2str0(val, tab, sizeof(tab) / sizeof(tab[0])) +static inline htsmsg_t * +strtab2htsmsg0(const struct strtab tab[], int n) +{ + int i; + htsmsg_t *e, *l = htsmsg_create_list(); + for (i = 0; i < n; i++) { + e = htsmsg_create_map(); + htsmsg_add_s32(e, "key", tab[i].val); + htsmsg_add_str(e, "val", tab[i].str); + htsmsg_add_msg(l, NULL, e); + } + return l; +} + +#define strtab2htsmsg(tab) strtab2htsmsg0(tab, sizeof(tab) / sizeof(tab[0])) + #endif /* STRTAB_H_ */