main.c
2.57 KB
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
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @brief PW3270 main aplication Entry point
*
*/
#include "private.h"
#include <pw3270/application.h>
#include <lib3270.h>
#include <lib3270/log.h>
#include <locale.h>
#include <stdlib.h>
#ifdef G_OS_UNIX
#include <glib-unix.h>
#endif // G_OS_UNIX
/*---[ Implement ]----------------------------------------------------------------------------------*/
#ifdef G_OS_UNIX
static gboolean quit_signal(GtkApplication *app) {
debug("%s",__FUNCTION__);
g_message("Terminating by signal");
g_application_quit(G_APPLICATION(app));
return FALSE;
}
#endif // G_OS_UNIX
int main (int argc, char **argv) {
int status = -1;
#ifdef _WIN32
debug("Process %s running on pid %u\n",argv[0],(unsigned int) GetCurrentProcessId());
#endif // _WIN32
GtkApplication *app;
// Setup locale
#ifdef LC_ALL
setlocale( LC_ALL, "" );
#endif
#ifdef _WIN32
{
g_autofree gchar * pkgdir = g_win32_get_package_installation_directory_of_module(NULL);
{
g_autofree gchar * appdir = g_build_filename(pkgdir,"locale",NULL);
if(g_file_test(appdir,G_FILE_TEST_IS_DIR)) {
bindtextdomain( PACKAGE_NAME, appdir );
} else {
g_autofree gchar * sysdir = g_build_filename(pkgdir,"share","locale",NULL);
if(g_file_test(sysdir,G_FILE_TEST_IS_DIR)) {
bindtextdomain( PACKAGE_NAME, sysdir );
}
}
}
}
#endif // _WIN32
bind_textdomain_codeset(G_STRINGIFY(PRODUCT_NAME), "UTF-8");
textdomain(G_STRINGIFY(PRODUCT_NAME));
// Setup and start application.
g_set_application_name(G_STRINGIFY(PRODUCT_NAME));
app = pw3270_application_new(G_STRINGIFY(APPLICATION_ID),G_APPLICATION_HANDLES_OPEN);
#ifdef G_OS_UNIX
g_unix_signal_add(SIGTERM, (GSourceFunc) quit_signal, app);
#endif // G_OS_UNIX
status = g_application_run(G_APPLICATION (app), argc, argv);
g_object_unref (app);
debug("%s ends with RC=%d",__FUNCTION__,status);
return status;
}