2 #include <lib/base/encoding.h>
3 #include <lib/base/eerror.h>
5 eDVBTextEncodingHandler encodingHandler; // the one and only instance
7 inline char toupper(char c)
17 eDVBTextEncodingHandler::eDVBTextEncodingHandler()
19 const char * file=DATADIR "/enigma2/encoding.conf";
20 FILE *f = fopen(file, "rt");
23 char *line = (char*) malloc(256);
25 char countrycode[256];
26 while( getline(&line, &bufsize, f) != -1 )
30 int tsid, onid, encoding;
31 if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
32 ||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
33 m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
34 else if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
36 m_CountryCodeDefaultMapping[countrycode]=encoding;
37 countrycode[0]=toupper(countrycode[0]);
38 countrycode[1]=toupper(countrycode[1]);
39 countrycode[2]=toupper(countrycode[2]);
40 m_CountryCodeDefaultMapping[countrycode]=encoding;
42 else if ( (sscanf( line, "0x%x 0x%x ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 )
43 ||(sscanf( line, "%d %d ISO%d", &tsid, &onid, &encoding ) == 3 && encoding == 6397 ) )
44 m_TransponderDefaultMapping[(tsid<<16)|onid]=64;
45 else if ( sscanf( line, "%s ISO%d", countrycode, &encoding ) == 2 && encoding == 6397 )
47 m_CountryCodeDefaultMapping[countrycode]=64;
48 countrycode[0]=toupper(countrycode[0]);
49 countrycode[1]=toupper(countrycode[1]);
50 countrycode[2]=toupper(countrycode[2]);
51 m_CountryCodeDefaultMapping[countrycode]=64;
53 else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
54 ||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
55 m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
57 eDebug("couldn't parse %s", line);
63 eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file);
66 void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
68 std::map<int, int>::iterator it =
69 m_TransponderDefaultMapping.find(tsidonid);
70 if ( it != m_TransponderDefaultMapping.end() )
74 bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
76 return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
79 int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
81 std::map<std::string, int>::iterator it =
82 m_CountryCodeDefaultMapping.find(country_code);
83 if ( it != m_CountryCodeDefaultMapping.end() )
85 return 0; // ISO8859-1 / Latin1