Ejemplo n.º 1
0
FlocaleCharset *FlocaleCharsetGetDefaultCharset(Display *dpy, char *module)
{
	static int warn = True;

	FlocaleCharsetInit(dpy, module);

	if (FLCXOMCharset != NULL)
		return FLCXOMCharset;
	if (FLCLocaleCharset != NULL)
		return FLCLocaleCharset;

	if (warn)
	{
		warn = False;
		fprintf(stderr,
			"[%s][%s]: WARN -- Cannot find default locale "
			"charset with:\n\t",
			(module != NULL)? module:"FVWMlibs",
			"FlocaleGetDefaultCharset");
		fprintf(stderr,"X Output Method ");
		fprintf(stderr,", CHARSET env variable");
		if (FlocaleLibcharsetSupport)
			fprintf(stderr,", locale_charset");
		if (FlocaleCodesetSupport)
			fprintf(stderr,", nl_langinfo");
		fprintf(stderr,"\n");
		/* never null */
		FLCLocaleCharset =
			FlocaleCharsetOfXCharset(FLOCALE_FALLBACK_XCHARSET);
		fprintf(stderr,"\tUse default charset: %s\n",
			FLOCALE_FALLBACK_XCHARSET);

	}
	return FLCLocaleCharset;
}
Ejemplo n.º 2
0
static
void FiconvInit(Display *dpy, const char *module)
{
	int suc = False;

	if (!FiconvSupport || FiconvInitialized)
		return;

	FiconvInitialized = True;
	FlocaleCharsetInit(dpy, module);
	FLCIconvUtf8Charset = FlocaleCharsetGetUtf8Charset();
	FLCIconvDefaultCharset = FlocaleCharsetGetFLCXOMCharset();

	suc = set_default_iconv_charsets(FLCIconvDefaultCharset);
	if (!suc)
	{
		FLCIconvDefaultCharset = FlocaleCharsetGetLocaleCharset();
		suc = set_default_iconv_charsets(FLCIconvDefaultCharset);
	}
	if (!suc)
	{
		fprintf(stderr,
		       "[%s][FiconvInit]: WARN -- Cannot get default "
		       "iconv charset for default charsets '%s' and '%s'\n",
		       module,
		       FLC_DEBUG_GET_X_CHARSET(
			       FlocaleCharsetGetFLCXOMCharset()),
		       FLC_DEBUG_GET_X_CHARSET(FLCIconvDefaultCharset));
		FLCIconvUtf8Charset = NULL;
		FLCIconvDefaultCharset = NULL;
	}

#if FLOCALE_DEBUG_CHARSET
	fprintf(stderr,"[FiconvInit] iconv charset: x:%s, iconv:%s\n",
		FLC_DEBUG_GET_X_CHARSET(FLCIconvDefaultCharset),
		FLC_DEBUG_GET_ICONV_CHARSET(FLCIconvDefaultCharset));
	fprintf(stderr,"[FiconvInit] UTF-8 charset: x:%s, iconv:%s\n",
		FLC_DEBUG_GET_X_CHARSET(FLCIconvUtf8Charset),
		FLC_DEBUG_GET_ICONV_CHARSET(FLCIconvUtf8Charset));
#endif

}
Ejemplo n.º 3
0
Bool FlocaleCharsetIsCharsetXLocale(Display *dpy, char *charset, char *module)
{
#ifdef HAVE_XOUTPUT_METHOD
	int i;

	FlocaleCharsetInit(dpy, module);
	if (FLCXOMCharsetList_num > 0)
	{
		for(i = 0; i <  FLCXOMCharsetList_num; i++)
		{
			if (StrEquals(
				    FLC_DEBUG_GET_X_CHARSET(
					    FLCXOMCharsetList[i]),
				    charset))
			{
				return True;
			}
		}
	}
	return False;
#else
	return True; /* Hum */
#endif
}
Ejemplo n.º 4
0
void FlocaleCharsetSetFlocaleCharset(
	Display *dpy, FlocaleFont *flf, char *hints, char *encoding,
	char *module)
{
	char *charset = NULL;
	char *iconv = NULL;
	Bool iconv_found = False;
	int i = 0;

	FlocaleCharsetInit(dpy, module);

	if (hints && *hints)
	{
		iconv = GetQuotedString(
			hints, &charset, "/", NULL, NULL, NULL);
		if (charset && *charset && *charset != '*' )
		{
			flf->fc = FlocaleCharsetOfXCharset(charset);
		}
		if (flf->fc == NULL && charset && *charset && *charset != '*')
		{
			flf->fc = FlocaleCharsetOfLocaleCharset(charset);
		}
		if (flf->fc == NULL && iconv && *iconv)
		{
			flf->fc = FlocaleCharsetOfLocaleCharset(iconv);
		}
	}
	if (flf->fc == NULL)
	{
		if (FftSupport && flf->fftf.fftfont != NULL)
		{
			flf->fc = FlocaleCharsetOfXCharset(flf->fftf.encoding);
		}
		else if (flf->fontset != None)
		{
			if (FLCXOMCharset != NULL)
			{
				flf->fc = FLCXOMCharset;
			}
			else
			{
				/* we are here if !HAVE_XOUTPUT_METHOD */
				XFontStruct **fs_list;
				char **ml;

				if (XFontsOfFontSet(
					    flf->fontset, &fs_list, &ml) > 0)
				{
					flf->fc = FLCXOMCharset =
						FlocaleCharsetOfFontStruct(
							dpy, fs_list[0]);
				}
			}
		}
		else if (flf->font != NULL)
		{
			flf->fc = FlocaleCharsetOfFontStruct(dpy, flf->font);
		}
	}
	if (flf->fc != NULL && iconv && *iconv)
	{
		/* the user has specified an iconv converter name:
		 * check if we have it and force user choice */
		while(!iconv_found &&
		      FLC_GET_LOCALE_CHARSET(flf->fc,i) != NULL)
		{
			if (
				strcmp(
					iconv,
					FLC_GET_LOCALE_CHARSET(flf->fc,i)) ==
				0)
			{
				iconv_found = True;
				/* Trust the user? yes ... */
				FLC_SET_ICONV_INDEX(flf->fc,i);
			}
			i++;
		}
	}
	if (iconv && *iconv && !iconv_found)
	{
		FlocaleCharset *fc;

		/* the user has specified an iconv converter name and we do not
		 * have it: must create a FlocaleCharset */
		flf->flags.must_free_fc = True;
		fc = (FlocaleCharset *)safemalloc(sizeof(FlocaleCharset));
		if (flf->fc != NULL)
		{
			CopyString(&fc->x, flf->fc->x);
			fc->encoding_type = flf->fc->encoding_type;
			if (flf->fc->bidi)
				CopyString(&fc->bidi, flf->fc->bidi);
			else
				fc->bidi = NULL;
		}
		else
		{
			CopyString(&fc->x, "Unknown"); /* for simplicity */
			fc->bidi = NULL;
			fc->encoding_type = FLC_ENCODING_TYPE_FONT;
		}
		fc->locale = (char **)safemalloc(2*sizeof(char *));
		CopyString(&fc->locale[0], iconv);
		fc->locale[1] = NULL;
		fc->iconv_index =  FLC_INDEX_ICONV_CHARSET_NOT_INITIALIZED;
		flf->fc = fc;
	}
	if (charset != NULL)
	{
		free(charset);
	}
	if (flf->fc == NULL)
	{
		flf->fc = &UnknownCharset;
	}

	/* now the string charset */
	if (encoding != NULL)
	{
		flf->str_fc = FlocaleCharsetOfXCharset(encoding);
		if (flf->str_fc == NULL)
		{
			flf->str_fc = FlocaleCharsetOfLocaleCharset(encoding);
		}
		if (flf->str_fc == NULL)
		{
			flf->str_fc = &UnknownCharset;
		}
	}
	else if (FftSupport && flf->fftf.fftfont != NULL)
	{
		if (flf->fftf.str_encoding != NULL)
		{
			flf->str_fc = FlocaleCharsetOfXCharset(
				flf->fftf.str_encoding);
			if (flf->str_fc == NULL)
			{
				flf->str_fc = FlocaleCharsetOfLocaleCharset(
					flf->fftf.str_encoding);
			}
			if (flf->str_fc == NULL)
			{
				flf->str_fc = &UnknownCharset;
			}
		}
		else
		{
			flf->str_fc =
				FlocaleCharsetGetDefaultCharset(dpy, module);
		}
	}
	if (flf->str_fc == NULL)
	{
		if (flf->fc != &UnknownCharset)
		{
			flf->str_fc = flf->fc;
		}
		else
		{
			flf->str_fc =
				FlocaleCharsetGetDefaultCharset(dpy, module);
		}
	}
}