-
Notifications
You must be signed in to change notification settings - Fork 52
/
gui.c
154 lines (134 loc) · 4.52 KB
/
gui.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Xiphos Bible Study Tool
* gui.c - The heart of the gui.
*
* Copyright (C) 2000-2018 Xiphos Developer Team
*
* 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 Library 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <locale.h>
#include <stdlib.h>
/* ----------------------------------------------- */
/* do not #include "gui/debug_glib_null.h" in this */
/* file: here we define the replacement functions, */
/* so we need access to the real glib versions. */
/* ----------------------------------------------- */
#include "gui/gui.h"
#include "gui/dialog.h"
#ifdef HAVE_DBUS
#include "gui/ipc.h"
static IpcObject *ipc;
#endif
void gui_init(int argc, char *argv[])
{
static int gui_init_done = FALSE;
if (gui_init_done)
return;
gui_init_done = TRUE;
#ifdef ENABLE_NLS
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
#endif
#ifdef WIN32
gchar *locale_dir =
g_win32_get_package_installation_directory_of_module(NULL);
locale_dir = g_strconcat(locale_dir, "\0", NULL);
locale_dir = g_build_filename(locale_dir, "share", "locale", NULL);
bindtextdomain(GETTEXT_PACKAGE, locale_dir);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
g_free(locale_dir);
#endif
if (!gtk_init_with_args(&argc, &argv, NULL, NULL, NULL, NULL)) {
exit(1);
};
#ifdef HAVE_DBUS
ipc = ipc_init_dbus_connection(ipc);
#endif
}
void gui_main(void)
{
gtk_main();
}
#ifdef DEBUG
/* NOTE: these routines are here only and exactly because there is no other */
/* code in this file that needs the real glib versions. if there is ever a */
/* reason for using g_str{dup,ing}_printf in this file, these functions */
/* will need to be moved to some other file which does not need them. this */
/* is because the file implementing replacements must not #include the .h */
/* that induces access to the replacements via #define. */
/* this is a total mind game: we redefine the standard use of glib functions */
/* so as to see our internal versions. our internal versions scan for mis- */
/* use of %s, i.e. (char*)NULL that should (by rights) cause crashes anyhow. */
/* GIVE US THE CRASHES, PLEASE! MYSTERY BUGS ARE EVIL! glibc.helpfulness-- */
gchar *XI_g_strdup_printf(const char *filename,
int linenumber, const gchar *format, ...)
{
gchar *buffer, *s;
va_list args;
va_start(args, format);
for (s = strchr(format, '%'); s; s = strchr(++s, '%')) {
gchar *next = va_arg(args, gchar *);
if ((next == (gchar *)NULL) && (*(s + 1) == 's')) {
gchar *msg = g_strdup_printf("%s\n%s\n\n%s:%d \"%s\"",
_("BUG! Xiphos is about to crash due to a \"STRDUP\" error."),
_("Please report this error to the Xiphos team with:"),
filename, linenumber, format);
gui_generic_warning_modal(msg);
g_free(msg);
abort();
}
}
va_end(args);
/* real g_strdup_printf content */
va_start(args, format);
buffer = g_strdup_vprintf(format, args);
va_end(args);
return buffer;
}
void
XI_g_string_printf(const char *filename,
int linenumber,
GString *string, const gchar *format, ...)
{
gchar *s;
va_list args;
va_start(args, format);
for (s = strchr(format, '%'); s; s = strchr(++s, '%')) {
gchar *next = va_arg(args, gchar *);
if ((next == (gchar *)NULL) && (*(s + 1) == 's')) {
gchar *msg = g_strdup_printf("%s\n%s\n\n%s:%d \"%s\"",
_("BUG! Xiphos is about to crash due to a \"STRING\" error."),
_("Please report this error to the Xiphos team with:"),
filename, linenumber, format);
gui_generic_warning_modal(msg);
g_free(msg);
abort();
}
}
va_end(args);
/* real g_string_printf content */
g_string_truncate(string, 0);
va_start(args, format);
g_string_append_vprintf(string, format, args);
va_end(args);
}
#endif /* DEBUG */