From: Adam Sutton Date: Thu, 5 Jun 2014 21:18:28 +0000 (+0100) Subject: util: allow conversion from strtab to htsmsg (suitable for idnode enum) X-Git-Tag: v4.1~1997 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c26ccaba3d96aa9b463ac27cc6f02d2b4e30b979;p=thirdparty%2Ftvheadend.git util: allow conversion from strtab to htsmsg (suitable for idnode enum) --- diff --git a/src/hts_strtab.h b/src/hts_strtab.h index 38d47bcce..8024f9913 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_ */