]> www.fi.muni.cz Git - evince.git/blob - backend/dvi/texmfcnf.c
[windows] Guess texmf.cnf location from mktexpk executable
[evince.git] / backend / dvi / texmfcnf.c
1 /*
2  * Copyright (C) 2010, Hib Eris <hib@hiberis.nl>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include "texmfcnf.h"
22
23 #include <glib.h>
24 #include <stdlib.h>
25 #ifdef G_OS_WIN32
26 #include <windows.h>
27 #endif
28
29 gchar *
30 get_texmfcnf(void)
31 {
32         char *env = getenv("TEXMFCNF");
33         if (env)
34                 return g_strdup(env);
35
36 #ifdef G_OS_WIN32
37         gchar *texmfcnf = NULL;
38         TCHAR path[_MAX_PATH];
39
40         if (SearchPath(NULL, "mktexpk", ".exe", _MAX_PATH, path, NULL))
41         {
42                 gchar *sdir, *sdir_parent, *sdir_grandparent;
43                 const gchar *texmfcnf_fmt = "{%s,%s,%s}{,{/share,}/texmf{-local,}/web2c}";
44
45                 sdir = g_path_get_dirname(path);
46                 sdir_parent = g_path_get_dirname(sdir);
47                 sdir_grandparent = g_path_get_dirname(sdir_parent);
48
49                 texmfcnf = g_strdup_printf(texmfcnf_fmt,
50                         sdir, sdir_parent, sdir_grandparent);
51
52                 g_free(sdir);
53                 g_free(sdir_parent);
54                 g_free(sdir_grandparent);
55         }
56         return texmfcnf;
57 #else
58         return NULL;
59 #endif
60 }
61
62
63
64