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
9 inline char toupper(char c)
19 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
21 std::string file = eEnv::resolve("${datadir}/enigma2/encoding.conf");
22 FILE *f = fopen(file.c_str(), "rt");
25 char *line = (char*) malloc(256);
27 char countrycode[256];
28 while( getline(&line, &bufsize, f) != -1 )
32 int tsid, onid, encoding;
33 if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
34 ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
35 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
36 else if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
38 m_CountryCodeDefaultMapping[countrycode]=encoding;
39 countrycode[0]=toupper(countrycode[0]);
40 countrycode[1]=toupper(countrycode[1]);
41 countrycode[2]=toupper(countrycode[2]);
42 m_CountryCodeDefaultMapping[countrycode]=encoding;
44 else if ( (sscanf( line, "0x%x 0x%x ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 )
45 ||(sscanf( line, "%d %d ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 ) )
46 m_TransponderDefaultMapping[(tsid<<16)|onid]=0;
47 else if ( sscanf( line, "%s ISO%d", countrycode, &encoding ) == 2 && encoding == 6397 )
49 m_CountryCodeDefaultMapping[countrycode]=0;
50 countrycode[0]=toupper(countrycode[0]);
51 countrycode[1]=toupper(countrycode[1]);
52 countrycode[2]=toupper(countrycode[2]);
53 m_CountryCodeDefaultMapping[countrycode]=0;
55 else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
56 ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
57 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
59 eDebug("couldn't parse %s", line);
65 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file.c_str());
68 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
70 std::map<int, int>::iterator it =
71 m_TransponderDefaultMapping.find(tsidonid);
72 if ( it != m_TransponderDefaultMapping.end() )
76 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
78 return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
81 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
83 std::map<std::string, int>::iterator it =
84 m_CountryCodeDefaultMapping.find(country_code);
85 if ( it != m_CountryCodeDefaultMapping.end() )
87 return 1; // ISO8859-1 / Latin1