Exemplo n.º 1
0
char *
load_mc_home_file (const char *filename, char **allocated_filename)
{
    char *hintfile_base, *hintfile;
    char *lang;
    char *data;

    hintfile_base = concat_dir_and_file (mc_home, filename);
    lang = guess_message_value ();

    hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
    data = load_file (hintfile);

    if (!data) {
	g_free (hintfile);
	/* Fall back to the two-letter language code */
	if (lang[0] && lang[1])
	    lang[2] = 0;
	hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
	data = load_file (hintfile);

	if (!data) {
	    g_free (hintfile);
	    hintfile = hintfile_base;
	    data = load_file (hintfile_base);
	}
    }

    g_free (lang);

    if (hintfile != hintfile_base)
	g_free (hintfile_base);

    if (allocated_filename)
	*allocated_filename = hintfile;
    else
	g_free (hintfile);

    return data;
}
Exemplo n.º 2
0
Arquivo: util.c Projeto: JBurant/mc
char *
load_mc_home_file (const char *from, const char *filename, char **allocated_filename)
{
    char *hintfile_base, *hintfile;
    char *lang;
    char *data;

    hintfile_base = g_build_filename (from, filename, (char *) NULL);
    lang = guess_message_value ();

    hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
    if (!g_file_get_contents (hintfile, &data, NULL, NULL))
    {
        /* Fall back to the two-letter language code */
        if (lang[0] != '\0' && lang[1] != '\0')
            lang[2] = '\0';
        g_free (hintfile);
        hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
        if (!g_file_get_contents (hintfile, &data, NULL, NULL))
        {
            g_free (hintfile);
            hintfile = hintfile_base;
            g_file_get_contents (hintfile_base, &data, NULL, NULL);
        }
    }

    g_free (lang);

    if (hintfile != hintfile_base)
        g_free (hintfile_base);

    if (allocated_filename != NULL)
        *allocated_filename = hintfile;
    else
        g_free (hintfile);

    return data;
}