aboutsummaryrefslogtreecommitdiff
path: root/lib/base/encoding.cpp
blob: e865169913ac8663bbbd6581484b847520e6bb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <lib/base/encoding.h>
#include <lib/base/eerror.h>
#include <config.h>

eDVBTextEncodingHandler encodingHandler;  // the one and only instance

eDVBTextEncodingHandler::eDVBTextEncodingHandler()
{
	const char * file=DATADIR "/enigma2/encoding.conf";
	FILE *f = fopen(file, "rt");
	if (f)
	{
		char *line = (char*) malloc(256);
		size_t bufsize=256;
		char countrycode[256];
		while( getline(&line, &bufsize, f) != -1 )
		{
			if ( line[0] == '#' )
				continue;
			int tsid, onid, encoding;
			if ( sscanf( line, "%s ISO8859-%d", countrycode, &encoding ) == 2 )
				m_CountryCodeDefaultMapping[countrycode]=encoding;
			else if ( (sscanf( line, "0x%x 0x%x ISO8859-%d", &tsid, &onid, &encoding ) == 3 )
					||(sscanf( line, "%d %d ISO8859-%d", &tsid, &onid, &encoding ) == 3 ) )
				m_TransponderDefaultMapping[(tsid<<16)|onid]=encoding;
			else if ( (sscanf( line, "0x%x 0x%x", &tsid, &onid ) == 2 )
					||(sscanf( line, "%d %d", &tsid, &onid ) == 2 ) )
				m_TransponderUseTwoCharMapping.insert((tsid<<16)|onid);
			else
				eDebug("couldn't parse %s", line);
		}
		fclose(f);
		free(line);
	}
	else
		eDebug("[eDVBTextEncodingHandler] couldn't open %s !", file);
}

void eDVBTextEncodingHandler::getTransponderDefaultMapping(int tsidonid, int &table)
{
	std::map<int, int>::iterator it =
		m_TransponderDefaultMapping.find(tsidonid);
	if ( it != m_TransponderDefaultMapping.end() )
		table = it->second;
}

bool eDVBTextEncodingHandler::getTransponderUseTwoCharMapping(int tsidonid)
{
	return m_TransponderUseTwoCharMapping.find(tsidonid) != m_TransponderUseTwoCharMapping.end();
}

int eDVBTextEncodingHandler::getCountryCodeDefaultMapping( const std::string &country_code )
{
	std::map<std::string, int>::iterator it =
		m_CountryCodeDefaultMapping.find(country_code);
	if ( it != m_CountryCodeDefaultMapping.end() )
		return it->second;
	return 0;  // ISO8859-1 / Latin1
}