Merge pull request #4011 from fritsch/vdpau-settings
[vuplus_xbmc] / lib / libhts / hts_strtab.h
1 /*
2  *  tvheadend
3  *  Copyright (C) 2007 Andreas Ă–man
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  as published by the Free Software Foundation; either version 2
8  *  of the License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef STRTAB_H_
21 #define STRTAB_H_
22
23 #include <strings.h>
24
25 struct strtab {
26   const char *str;
27   int val;
28 };
29
30 static int str2val0(const char *str, struct strtab tab[], int l)
31      __attribute((unused));
32
33 static int
34 str2val0(const char *str, struct strtab tab[], int l)
35 {
36   int i;
37   for(i = 0; i < l; i++)
38     if(!strcasecmp(str, tab[i].str))
39       return tab[i].val;
40
41   return -1;
42 }
43
44 #define str2val(str, tab) str2val0(str, tab, sizeof(tab) / sizeof(tab[0]))
45
46 static const char * val2str0(int val, struct strtab tab[], int l)
47      __attribute__((unused));
48
49 static const char *
50 val2str0(int val, struct strtab tab[], int l)
51 {
52   int i;
53   for(i = 0; i < l; i++)
54     if(tab[i].val == val)
55       return tab[i].str;
56   return NULL;
57
58
59 #define val2str(val, tab) val2str0(val, tab, sizeof(tab) / sizeof(tab[0]))
60
61 #endif /* STRTAB_H_ */