Пример #1
0
/**
 * Get locale information. 
 * @return allocated structure with all information or NULL if error
 */
TDSLOCALE *
tds_get_locale(void)
{
	TDSLOCALE *locale;
	char *s;
	FILE *in;

	/* allocate a new structure with hard coded and build-time defaults */
	locale = tds_alloc_locale();
	if (!locale)
		return NULL;

	tdsdump_log(TDS_DBG_INFO1, "Attempting to read locales.conf file\n");

	in = fopen(FREETDS_LOCALECONFFILE, "r");
	if (in) {
		tds_read_conf_section(in, "default", tds_parse_locale, locale);

#if HAVE_LOCALE_H
		s = setlocale(LC_ALL, NULL);
#else
		s = getenv("LANG");
#endif
		if (s && s[0]) {
			int found;
			char buf[128];
			const char *strip = "@._";

			/* do not change environment !!! */
			tds_strlcpy(buf, s, sizeof(buf));

			/* search full name */
			rewind(in);
			found = tds_read_conf_section(in, buf, tds_parse_locale, locale);

			/*
			 * Here we try to strip some part of language in order to
			 * catch similar language
			 * LANG is composed by 
			 *   language[_sublanguage][.charset][@modified]
			 * ie it_IT@euro or it_IT.UTF-8 so we strip in order
			 * modifier, charset and sublanguage
			 * ie it_IT@euro -> it_IT -> it
			 */
			for (;!found && *strip; ++strip) {
				s = strrchr(buf, *strip);
				if (!s)
					continue;
				*s = 0;
				rewind(in);
				found = tds_read_conf_section(in, buf, tds_parse_locale, locale);
			}

		}


		fclose(in);
	}
	return locale;
}
Пример #2
0
/**
 * Get locale information. 
 * @return allocated structure with all information or NULL if error
 */
TDSLOCALE *
tds_get_locale(void)
{
	TDSLOCALE *locale;
	char *s;
	FILE *in;

	/* allocate a new structure with hard coded and build-time defaults */
	locale = tds_alloc_locale();
	if (!locale)
		return NULL;

	tdsdump_log(TDS_DBG_INFO1, "%L Attempting to read locales.conf file\n");

	in = fopen(FREETDS_LOCALECONFFILE, "r");
	if (in) {
		tds_read_conf_section(in, "default", tds_parse_locale, locale);

		s = getenv("LANG");
		if (s && s[0]) {
			rewind(in);
			tds_read_conf_section(in, s, tds_parse_locale, locale);
		}

		fclose(in);
	}
	return locale;
}