map.c

Mon, 17 Jan 2005 22:02:09 +0100

author
tuomov
date
Mon, 17 Jan 2005 22:02:09 +0100
changeset 85
9f94b2e96e3b
parent 76
58280b944cda
permissions
-rw-r--r--

trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.

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
75
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
33
76
58280b944cda trunk: changeset 1585
tuomov
parents: 75
diff changeset
34 const char *stringintmap_key(const StringIntMap *map, int value,
58280b944cda trunk: changeset 1585
tuomov
parents: 75
diff changeset
35 const char *dflt)
75
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
36 {
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
37 int i;
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
38
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
39 for(i=0; map[i].string!=NULL; ++i){
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
40 if(map[i].value==value){
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
41 return map[i].string;
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
42 }
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
43 }
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
44
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
45 return dflt;
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
46
725a7187c6ff trunk: changeset 1583
tuomov
parents: 70
diff changeset
47 }

mercurial