remove unneeded file
[enigma2.git] / lib / base / encoding.cpp
1 #include <lib/base/encoding.h>
2 #include <lib/base/eerror.h>
3
4 eDVBTextEncodingHandler encodingHandler;  // the one and only instance
5
6 inline char toupper(char c)
7 {
8         switch (c)
9         {
10                 case 'a' ... 'z':
11                         return c-32;
12         }
13         return c;
14 }
15
16 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
17 {
18         const char * file=DATADIR "/enigma2/encoding.conf";
19         FILE *f = fopen(file, "rt");
20         if (f)
21         {
22                 char *line = (char*) malloc(256);
23                 size_t bufsize=256;
24                 char countrycode[256];
25                 while( getline(&line, &bufsize, f) != -1 )
26                 {
27                         if ( line[0] == '#' )
28                                 continue;
29                         int tsid, onid, encoding;
30                         if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
31                         {
32                                 m_CountryCodeDefaultMapping[countrycode]=encoding;
33                                 countrycode[0]=toupper(countrycode[0]);
34                                 countrycode[1]=toupper(countrycode[1]);
35                                 countrycode[2]=toupper(countrycode[2]);
36                                 m_CountryCodeDefaultMapping[countrycode]=encoding;
37                         }
38                         else if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
39                                         ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
40                                 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
41                         else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
42                                         ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
43                                 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
44                         else
45                                 eDebug("couldn't parse %s", line);
46                 }
47                 fclose(f);
48                 free(line);
49         }
50         else
51                 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file);
52 }
53
54 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
55 {
56         std::map<int, int>::iterator it =
57                 m_TransponderDefaultMapping.find(tsidonid);
58         if ( it != m_TransponderDefaultMapping.end() )
59                 table = it->second;
60 }
61
62 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
63 {
64         return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
65 }
66
67 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
68 {
69         std::map<std::string, int>::iterator it =
70                 m_CountryCodeDefaultMapping.find(country_code);
71         if ( it != m_CountryCodeDefaultMapping.end() )
72                 return it->second;
73         return 0;  // ISO8859-1 / Latin1
74 }