drivers/option: Add forms in cbtables
[coreboot2.git] / util / cbfstool / flashmap / valstr.c
blob32c318c3506431599c9c8b5f7b5cb4827b6eea41
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <inttypes.h>
4 #include <string.h>
5 #include <strings.h>
7 #include <valstr.h>
9 const char *val2str_default(uint32_t val, const struct valstr *vs,
10 const char *def_str)
12 int i;
14 for (i = 0; vs[i].str; i++) {
15 if (vs[i].val == val)
16 return vs[i].str;
19 return def_str;
22 const char *val2str(uint32_t val, const struct valstr *vs)
24 return val2str_default(val, vs, "Unknown");
27 uint32_t str2val(const char *str, const struct valstr *vs)
29 int i;
31 for (i = 0; vs[i].str; i++) {
32 if (strcasecmp(vs[i].str, str) == 0)
33 return vs[i].val;
36 return vs[i].val;