2 * Contains functions for dealing with things that happen in the
5 * @(#)daemon.c 3.3 (Berkeley) 6/15/81
7 * Rogue: Exploring the Cavern of Cuties
8 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
11 * See the file LICENSE.TXT for full copyright and licensing information.
23 struct delayed_action d_list
[MAXDAEMONS
] = {
24 _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
,
25 _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
, _X_
,
30 * Find an empty slot in the daemon/fuse list
32 struct delayed_action
*
36 register struct delayed_action
*dev
;
38 for (i
= 0, dev
= d_list
; i
< MAXDAEMONS
; i
++, dev
++)
39 if (dev
->d_type
== EMPTY
)
41 debug("Ran out of fuse slots");
47 * Find a particular slot in the table
50 struct delayed_action
*
52 register int (*func
)();
55 register struct delayed_action
*dev
;
57 for (i
= 0, dev
= d_list
; i
< MAXDAEMONS
; i
++, dev
++)
58 if (dev
->d_type
!= EMPTY
&& func
== dev
->d_func
)
65 * Start a daemon, takes a function.
68 start_daemon(func
, arg
, type
)
69 int (*func
)(), arg
, type
;
71 register struct delayed_action
*dev
;
86 * Remove a daemon from the list
92 register struct delayed_action
*dev
;
94 if ((dev
= find_slot(func
)) == NULL
)
97 * Take it out of the list
104 * Run all the daemons that are active with the current flag,
105 * passing the argument to the function.
111 register struct delayed_action
*dev
;
114 * Loop through the devil list
116 for (dev
= d_list
; dev
<= &d_list
[MAXDAEMONS
-1]; dev
++)
118 * Executing each one, giving it the proper arguments
120 if (dev
->d_type
== flag
&& dev
->d_time
== DAEMON
)
121 (*dev
->d_func
)(dev
->d_arg
);
126 * Start a fuse to go off in a certain number of turns
129 fuse(func
, arg
, time
, type
)
130 int (*func
)(), arg
, time
, type
;
132 register struct delayed_action
*wire
;
147 * Increase the time until a fuse goes off
150 lengthen(func
, xtime
)
154 register struct delayed_action
*wire
;
156 if ((wire
= find_slot(func
)) == NULL
)
158 wire
->d_time
+= xtime
;
169 register struct delayed_action
*wire
;
171 if ((wire
= find_slot(func
)) == NULL
)
173 wire
->d_type
= EMPTY
;
178 * Decrement counters and start needed fuses
184 register struct delayed_action
*wire
;
187 * Step though the list
189 for (wire
= d_list
; wire
<= &d_list
[MAXDAEMONS
-1]; wire
++)
192 * Decrementing counters and starting things we want. We also need
193 * to remove the fuse from the list once it has gone off.
195 if (flag
== wire
->d_type
&& wire
->d_time
> 0 && --wire
->d_time
== 0)
197 wire
->d_type
= EMPTY
;
198 (*wire
->d_func
)(wire
->d_arg
);