Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend/dvi/texmfcnf.c
blob: 72fbff23764eb025c218fa3d5cfe85fd8f7be0f0 (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
60
61
62
63
64
/*
 * Copyright (C) 2010, Hib Eris <hib@hiberis.nl>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"

#include "texmfcnf.h"

#include <glib.h>
#include <stdlib.h>
#ifdef G_OS_WIN32
#include <windows.h>
#endif

gchar *
get_texmfcnf(void)
{
	char *env = getenv("TEXMFCNF");
	if (env)
		return g_strdup(env);

#ifdef G_OS_WIN32
	gchar *texmfcnf = NULL;
	TCHAR path[_MAX_PATH];

	if (SearchPath(NULL, "mktexpk", ".exe", _MAX_PATH, path, NULL))
	{
		gchar *sdir, *sdir_parent, *sdir_grandparent;
		const gchar *texmfcnf_fmt = "{%s,%s,%s}{,{/share,}/texmf{-local,}/web2c}";

		sdir = g_path_get_dirname(path);
		sdir_parent = g_path_get_dirname(sdir);
		sdir_grandparent = g_path_get_dirname(sdir_parent);

		texmfcnf = g_strdup_printf(texmfcnf_fmt,
			sdir, sdir_parent, sdir_grandparent);

		g_free(sdir);
		g_free(sdir_parent);
		g_free(sdir_grandparent);
	}
	return texmfcnf;
#else
	return NULL;
#endif
}