3 #include <lib/base/encoding.h>
4 #include <lib/base/eerror.h>
6 eDVBTextEncodingHandler encodingHandler; // the one and only instance
8 inline char toupper(char c)
18 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
20 const char * file=DATADIR "/enigma2/encoding.conf";
21 FILE *f = fopen(file, "rt");
24 char *line = (char*) malloc(256);
26 char countrycode[256];
27 while( getline(&line, &bufsize, f) != -1 )
31 int tsid, onid, encoding;
32 if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
33 ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
34 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
35 else if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
37 m_CountryCodeDefaultMapping[countrycode]=encoding;
38 countrycode[0]=toupper(countrycode[0]);
39 countrycode[1]=toupper(countrycode[1]);
40 countrycode[2]=toupper(countrycode[2]);
41 m_CountryCodeDefaultMapping[countrycode]=encoding;
43 else if ( (sscanf( line, "0x%x 0x%x ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 )
44 ||(sscanf( line, "%d %d ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 ) )
45 m_TransponderDefaultMapping[(tsid<<16)|onid]=0;
46 else if ( sscanf( line, "%s ISO%d", countrycode, &encoding ) == 2 && encoding == 6397 )
48 m_CountryCodeDefaultMapping[countrycode]=0;
49 countrycode[0]=toupper(countrycode[0]);
50 countrycode[1]=toupper(countrycode[1]);
51 countrycode[2]=toupper(countrycode[2]);
52 m_CountryCodeDefaultMapping[countrycode]=0;
54 else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
55 ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
56 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
58 eDebug("couldn't parse %s", line);
64 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file);
67 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
69 std::map<int, int>::iterator it =
70 m_TransponderDefaultMapping.find(tsidonid);
71 if ( it != m_TransponderDefaultMapping.end() )
75 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
77 return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
80 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
82 std::map<std::string, int>::iterator it =
83 m_CountryCodeDefaultMapping.find(country_code);
84 if ( it != m_CountryCodeDefaultMapping.end() )
86 return 1; // ISO8859-1 / Latin1