1 | /* |
---|
2 | * Copyright (C) 2002, 2004 Mike Wray <mike.wray@hp.com> |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU Lesser General Public License as |
---|
6 | * published by the Free Software Foundation; either version 2.1 of the |
---|
7 | * License, or (at your option) any later version. This library is |
---|
8 | * distributed in the hope that it will be useful, but WITHOUT ANY |
---|
9 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
10 | * FITNESS FOR A PARTICULAR PURPOSE. |
---|
11 | * See the GNU Lesser General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU Lesser General Public License |
---|
14 | * along with this library; if not, write to the Free Software Foundation, |
---|
15 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
16 | */ |
---|
17 | |
---|
18 | #ifdef __KERNEL__ |
---|
19 | #include <linux/errno.h> |
---|
20 | #else |
---|
21 | #include <errno.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include "sys_string.h" |
---|
25 | #include "enum.h" |
---|
26 | |
---|
27 | /** Map an enum name to its value using a table. |
---|
28 | * |
---|
29 | * @param name enum name |
---|
30 | * @param defs enum definitions |
---|
31 | * @return enum value or -1 if not known |
---|
32 | */ |
---|
33 | int enum_name_to_val(char *name, EnumDef *defs){ |
---|
34 | int val = -1; |
---|
35 | for(; defs->name; defs++){ |
---|
36 | if(!strcmp(defs->name, name)){ |
---|
37 | val = defs->val; |
---|
38 | break; |
---|
39 | } |
---|
40 | } |
---|
41 | return val; |
---|
42 | } |
---|
43 | |
---|
44 | /** Map an enum value to its name using a table. |
---|
45 | * |
---|
46 | * @param val enum value |
---|
47 | * @param defs enum definitions |
---|
48 | * @param defs_n number of definitions |
---|
49 | * @return enum name or NULL if not known |
---|
50 | */ |
---|
51 | char *enum_val_to_name(int val, EnumDef *defs){ |
---|
52 | char *name = NULL; |
---|
53 | for(; defs->name; defs++){ |
---|
54 | if(val == defs->val){ |
---|
55 | name = defs->name; |
---|
56 | break; |
---|
57 | } |
---|
58 | } |
---|
59 | return name; |
---|
60 | } |
---|
61 | |
---|