+/* $NetBSD: schedule.c,v 1.11 2009/05/24 22:55:03 dholland Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)schedule.c 5.4 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: schedule.c,v 1.2 1993/08/01 18:50:03 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: schedule.c,v 1.11 2009/05/24 22:55:03 dholland Exp $");
+#endif
#endif /* not lint */
-# include "trek.h"
+#include <stdio.h>
+#include <math.h>
+#include <err.h>
+#include <limits.h>
+#include "trek.h"
/*
** SCHEDULE AN EVENT
** The address of the slot is returned.
*/
-struct event *schedule(type, offset, x, y, z)
-int type;
-double offset;
-char x, y;
-char z;
+struct event *
+schedule(int type, double offset, int x, int y, int z)
{
- register struct event *e;
- register int i;
+ struct event *e;
+ int i;
double date;
date = Now.date + offset;
- for (i = 0; i < MAXEVENTS; i++)
- {
+ for (i = 0; i < MAXEVENTS; i++) {
e = &Event[i];
if (e->evcode)
continue;
/* got a slot */
-# ifdef xTRACE
+#ifdef xTRACE
if (Trace)
- printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
+ printf("schedule: type %d @ %.2f "
+ "slot %d parm %d %d %d\n",
type, date, i, x, y, z);
-# endif
+#endif
e->evcode = type;
e->date = date;
e->x = x;
e->y = y;
e->systemname = z;
- Now.eventptr[type] = e;
+ Now.eventptr[type & ~E_GHOST] = e;
return (e);
}
- syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z);
+ errx(1, "Cannot schedule event %d parm %d %d %d", type, x, y, z);
}
** time plus 'offset'.
*/
-reschedule(e1, offset)
-struct event *e1;
-double offset;
+void
+reschedule(struct event *e1, double offset)
{
double date;
- register struct event *e;
+ struct event *e;
e = e1;
date = Now.date + offset;
e->date = date;
-# ifdef xTRACE
+#ifdef xTRACE
if (Trace)
printf("reschedule: type %d parm %d %d %d @ %.2f\n",
e->evcode, e->x, e->y, e->systemname, date);
-# endif
+#endif
return;
}
** The event at slot 'e' is deleted.
*/
-unschedule(e1)
-struct event *e1;
+void
+unschedule(struct event *e1)
{
- register struct event *e;
+ struct event *e;
e = e1;
-# ifdef xTRACE
+#ifdef xTRACE
if (Trace)
printf("unschedule: type %d @ %.2f parm %d %d %d\n",
e->evcode, e->date, e->x, e->y, e->systemname);
-# endif
+#endif
Now.eventptr[e->evcode & E_EVENT] = 0;
- e->date = 1e50;
+ e->date = TOOLARGE;
e->evcode = 0;
return;
}
** figure.
*/
-struct event *xsched(ev1, factor, x, y, z)
-int ev1;
-int factor;
-int x, y, z;
+struct event *
+xsched(int ev1, int factor, int x, int y, int z)
{
- register int ev;
+ int ev;
+ double when;
ev = ev1;
- return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
+ when = -Param.eventdly[ev] * Param.time * log(franf()) / factor;
+ return (schedule(ev, when, x, y, z));
}
** division factor. Look at the code to see what really happens.
*/
-xresched(e1, ev1, factor)
-struct event *e1;
-int ev1;
-int factor;
+void
+xresched(struct event *e1, int ev1, int factor)
{
- register int ev;
- register struct event *e;
+ int ev;
+ struct event *e;
+ double when;
ev = ev1;
e = e1;
- reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
+ when = -Param.eventdly[ev] * Param.time * log(franf()) / factor;
+ reschedule(e, when);
}