map.c

Tue, 16 Mar 2004 21:35:13 +0100

author
tuomov
date
Tue, 16 Mar 2004 21:35:13 +0100
changeset 70
e866dc825481
parent 62
aae5facf9fc5
child 75
725a7187c6ff
permissions
-rw-r--r--

trunk: changeset 1408
Changed include directives to reflect change in locations of headers.

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.
53
f8f9366b359c trunk: changeset 57
tuomov
parents: 51
diff changeset
5 *
f8f9366b359c trunk: changeset 57
tuomov
parents: 51
diff changeset
6 * You may distribute and modify this library under the terms of either
f8f9366b359c trunk: changeset 57
tuomov
parents: 51
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
8 */
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
9
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
10 #include <string.h>
70
e866dc825481 trunk: changeset 1408
tuomov
parents: 62
diff changeset
11 #include "map.h"
34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
12
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
13
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
14 int stringintmap_ndx(const StringIntMap *map, const char *str)
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
15 {
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
16 int i;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
17
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
18 for(i=0; map[i].string!=NULL; i++){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
19 if(strcmp(str, map[i].string)==0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
20 return i;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
21 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
22
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
23 return -1;
34
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
24 }
828f3afd5c76 trunk: changeset 37
tuomov
parents:
diff changeset
25
51
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
26
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
27 int stringintmap_value(const StringIntMap *map, const char *str, int dflt)
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
28 {
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
29 int i=stringintmap_ndx(map, str);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
30 return (i==-1 ? dflt : map[i].value);
51
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
31 }
2d95d77aa954 trunk: changeset 55
tuomov
parents: 49
diff changeset
32

mercurial