| 12 |
12 |
| 13 |
13 |
| 14 int stringintmap_ndx(const StringIntMap *map, const char *str) |
14 int stringintmap_ndx(const StringIntMap *map, const char *str) |
| 15 { |
15 { |
| 16 int i; |
16 int i; |
| 17 |
17 |
| 18 for(i=0; map[i].string!=NULL; i++){ |
18 for(i=0; map[i].string!=NULL; i++){ |
| 19 if(strcmp(str, map[i].string)==0) |
19 if(strcmp(str, map[i].string)==0) |
| 20 return i; |
20 return i; |
| 21 } |
21 } |
| 22 |
22 |
| 23 return -1; |
23 return -1; |
| 24 } |
24 } |
| 25 |
25 |
| 26 |
26 |
| 27 int stringintmap_value(const StringIntMap *map, const char *str, int dflt) |
27 int stringintmap_value(const StringIntMap *map, const char *str, int dflt) |
| 28 { |
28 { |
| 29 int i=stringintmap_ndx(map, str); |
29 int i=stringintmap_ndx(map, str); |
| 30 return (i==-1 ? dflt : map[i].value); |
30 return (i==-1 ? dflt : map[i].value); |
| 31 } |
31 } |
| 32 |
32 |