2
* umain.c -- $Id: umain.c,v 1.1 2003/03/08 15:26:48 travo Exp $
3
* UNIX objects referenced by main.c that goes with play model
5
* Copyright (c) 1998. See accompanying LEGAL file for details.
15
void (*u_abort_hook)(void)= 0;
16
void (*u_exception)(int, char *)= 0;
18
volatile int p_signalling = 0;
20
static int (*u_quitter)(void)= 0;
21
static int u_quitting = 0;
22
static int u_launched = 0;
23
static jmp_buf u_mainloop;
24
static int fault_loop = 0;
27
u_main_loop(int (*on_launch)(int,char**), int argc, char **argv)
30
if (setjmp(u_mainloop)) u_fpu_setup(0);
31
if (!u_quitting && !u_launched) {
33
if (argc>0 && !u_launched)
34
argv[0] = p_strcpy(u_track_link(u_find_exe(argv[0])));
36
result = on_launch(argc, argv);
37
if (result) return result;
39
while (!u_quitting) u_waiter(1);
40
p_signalling = 0; /* ignore signals after u_quitting flag is set */
41
return u_quitter? u_quitter() : 0;
47
if (!p_signalling) p_signalling = PSIG_SOFT;
48
if (u_abort_hook) u_abort_hook();
49
longjmp(u_mainloop, 1);
53
p_quitter(int (*on_quit)(void))
67
int serviced_event = 0;
70
/* first priority is to catch any pending signals */
73
if (!fault_loop && u_exception) {
74
fault_loop = 1; /* don't trust u_exception not to fault */
75
u_exception(i, u_errmsg);
82
serviced_event = u_poll(0); /* anything pending? */
83
if (!serviced_event) { /* if not, wait for input */
85
double wait_secs = p_timeout();
86
have_timeout = (wait_secs>0.);
87
if (wait && wait_secs) {
88
do { /* int timeout may not handle > 32.767 s at once */
89
if (wait_secs < 0.0) timeout = -1;
90
else if (wait_secs < 32.767) timeout = (int)(1000.*wait_secs);
92
serviced_event = u_poll(timeout);
93
if (p_signalling) return 0;
94
if (serviced_event) break;
96
} while (wait_secs > 0.0);
100
if (serviced_event==-3) p_quit();
104
serviced_event = have_timeout;
109
return serviced_event;