3 #include <lib/base/encoding.h>
4 #include <lib/base/eerror.h>
5 #include <lib/base/eenv.h>
7 eDVBTextEncodingHandler encodingHandler; // the one and only instance
8 int defaultEncodingTable = 1; // ISO8859-1 / Latin1
10 inline char toupper(char c)
12 return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c;
15 inline char tolower(char c)
17 return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
20 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
22 std::string file = eEnv::resolve("${datadir}/enigma2/encoding.conf");
23 FILE *f = fopen(file.c_str(), "rt");
26 char *line = (char*) malloc(256);
28 char countrycode[256];
29 while( getline(&line, &bufsize, f) != -1 )
33 int tsid, onid, encoding;
34 if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
35 ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
36 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
37 else if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
39 m_CountryCodeDefaultMapping[countrycode]=encoding;
40 countrycode[0]=toupper(countrycode[0]);
41 countrycode[1]=toupper(countrycode[1]);
42 countrycode[2]=toupper(countrycode[2]);
43 m_CountryCodeDefaultMapping[countrycode]=encoding;
45 else if ( (sscanf( line, "0x%x 0x%x ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6937 )
46 ||(sscanf( line, "%d %d ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6937 ) )
47 m_TransponderDefaultMapping[(tsid<<16)|onid]=0;
48 else if ( sscanf( line, "%s ISO%d", countrycode, &encoding ) == 2 && encoding == 6937 )
50 m_CountryCodeDefaultMapping[countrycode]=0;
51 countrycode[0]=toupper(countrycode[0]);
52 countrycode[1]=toupper(countrycode[1]);
53 countrycode[2]=toupper(countrycode[2]);
54 m_CountryCodeDefaultMapping[countrycode]=0;
56 else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
57 ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
58 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
60 eDebug("couldn't parse %s", line);
66 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file.c_str());
69 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
71 std::map<unsigned int, int>::iterator it =
72 m_TransponderDefaultMapping.find(tsidonid);
73 if ( it != m_TransponderDefaultMapping.end() )
77 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
79 return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
82 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
84 std::map<std::string, int>::iterator it =
85 m_CountryCodeDefaultMapping.find(country_code);
86 if ( it != m_CountryCodeDefaultMapping.end() )
88 return defaultEncodingTable;