~ubuntu-branches/ubuntu/lucid/python-scipy/lucid

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/unix/umain.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-07 14:12:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070107141212-mm0ebkh5b37hcpzn
* Remove build dependency on python-numpy-dev.
* python-scipy: Depend on python-numpy instead of python-numpy-dev.
* Package builds on other archs than i386. Closes: #402783.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
4
 
 *
5
 
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
6
 
 */
7
 
 
8
 
#include "config.h"
9
 
#include "pstdlib.h"
10
 
#include "play.h"
11
 
#include "playu.h"
12
 
 
13
 
#include <setjmp.h>
14
 
 
15
 
void (*u_abort_hook)(void)= 0;
16
 
void (*u_exception)(int, char *)= 0;
17
 
char *u_errmsg = 0;
18
 
volatile int p_signalling = 0;
19
 
 
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;
25
 
 
26
 
int
27
 
u_main_loop(int (*on_launch)(int,char**), int argc, char **argv)
28
 
{
29
 
  u_fpu_setup(-1);
30
 
  if (setjmp(u_mainloop)) u_fpu_setup(0);
31
 
  if (!u_quitting && !u_launched) {
32
 
    int result;
33
 
    if (argc>0 && !u_launched)
34
 
      argv[0] = p_strcpy(u_track_link(u_find_exe(argv[0])));
35
 
    u_launched = 1;
36
 
    result = on_launch(argc, argv);
37
 
    if (result) return result;
38
 
  }
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;
42
 
}
43
 
 
44
 
void
45
 
p_abort(void)
46
 
{
47
 
  if (!p_signalling) p_signalling = PSIG_SOFT;
48
 
  if (u_abort_hook) u_abort_hook();
49
 
  longjmp(u_mainloop, 1);
50
 
}
51
 
 
52
 
void
53
 
p_quitter(int (*on_quit)(void))
54
 
{
55
 
  u_quitter = on_quit;
56
 
}
57
 
 
58
 
void
59
 
p_quit(void)
60
 
{
61
 
  u_quitting = 1;
62
 
}
63
 
 
64
 
int
65
 
u_waiter(int wait)
66
 
{
67
 
  int serviced_event = 0;
68
 
 
69
 
  if (p_signalling) {
70
 
    /* first priority is to catch any pending signals */
71
 
    int i = p_signalling;
72
 
    p_signalling = 0;
73
 
    if (!fault_loop && u_exception) {
74
 
      fault_loop = 1;    /* don't trust u_exception not to fault */
75
 
      u_exception(i, u_errmsg);
76
 
      serviced_event = 1;
77
 
    }
78
 
    u_errmsg = 0;
79
 
 
80
 
  } else {
81
 
    int have_timeout = 0;
82
 
    serviced_event = u_poll(0);   /* anything pending? */
83
 
    if (!serviced_event) {        /* if not, wait for input */
84
 
      int timeout;
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);
91
 
          else                          timeout = 32767;
92
 
          serviced_event = u_poll(timeout);
93
 
          if (p_signalling) return 0;
94
 
          if (serviced_event) break;
95
 
          wait_secs -= 32.767;
96
 
        } while (wait_secs > 0.0);
97
 
      }
98
 
    }
99
 
    if (serviced_event) {
100
 
      if (serviced_event==-3) p_quit();
101
 
      p_on_idle(1);
102
 
    } else {
103
 
      p_on_idle(0);
104
 
      serviced_event = have_timeout;
105
 
    }
106
 
    fault_loop = 0;
107
 
  }
108
 
 
109
 
  return serviced_event;
110
 
}