Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[a2776f]: uget-cmd / UgApp-cmd-main.c Maximize Restore History

Download this file

UgApp-cmd-main.c    146 lines (130 with data), 4.1 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
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
/*
*
* Copyright (C) 2005-2011 by C.H. Huang
* plushuang.tw@gmail.com
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* ---
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU Lesser General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*
*/
// ----------------------------------------------------------------------------
#ifdef _WIN32
#include <windows.h>
#include <winsock.h>
// ------------------------------------
// Windows functions
static void win32_winsock_init (void)
{
WSADATA WSAData;
WSAStartup (MAKEWORD (2, 2), &WSAData);
}
static void win32_winsock_finalize (void)
{
WSACleanup ();
}
#endif // _WIN32
// ----------------------------------------------------------------------------
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// PACKAGE_VERSION
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "1.7.0"
#endif
// std
#include <stdlib.h> // exit(), EXIT_SUCCESS, EXIT_FAILURE
#include <signal.h>
// uglib
#include <UgApp-base.h>
#include <UgApp-cmd.h>
// ----------------------------------------------------------------------------
static UgAppCmd* app;
static void term_signal_handler (int sig)
{
ug_app_cmd_save (app);
ug_ipc_finalize (&app->ipc);
#if defined (_WIN32)
win32_winsock_finalize ();
#endif
exit (0);
}
// ----------------------------------------------------------------------------
int main (int argc, char** argv)
{
gchar* string;
gint ipc_status;
string = ug_arg_find_version (argc, argv);
if (string) {
#if defined (_WIN32) && defined (_WINDOWS)
win32_console_init ();
#endif // _WIN32 && _WINDOWS
g_print ("uGet " PACKAGE_VERSION " for commandline" "\n");
return EXIT_SUCCESS;
}
string = ug_arg_find_help (argc, argv);
// initialize for MS-Windows
#if defined (_WIN32)
win32_winsock_init ();
#endif // _WIN32
// GLib: GThread
if (g_thread_supported () == FALSE)
g_thread_init (NULL);
// allocate memory for application
app = g_slice_alloc0 (sizeof (UgAppCmd));
// uglib options
ug_option_init (&app->option);
if (string) {
g_print ("uGet " PACKAGE_VERSION " for commandline" "\n");
ug_option_help (&app->option, argv[0], string);
}
// IPC initialize & check exist Uget program
ipc_status = ug_ipc_init_with_args (&app->ipc, argc, argv);
if (ipc_status < 1) {
if (ipc_status == -1)
g_print ("uget: IPC failed.\n");
// if (ipc_status == 0)
// g_print ("uget: Server exists.\n");
ug_ipc_finalize (&app->ipc);
goto exit;
}
// register uget interfaces
uglib_init ();
// main program
signal (SIGTERM, term_signal_handler);
ug_app_cmd_run (app);
// shutdown IPC and sleep 2 second to wait thread
ug_ipc_finalize (&app->ipc);
g_usleep (2 * 1000000);
exit:
// finalize for MS-Windows
#if defined (_WIN32)
win32_winsock_finalize ();
#endif
return EXIT_SUCCESS;
}