-/* $NetBSD: update.c,v 1.3 1995/03/21 15:04:37 cgd Exp $ */
+/* $NetBSD: update.c,v 1.14 2005/08/10 17:53:28 rpaulo Exp $ */
/*-
* Copyright (c) 1990, 1993
* 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.
*
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: update.c,v 1.3 1995/03/21 15:04:37 cgd Exp $";
+__RCSID("$NetBSD: update.c,v 1.14 2005/08/10 17:53:28 rpaulo Exp $");
#endif
-#endif not lint
+#endif /* not lint */
#include "include.h"
-update()
+/* ARGSUSED */
+void
+update(int dummy __attribute__((__unused__)))
{
- int i, dir_diff, mask, unclean;
- PLANE *pp, *p1, *p2, *p;
+ int i, dir_diff, unclean;
+ PLANE *pp, *p1, *p2;
-#ifdef BSD
- mask = sigblock(sigmask(SIGINT));
-#endif
#ifdef SYSV
alarm(0);
signal(SIGALRM, update);
* we don't update props on odd updates.
*/
if ((rand() % sp->newplane_time) == 0)
- addplane();
+ (void)addplane();
-#ifdef BSD
- sigsetmask(mask);
-#endif
#ifdef SYSV
alarm(sp->update_secs);
#endif
}
-char *
-command(pp)
- PLANE *pp;
+const char *
+command(const PLANE *pp)
{
static char buf[50], *bp, *comm_start;
- char *index();
buf[0] = '\0';
bp = buf;
(pp->fuel < LOWFUEL) ? '*' : ' ',
(pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no);
- comm_start = bp = index(buf, '\0');
+ comm_start = bp = strchr(buf, '\0');
if (pp->altitude == 0)
(void)sprintf(bp, "Holding @ A%d", pp->orig_no);
else if (pp->new_dir >= MAXDIR || pp->new_dir < 0)
- strcpy(bp, "Circle");
+ (void)strcpy(bp, "Circle");
else if (pp->new_dir != pp->dir)
(void)sprintf(bp, "%d", dir_deg(pp->new_dir));
- bp = index(buf, '\0');
+ bp = strchr(buf, '\0');
if (pp->delayd)
(void)sprintf(bp, " @ B%d", pp->delayd_no);
- bp = index(buf, '\0');
+ bp = strchr(buf, '\0');
if (*comm_start == '\0' &&
(pp->status == S_UNMARKED || pp->status == S_IGNORED))
- strcpy(bp, "---------");
+ (void)strcpy(bp, "---------");
return (buf);
}
-/* char */
-name(p)
- PLANE *p;
+char
+name(const PLANE *p)
{
if (p->plane_type == 0)
return ('A' + p->plane_no);
return ('a' + p->plane_no);
}
-number(l)
+int
+number(int l)
{
if (l < 'a' && l > 'z' && l < 'A' && l > 'Z')
return (-1);
return (l - 'A');
}
-next_plane()
+int
+next_plane(void)
{
static int last_plane = -1;
PLANE *pp;
return (last_plane);
}
-addplane()
+int
+addplane(void)
{
PLANE p, *pp, *p1;
- int i, num_starts, close, rnd, rnd2, pnum;
+ int i, num_starts, isclose, rnd, rnd2, pnum;
- bzero(&p, sizeof (p));
+ (void)memset(&p, 0, sizeof (p));
p.status = S_MARKED;
p.plane_type = random() % 2;
p.ypos = sp->exit[rnd2].y;
p.new_dir = p.dir = sp->exit[rnd2].dir;
p.altitude = p.new_altitude = 7;
- close = 0;
+ isclose = 0;
for (p1 = air.head; p1 != NULL; p1 = p1->next)
if (too_close(p1, &p, 4)) {
- close++;
+ isclose++;
break;
}
- if (close)
+ if (isclose)
continue;
} else {
p.orig_type = T_AIRPORT;
p.plane_no = pnum;
pp = newplane();
- bcopy(&p, pp, sizeof (p));
+ if (pp == NULL)
+ loser(NULL, "Out of memory!");
+ (void)memcpy(pp, &p, sizeof (p));
if (pp->orig_type == T_AIRPORT)
append(&ground, pp);
return (pp->dest_type);
}
-PLANE *
-findplane(n)
+PLANE *
+findplane(int n)
{
PLANE *pp;
return (NULL);
}
-too_close(p1, p2, dist)
- PLANE *p1, *p2;
+int
+too_close(const PLANE *p1, const PLANE *p2, int dist)
{
if (ABS(p1->altitude - p2->altitude) <= dist &&
- ABS(p1->xpos - p2->xpos) <= dist && ABS(p1->ypos - p2->ypos) <= dist)
+ ABS(p1->xpos - p2->xpos) <= dist &&
+ ABS(p1->ypos - p2->ypos) <= dist)
return (1);
else
return (0);
}
-dir_deg(d)
+int
+dir_deg(int d)
{
switch (d) {
case 0: return (0);