| 1 |
|
| 2 |
|
| 3 |
#include <inttypes.h> |
| 4 |
#include <string.h> |
| 5 |
#include <strings.h> |
| 6 |
|
| 7 |
#include <valstr.h> |
| 8 |
|
| 9 |
const char *val2str_default(uint32_t val, const struct valstr *vs, |
| 10 |
const char *def_str) |
| 11 |
{ |
| 12 |
int i; |
| 13 |
|
| 14 |
for (i = 0; vs[i].str; i++) { |
| 15 |
if (vs[i].val == val) |
| 16 |
return vs[i].str; |
| 17 |
} |
| 18 |
|
| 19 |
return def_str; |
| 20 |
} |
| 21 |
|
| 22 |
const char *val2str(uint32_t val, const struct valstr *vs) |
| 23 |
{ |
| 24 |
return val2str_default(val, vs, "Unknown"); |
| 25 |
} |
| 26 |
|
| 27 |
uint32_t str2val(const char *str, const struct valstr *vs) |
| 28 |
{ |
| 29 |
int i; |
| 30 |
|
| 31 |
for (i = 0; vs[i].str; i++) { |
| 32 |
if (strcasecmp(vs[i].str, str) == 0) |
| 33 |
return vs[i].val; |
| 34 |
} |
| 35 |
|
| 36 |
return vs[i].val; |
| 37 |
} |