X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/a1870bc7909b311399735583c9363b06af9b0a56..70f825fc24933eacf0a9d8619a5cb35e7153b41a:/atc/update.c diff --git a/atc/update.c b/atc/update.c index fd7c8a05..963c57f3 100644 --- a/atc/update.c +++ b/atc/update.c @@ -1,4 +1,4 @@ -/* $NetBSD: update.c,v 1.5 1997/01/13 06:50:27 tls Exp $ */ +/* $NetBSD: update.c,v 1.14 2005/08/10 17:53:28 rpaulo Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -15,11 +15,7 @@ * 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. * @@ -45,20 +41,23 @@ * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ +#include #ifndef lint #if 0 static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: update.c,v 1.5 1997/01/13 06:50:27 tls 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 SYSV alarm(0); @@ -212,19 +211,17 @@ update() * we don't update props on odd updates. */ if ((rand() % sp->newplane_time) == 0) - addplane(); + (void)addplane(); #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; @@ -232,28 +229,27 @@ command(pp) (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); @@ -261,7 +257,8 @@ name(p) return ('a' + p->plane_no); } -number(l) +int +number(int l) { if (l < 'a' && l > 'z' && l < 'A' && l > 'Z') return (-1); @@ -271,7 +268,8 @@ number(l) return (l - 'A'); } -next_plane() +int +next_plane(void) { static int last_plane = -1; PLANE *pp; @@ -299,12 +297,13 @@ next_plane() 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; - memset(&p, 0, sizeof (p)); + (void)memset(&p, 0, sizeof (p)); p.status = S_MARKED; p.plane_type = random() % 2; @@ -332,13 +331,13 @@ addplane() 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; @@ -359,7 +358,9 @@ addplane() p.plane_no = pnum; pp = newplane(); - memcpy(pp, &p, 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); @@ -369,8 +370,8 @@ addplane() return (pp->dest_type); } -PLANE * -findplane(n) +PLANE * +findplane(int n) { PLANE *pp; @@ -383,17 +384,19 @@ findplane(n) 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);