util: allow conversion from strtab to htsmsg (suitable for idnode enum)
This commit is contained in:
parent
b5f9979852
commit
c26ccaba3d
1 changed files with 18 additions and 0 deletions
|
@ -19,6 +19,8 @@
|
||||||
#ifndef STRTAB_H_
|
#ifndef STRTAB_H_
|
||||||
#define STRTAB_H_
|
#define STRTAB_H_
|
||||||
|
|
||||||
|
#include "htsmsg.h"
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
struct strtab {
|
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]))
|
#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_ */
|
#endif /* STRTAB_H_ */
|
||||||
|
|
Loading…
Add table
Reference in a new issue