map.c

Sat, 05 Apr 2003 22:32:55 +0200

author
tuomov
date
Sat, 05 Apr 2003 22:32:55 +0200
changeset 51
2d95d77aa954
parent 49
755bdb97a607
child 53
f8f9366b359c
permissions
-rw-r--r--

trunk: changeset 55
stringintmap_value added

34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
1 /*
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
2 * libtu/map.c
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
3 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 34
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
5 * See the included file LICENSE for details.
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
6 */
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
7
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
8 #include <string.h>
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
9 #include <libtu/map.h>
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
10
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
11
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
12 int stringintmap_ndx(const StringIntMap *map, const char *str)
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
13 {
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
14 int i;
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
15
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
16 for(i=0; map[i].string!=NULL; i++){
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
17 if(strcmp(str, map[i].string)==0)
51
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
18 return i;
34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
19 }
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
20
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
21 return -1;
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
22 }
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
23
51
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
24
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
25 int stringintmap_value(const StringIntMap *map, const char *str, int dflt)
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
26 {
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
27 int i=stringintmap_ndx(map, str);
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
28 return (i==-1 ? dflt : map[i].value);
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
29 }
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
30

mercurial