X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/f4bbbc82b97201e01b30fc2e56e1e2bf596f916f..cd13042d23065cae90a02dae4f7602a2b4eb7ce0:/atc/update.c diff --git a/atc/update.c b/atc/update.c index dafa74e7..4396aaba 100644 --- a/atc/update.c +++ b/atc/update.c @@ -1,4 +1,4 @@ -/* $NetBSD: update.c,v 1.16 2006/03/22 05:03:10 christos Exp $ */ +/* $NetBSD: update.c,v 1.25 2014/03/22 22:58:56 dholland Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -46,17 +46,22 @@ #if 0 static char sccsid[] = "@(#)update.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: update.c,v 1.16 2006/03/22 05:03:10 christos Exp $"); +__RCSID("$NetBSD: update.c,v 1.25 2014/03/22 22:58:56 dholland Exp $"); #endif #endif /* not lint */ #include "include.h" +static int next_plane(void); +static int too_close(const PLANE *p1, const PLANE *p2, int); +static int dir_deg(int); + /* ARGSUSED */ void -update(int dummy __attribute__((__unused__))) +update(int dummy __unused) { - int i, dir_diff, unclean; + int dir_diff, unclean; + unsigned i; PLANE *pp, *p1, *p2; #ifdef SYSV @@ -119,7 +124,7 @@ update(int dummy __attribute__((__unused__))) if (pp->delayd && pp->xpos == sp->beacon[pp->delayd_no].x && pp->ypos == sp->beacon[pp->delayd_no].y) { - pp->delayd = 0; + pp->delayd = false; if (pp->status == S_UNMARKED) pp->status = S_MARKED; } @@ -153,7 +158,7 @@ update(int dummy __attribute__((__unused__))) } if (pp->altitude > 9) /* "this is impossible" */ - loser(pp, "exceded flight ceiling."); + loser(pp, "exceeded flight ceiling."); if (pp->altitude <= 0) { for (i = 0; i < sp->num_airports; i++) if (pp->xpos == sp->airport[i].x && @@ -201,7 +206,8 @@ update(int dummy __attribute__((__unused__))) if (too_close(p1, p2, 1)) { static char buf[80]; - (void)sprintf(buf, "collided with plane '%c'.", + (void)snprintf(buf, sizeof(buf), + "collided with plane '%c'.", name(p2)); loser(p1, buf); } @@ -211,7 +217,7 @@ update(int dummy __attribute__((__unused__))) * we don't update props on odd updates. */ if ((rand() % sp->newplane_time) == 0) - (void)addplane(); + addplane(); #ifdef SYSV alarm(sp->update_secs); @@ -222,29 +228,34 @@ const char * command(const PLANE *pp) { static char buf[50], *bp, *comm_start; + size_t bpsize; buf[0] = '\0'; bp = buf; - (void)sprintf(bp, "%c%d%c%c%d: ", name(pp), pp->altitude, + bpsize = sizeof(buf); + (void)snprintf(bp, bpsize, "%c%d%c%c%u: ", name(pp), pp->altitude, (pp->fuel < LOWFUEL) ? '*' : ' ', (pp->dest_type == T_AIRPORT) ? 'A' : 'E', pp->dest_no); comm_start = bp = strchr(buf, '\0'); + bpsize = buf + sizeof(buf) - bp; if (pp->altitude == 0) - (void)sprintf(bp, "Holding @ A%d", pp->orig_no); + (void)snprintf(bp, bpsize, "Holding @ A%u", pp->orig_no); else if (pp->new_dir >= MAXDIR || pp->new_dir < 0) - (void)strcpy(bp, "Circle"); + (void)snprintf(bp, bpsize, "Circle"); else if (pp->new_dir != pp->dir) - (void)sprintf(bp, "%d", dir_deg(pp->new_dir)); + (void)snprintf(bp, bpsize, "%d", dir_deg(pp->new_dir)); bp = strchr(buf, '\0'); + bpsize = buf + sizeof(buf) - bp; if (pp->delayd) - (void)sprintf(bp, " @ B%d", pp->delayd_no); + (void)snprintf(bp, bpsize, " @ B%u", pp->delayd_no); bp = strchr(buf, '\0'); + bpsize = buf + sizeof(buf) - bp; if (*comm_start == '\0' && (pp->status == S_UNMARKED || pp->status == S_IGNORED)) - (void)strcpy(bp, "---------"); + (void)snprintf(bp, bpsize, "---------"); return (buf); } @@ -260,15 +271,15 @@ name(const PLANE *p) int number(int l) { - if (islower((unsigned char)l) + if (islower((unsigned char)l)) return (l - 'a'); - else if (isupper((unsigned char)l) + else if (isupper((unsigned char)l)) return (l - 'A'); else return (-1); } -int +static int next_plane(void) { static int last_plane = -1; @@ -292,16 +303,17 @@ next_plane(void) break; } } while (found && last_plane != start_plane); - if (last_plane == start_plane) + if (found) return (-1); return (last_plane); } -int +void addplane(void) { PLANE p, *pp, *p1; - int i, num_starts, isclose, rnd, rnd2, pnum; + int isclose, pnum; + unsigned num_starts, rnd, rnd2, i; (void)memset(&p, 0, sizeof (p)); @@ -351,10 +363,10 @@ addplane(void) break; } if (i >= num_starts) - return (-1); + return; pnum = next_plane(); if (pnum < 0) - return (-1); + return; p.plane_no = pnum; pp = newplane(); @@ -366,8 +378,6 @@ addplane(void) append(&ground, pp); else append(&air, pp); - - return (pp->dest_type); } PLANE * @@ -384,7 +394,7 @@ findplane(int n) return (NULL); } -int +static int too_close(const PLANE *p1, const PLANE *p2, int dist) { if (ABS(p1->altitude - p2->altitude) <= dist && @@ -395,7 +405,7 @@ too_close(const PLANE *p1, const PLANE *p2, int dist) return (0); } -int +static int dir_deg(int d) { switch (d) {