Use a common early init() function

There is a number of things both virt-viewer and remote-viewer need to
do early during execution. Do it only in one place.
This commit is contained in:
Marc-André Lureau 2012-10-19 23:49:02 +02:00
parent 53c6549fb4
commit 14a1d48745
4 changed files with 36 additions and 32 deletions

View File

@ -229,27 +229,7 @@ main(int argc, char **argv)
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
#ifdef G_OS_WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
dup2(fileno(stdin), STDIN_FILENO);
dup2(fileno(stdout), STDOUT_FILENO);
dup2(fileno(stderr), STDERR_FILENO);
}
#endif
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
g_set_application_name(_("Remote Viewer"));
virt_viewer_util_init(_("Remote Viewer"));
/* Setup command line options */
context = g_option_context_new (_("- Remote viewer client"));

View File

@ -85,17 +85,7 @@ int main(int argc, char **argv)
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
g_set_application_name(_("Virt Viewer"));
virt_viewer_util_init(_("Virt Viewer"));
basename = g_path_get_basename(argv[0]);
help_msg = g_strdup_printf(_("Run '%s --help' to see a full list of available command line options"),

View File

@ -23,6 +23,14 @@
#include <config.h>
#include <glib.h>
#include <glib/gi18n.h>
#ifdef G_OS_WIN32
#include <windows.h>
#include <io.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@ -252,6 +260,30 @@ gulong virt_viewer_signal_connect_object(gpointer instance,
return ctx->handler_id;
}
void virt_viewer_util_init(const char *appname)
{
#ifdef G_OS_WIN32
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
dup2(fileno(stdin), STDIN_FILENO);
dup2(fileno(stdout), STDOUT_FILENO);
dup2(fileno(stderr), STDERR_FILENO);
}
#endif
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
g_set_application_name(appname);
}
/*
* Local variables:

View File

@ -32,6 +32,8 @@ extern gboolean doDebug;
#define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
void virt_viewer_util_init(const char *appname);
GtkBuilder *virt_viewer_util_load_ui(const char *name);
int virt_viewer_util_extract_host(const char *uristr,
char **scheme,