1 /* -*- Mode: C; tab-width: 8; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* dllmain.c: DLL entry point for libgtkhtml on Win32
3  * Copyright (C) 2005 Novell, Inc
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <config.h>
22 #include <string.h>
23 #include <glib.h>
24 
25 /* localedir uses system codepage as it is passed to the non-UTF8ified
26  * gettext library
27  */
28 static const gchar *localedir = NULL;
29 
30 /* The others are in UTF-8 */
31 static gchar *prefix;
32 static const gchar *libdir;
33 static const gchar *datadir;
34 static const gchar *sysconfdir;
35 static const gchar *icondir;
36 static const gchar *gtkhtml_datadir;
37 
38 static gpointer hmodule;
39 G_LOCK_DEFINE_STATIC (mutex);
40 
41 static gchar *
replace_prefix(const gchar * runtime_prefix,const gchar * configure_time_path)42 replace_prefix (const gchar *runtime_prefix,
43                 const gchar *configure_time_path)
44 {
45 	if (runtime_prefix &&
46 	    strncmp (configure_time_path, PREFIX "/",
47 		     strlen (PREFIX) + 1) == 0)
48 		return g_strconcat (runtime_prefix,
49 				    configure_time_path + strlen (PREFIX),
50 				    NULL);
51 	else
52 		return g_strdup (configure_time_path);
53 }
54 
55 static void
setup(void)56 setup (void)
57 {
58 	gchar *cp_prefix;
59 
60 	G_LOCK (mutex);
61 	if (localedir != NULL) {
62 		G_UNLOCK (mutex);
63 		return;
64 	}
65 
66 	prefix = g_win32_get_package_installation_directory_of_module (hmodule);
67 	cp_prefix = g_win32_locale_filename_from_utf8 (prefix);
68 
69 	localedir = replace_prefix (cp_prefix, GNOMELOCALEDIR);
70 	g_free (cp_prefix);
71 
72 	libdir = replace_prefix (prefix, LIBDIR);
73 	datadir = replace_prefix (prefix, DATADIR);
74 	sysconfdir = replace_prefix (prefix, SYSCONFDIR);
75 	icondir = replace_prefix (prefix, ICONDIR);
76 	gtkhtml_datadir = replace_prefix (prefix, GTKHTML_DATADIR);
77 
78 	G_UNLOCK (mutex);
79 }
80 
81 /* <windows.h> drags in a definition of DATADIR, argh. So #undef
82  * DATADIR and include <windows.h> only here.
83  */
84 #undef DATADIR
85 #include <windows.h>
86 
87 /* Silence gcc with a prototype */
88 BOOL WINAPI DllMain (HINSTANCE hinstDLL,
89 		     DWORD     fdwReason,
90 		     LPVOID    lpvReserved);
91 
92 /* DllMain used to tuck away the the DLL's HMODULE */
93 BOOL WINAPI
DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)94 DllMain (HINSTANCE hinstDLL,
95          DWORD fdwReason,
96          LPVOID lpvReserved)
97 {
98 	switch (fdwReason) {
99 	case DLL_PROCESS_ATTACH:
100 		hmodule = hinstDLL;
101 		break;
102 	}
103 	return TRUE;
104 }
105 
106 /* Include gtkhtml-private.h now to get prototypes for the getter
107  * functions, to silence gcc. Can't include it earlier as we need the
108  * definitions of the *DIR macros from the Makefile above, and
109  * gtkhtml-private overrides them.
110  */
111 #include "gtkhtml-private.h"
112 
113 #define GETTER(varbl)				\
114 const gchar *					\
115 _get_##varbl (void)				\
116 {						\
117 	setup ();				\
118 	return varbl;				\
119 }
120 
121 GETTER (prefix)
122 GETTER (localedir)
123 GETTER (libdir)
124 GETTER (datadir)
125 GETTER (sysconfdir)
126 GETTER (icondir)
127 GETTER (gtkhtml_datadir)
128