1 /*
2  * slookup.c - static lookup of character sets.
3  */
4 
5 #include "charset.h"
6 #include "internal.h"
7 
8 #define ENUM_CHARSET(x) extern charset_spec const charset_##x;
9 #include "enum.c"
10 #undef ENUM_CHARSET
11 
12 static charset_spec const *const cs_table[] = {
13 
14 #define ENUM_CHARSET(x) &charset_##x,
15 #include "enum.c"
16 #undef ENUM_CHARSET
17 
18 };
19 
charset_find_spec(int charset)20 charset_spec const *charset_find_spec(int charset)
21 {
22     int i;
23 
24     for (i = 0; i < (int)lenof(cs_table); i++)
25 	if (cs_table[i]->charset == charset)
26 	    return cs_table[i];
27 
28     return NULL;
29 }
30 
charset_exists(int charset)31 int charset_exists(int charset)
32 {
33     return charset_find_spec(charset) != NULL;
34 }
35 
charset_is_single_byte(int charset)36 int charset_is_single_byte(int charset)
37 {
38     charset_spec const *spec = charset_find_spec(charset);
39     return spec && spec->read == read_sbcs;
40 }
41