コード例 #1
0
ファイル: countries.c プロジェクト: cz172638/v4l-utils
enum dvb_country_t dvb_guess_user_country(void)
{
	char * buf, * pch, * pbuf;
	unsigned cat;
	enum dvb_country_t id = COUNTRY_UNKNOWN;

	for (cat = 0; cat < sizeof(cats)/sizeof(cats[0]); cat++) {

		// the returned char * should be "C", "POSIX" or something valid.
		// If valid, we can only *guess* which format is returned.
		// Assume here something like "de_DE.iso8859-1@euro" or "de_DE.utf-8"
		buf = secure_getenv(cats[cat]);
		if (! buf || strlen(buf) < 2)
			continue;

		if (! strncmp(buf, "POSIX", MIN(strlen(buf), 5)) ||
		    ! (strncmp(buf, "en", MIN(strlen(buf), 2)) && !isalpha(buf[2])) )
			continue;

		buf = strdup(buf);
		pbuf= buf;

		// assuming 'language_country.encoding@variant'

		// country after '_', if given
		if ((pch = strchr(buf, '_')))
			pbuf = pch + 1;

		// remove all after '@', including '@'
		if ((pch = strchr(pbuf, '@')))
			*pch = 0;

		// remove all after '.', including '.'
		if ((pch = strchr(pbuf, '.')))
			*pch = 0;

		if (strlen(pbuf) == 2)
			id = dvb_country_a2_to_id(pbuf);
		free(buf);
		if (id != COUNTRY_UNKNOWN)
			return id;
	}

	return COUNTRY_UNKNOWN;
}
コード例 #2
0
ファイル: dvb-fe.c プロジェクト: Distrotech/v4l-utils
int dvb_fe_set_default_country(struct dvb_v5_fe_parms *p, const char *cc)
{
	struct dvb_v5_fe_parms_priv *parms = (void *)p;

	if (!cc) {
		parms->country = dvb_guess_user_country();
		if (parms->p.verbose) {
			if (parms->country != COUNTRY_UNKNOWN)
				dvb_log(_("Assuming you're in %s.\n"),
					dvb_country_to_2letters(parms->country));
			else
				dvb_log(_("Failed to guess country from the current locale setting.\n"));
		}
		return 0;
	}

	parms->country = dvb_country_a2_to_id(cc);
	return (parms->country == COUNTRY_UNKNOWN) ? -EINVAL : 0;
}