diff options
author | 1997-10-10 16:32:15 +0000 | |
---|---|---|
committer | 1997-10-10 16:32:15 +0000 | |
commit | 50f99331097302f77db413ba7ad7299d928163eb (patch) | |
tree | 376410fecfef0c2ac47f5b4f0643e6a84a373cdc /hunt/hunt | |
parent | a25e10613cc56cac1b954b119f757a272dee9bc8 (diff) | |
download | bsdgames-darwin-50f99331097302f77db413ba7ad7299d928163eb.tar.gz bsdgames-darwin-50f99331097302f77db413ba7ad7299d928163eb.tar.zst bsdgames-darwin-50f99331097302f77db413ba7ad7299d928163eb.zip |
Yet Another Monster Commit:
- WARNSify
- getopt returns -1 not EOF
- select() uses an fd_set, not int/long; modify code to use FD_* et al
instead of direct bitwise operations
- in otto.c::look (renamed to ottolook() to prevent name clash), the
case WEST section had a 'goto cont_east', instead of 'goto cont_west'.
(picked up by WARNS=1, because cont_west was an unused label because
of this typo). probably meant that otto got lost in the maze :-/
- deprecate register, convert bcmp() -> memcmp()
Diffstat (limited to 'hunt/hunt')
-rw-r--r-- | hunt/hunt/connect.c | 9 | ||||
-rw-r--r-- | hunt/hunt/hunt.6 | 2 | ||||
-rw-r--r-- | hunt/hunt/hunt.c | 105 | ||||
-rw-r--r-- | hunt/hunt/otto.c | 79 | ||||
-rw-r--r-- | hunt/hunt/playit.c | 75 |
5 files changed, 165 insertions, 105 deletions
diff --git a/hunt/hunt/connect.c b/hunt/hunt/connect.c index 587f8b40..ae91c2ab 100644 --- a/hunt/hunt/connect.c +++ b/hunt/hunt/connect.c @@ -1,12 +1,20 @@ +/* $NetBSD: connect.c,v 1.2 1997/10/10 16:32:23 lukem Exp $ */ /* * Hunt * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold * San Francisco, California */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: connect.c,v 1.2 1997/10/10 16:32:23 lukem Exp $"); +#endif /* not lint */ + # include "hunt.h" # include <signal.h> +# include <unistd.h> +void do_connect(name, team, enter_status) char *name; char team; @@ -14,7 +22,6 @@ long enter_status; { static long uid; static long mode; - extern char *ttyname(); if (uid == 0) uid = htonl(getuid()); diff --git a/hunt/hunt/hunt.6 b/hunt/hunt/hunt.6 index da6b49db..b45d8271 100644 --- a/hunt/hunt/hunt.6 +++ b/hunt/hunt/hunt.6 @@ -1,3 +1,5 @@ +.\" $NetBSD: hunt.6,v 1.3 1997/10/10 16:32:30 lukem Exp $ +.\" .\" hunt .\" Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold .\" San Francisco, California diff --git a/hunt/hunt/hunt.c b/hunt/hunt/hunt.c index 6599b87e..f92f6bf5 100644 --- a/hunt/hunt/hunt.c +++ b/hunt/hunt/hunt.c @@ -1,21 +1,30 @@ +/* $NetBSD: hunt.c,v 1.2 1997/10/10 16:32:34 lukem Exp $ */ /* * Hunt * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold * San Francisco, California */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: hunt.c,v 1.2 1997/10/10 16:32:34 lukem Exp $"); +#endif /* not lint */ + +# include <sys/stat.h> +# include <sys/time.h> +# include <ctype.h> # include <errno.h> +# include <curses.h> +# include <signal.h> +# include <stdlib.h> +# include <string.h> # if !defined(USE_CURSES) && defined(BSD_RELEASE) && BSD_RELEASE >= 44 # include <termios.h> static struct termios saved_tty; # endif -# include <curses.h> -# include <string.h> +# include <unistd.h> + # include "hunt.h" -# include <signal.h> -# include <ctype.h> -# include <sys/stat.h> -# include <sys/time.h> /* * Some old versions of curses don't have these defined @@ -73,19 +82,24 @@ static char team = ' '; static int in_visual; extern int cur_row, cur_col; -extern char *tgoto(); +void dump_scores __P((SOCKET)); +long env_init __P((long)); +void fill_in_blanks __P((void)); +void leave __P((int, char *)); +int main __P((int, char *[])); # ifdef INTERNET -extern SOCKET *list_drivers(); +SOCKET *list_drivers __P((void)); # endif /* * main: * Main program for local process */ +int main(ac, av) -int ac; -char **av; + int ac; + char **av; { char *term; int c; @@ -94,11 +108,9 @@ char **av; extern int optind; extern char *optarg; long enter_status; - SIGNAL_TYPE intr(), sigterm(), sigemt(), tstp(); - long env_init(), quit(); enter_status = env_init((long) Q_CLOAK); - while ((c = getopt(ac, av, "Sbcfh:l:mn:op:qst:w:")) != EOF) { + while ((c = getopt(ac, av, "Sbcfh:l:mn:op:qst:w:")) != -1) { switch (c) { case 'l': /* rsh compatibility */ case 'n': @@ -341,10 +353,12 @@ char **av; } leave(0, (char *) NULL); /* NOTREACHED */ + return(0); } # ifdef INTERNET # ifdef BROADCAST +int broadcast_vec(s, vector) int s; /* socket */ struct sockaddr **vector; @@ -383,7 +397,7 @@ list_drivers() char local_name[256]; static initial = TRUE; static struct in_addr local_address; - register struct hostent *hp; + struct hostent *hp; extern int errno; # ifdef BROADCAST static int brdc; @@ -395,7 +409,7 @@ list_drivers() static SOCKET *listv; static unsigned int listmax; unsigned int listc; - int mask; + fd_set mask; struct timeval wait; if (initial) { /* do one time initialization */ @@ -502,10 +516,10 @@ get_response: listmax * sizeof(SOCKET)); } - mask = 1 << test_socket; - if (select(test_socket + 1, &mask, NULL, NULL, &wait) == 1 - && recvfrom(test_socket, (char *) &port_num, sizeof port_num, - 0, (struct sockaddr *) &listv[listc], &namelen) > 0) { + FD_SET(test_socket, &mask); + if (select(test_socket + 1, &mask, NULL, NULL, &wait) == 1 && + recvfrom(test_socket, (char *) &port_num, sizeof(port_num), + 0, (struct sockaddr *) &listv[listc], &namelen) > 0) { /* * Note that we do *not* convert from network to host * order since the port number *should* be in network @@ -543,8 +557,9 @@ test_one_host: goto get_response; } +void find_driver(do_startup) -FLAG do_startup; + FLAG do_startup; { SOCKET *hosts; @@ -610,6 +625,7 @@ FLAG do_startup; find_driver(FALSE); } +void dump_scores(host) SOCKET host; { @@ -639,9 +655,10 @@ dump_scores(host) # endif +void start_driver() { - register int procid; + int procid; # ifdef MONITOR if (Am_monitor) { @@ -703,6 +720,7 @@ start_driver() * We had a bad connection. For the moment we assume that this * means the game is full. */ +void bad_con() { leave(1, "The game is full. Sorry."); @@ -713,6 +731,7 @@ bad_con() * bad_ver: * version number mismatch. */ +void bad_ver() { leave(1, "Version number mismatch. No go."); @@ -724,7 +743,8 @@ bad_ver() * Handle a terminate signal */ SIGNAL_TYPE -sigterm() +sigterm(dummy) + int dummy; { leave(0, (char *) NULL); /* NOTREACHED */ @@ -736,7 +756,8 @@ sigterm() * Handle a emt signal - shouldn't happen on vaxes(?) */ SIGNAL_TYPE -sigemt() +sigemt(dummy) + int dummy; { leave(1, "Unable to start driver. Try again."); /* NOTREACHED */ @@ -748,7 +769,8 @@ sigemt() * Handle an alarm signal */ SIGNAL_TYPE -sigalrm() +sigalrm(dummy) + int dummy; { return; } @@ -758,10 +780,11 @@ sigalrm() * rmnl: * Remove a '\n' at the end of a string if there is one */ +void rmnl(s) -char *s; + char *s; { - register char *cp; + char *cp; cp = strrchr(s, '\n'); if (cp != NULL) @@ -773,11 +796,12 @@ char *s; * Handle a interrupt signal */ SIGNAL_TYPE -intr() +intr(dummy) + int dummy; { - register int ch; - register int explained; - register int y, x; + int ch; + int explained; + int y, x; (void) signal(SIGINT, SIG_IGN); # ifdef USE_CURSES @@ -832,9 +856,10 @@ intr() * Leave the game somewhat gracefully, restoring all current * tty stats. */ +void leave(eval, mesg) -int eval; -char *mesg; + int eval; + char *mesg; { if (in_visual) { # ifdef USE_CURSES @@ -864,7 +889,8 @@ char *mesg; * Handle stop and start signals */ SIGNAL_TYPE -tstp() +tstp(dummy) + int dummy; { # if BSD_RELEASE < 44 static struct sgttyb tty; @@ -908,10 +934,10 @@ tstp() # if defined(BSD_RELEASE) && BSD_RELEASE < 43 char * strpbrk(s, brk) - register char *s, *brk; + char *s, *brk; { - register char *p; - register c; + char *p; + c; while (c = *s) { for (p = brk; *p; p++) @@ -927,7 +953,7 @@ long env_init(enter_status) long enter_status; { - register int i; + int i; char *envp, *envname, *s; for (i = 0; i < 256; i++) @@ -1032,10 +1058,11 @@ env_init(enter_status) return enter_status; } +void fill_in_blanks() { - register int i; - register char *cp; + int i; + char *cp; again: if (name[0] != '\0') { diff --git a/hunt/hunt/otto.c b/hunt/hunt/otto.c index ab3b9029..773ceb7e 100644 --- a/hunt/hunt/otto.c +++ b/hunt/hunt/otto.c @@ -1,3 +1,4 @@ +/* $NetBSD: otto.c,v 1.2 1997/10/10 16:32:39 lukem Exp $ */ # ifdef OTTO /* * otto - a hunt otto-matic player @@ -7,15 +8,21 @@ * automatic players to link to. If you write your own "otto" * please let us know what subroutines you would expect in the * subroutine library. - * - * $Id: otto.c,v 1.1.1.1 1997/10/04 09:00:14 mrg Exp $ */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: otto.c,v 1.2 1997/10/10 16:32:39 lukem Exp $"); +#endif /* not lint */ + +# include <sys/time.h> # include <curses.h> # include <ctype.h> -# include "hunt.h" -# include <sys/time.h> # include <signal.h> +# include <stdlib.h> +# include <unistd.h> +# include "hunt.h" + # undef WALL # undef NORTH # undef SOUTH @@ -106,24 +113,28 @@ STATIC int num_turns; /* for wandering */ STATIC char been_there[HEIGHT][WIDTH2]; STATIC struct itimerval pause_time = { { 0, 0 }, { 0, 55000 }}; -STATIC int stop_look(); -STATIC int look_around(); -STATIC int face_and_move_direction(); -STATIC int attack(); -STATIC int duck(); -STATIC int go_for_ammo(); -STATIC int wander(); +STATIC void attack __P((int, struct item *)); +STATIC void duck __P((int)); +STATIC void face_and_move_direction __P((int, int)); +STATIC int go_for_ammo __P((char)); +STATIC void ottolook __P((int, struct item *)); +STATIC void look_around __P((void)); +STATIC SIGNAL_TYPE nothing __P((int)); +STATIC int stop_look __P((struct item *, char, int, int)); +STATIC void wander __P((void)); STATIC SIGNAL_TYPE -nothing() +nothing(dummy) + int dummy; { } +void otto(y, x, face) int y, x; char face; { - register int i; + int i; extern int Otto_count; int old_mask; @@ -190,7 +201,7 @@ done: # define direction(abs,rel) (((abs) + (rel)) % NUMDIRECTIONS) -STATIC +STATIC int stop_look(itemp, c, dist, side) struct item *itemp; char c; @@ -265,13 +276,15 @@ stop_look(itemp, c, dist, side) } } -look(rel_dir, itemp) +STATIC void +ottolook(rel_dir, itemp) int rel_dir; struct item *itemp; { - register int r, c; - register char ch; + int r, c; + char ch; + r = 0; itemp->what = 0; itemp->distance = -1; itemp->flags = DEADEND|BEEN; /* true until proven false */ @@ -325,7 +338,7 @@ look(rel_dir, itemp) for (r = row - 1; r < row + 2; r++) { ch = SCREEN(r, c); if (stop_look(itemp, ch, col - c, row - r)) - goto cont_east; + goto cont_west; if (r == row && !been_there[r][c]) itemp->flags &= ~BEEN; } @@ -363,15 +376,15 @@ look(rel_dir, itemp) } } -STATIC +STATIC void look_around() { - register int i; + int i; for (i = 0; i < NUMDIRECTIONS; i++) { - look(i, &flbr[i]); + ottolook(i, &flbr[i]); # ifdef DEBUG - fprintf(debug, " look(%c)=%c(%d)(0x%x)", + fprintf(debug, " ottolook(%c)=%c(%d)(0x%x)", RELCHARS[i], flbr[i].what, flbr[i].distance, flbr[i].flags); # endif } @@ -381,23 +394,23 @@ look_around() * as a side effect modifies facing and location (row, col) */ -STATIC +STATIC void face_and_move_direction(rel_dir, distance) int rel_dir, distance; { - register int old_facing; - register char cmd; + int old_facing; + char cmd; old_facing = facing; cmd = DIRKEYS[facing = direction(facing, rel_dir)]; if (rel_dir != FRONT) { - register int i; + int i; struct item items[NUMDIRECTIONS]; command[comlen++] = toupper(cmd); if (distance == 0) { - /* rotate look's to be in right position */ + /* rotate ottolook's to be in right position */ for (i = 0; i < NUMDIRECTIONS; i++) items[i] = flbr[(i + old_facing) % NUMDIRECTIONS]; @@ -418,7 +431,7 @@ face_and_move_direction(rel_dir, distance) } } -STATIC +STATIC void attack(rel_dir, itemp) int rel_dir; struct item *itemp; @@ -446,7 +459,7 @@ attack(rel_dir, itemp) } } -STATIC +STATIC void duck(rel_dir) int rel_dir; { @@ -496,11 +509,11 @@ duck(rel_dir) * go for the closest mine if possible */ -STATIC +STATIC int go_for_ammo(mine) char mine; { - register int i, rel_dir, dist; + int i, rel_dir, dist; rel_dir = -1; dist = WIDTH; @@ -523,10 +536,10 @@ go_for_ammo(mine) return TRUE; } -STATIC +STATIC void wander() { - register int i, j, rel_dir, dir_mask, dir_count; + int i, j, rel_dir, dir_mask, dir_count; for (i = 0; i < NUMDIRECTIONS; i++) if (!(flbr[i].flags & BEEN) || flbr[i].distance <= 1) diff --git a/hunt/hunt/playit.c b/hunt/hunt/playit.c index 4a6046c9..e6776673 100644 --- a/hunt/hunt/playit.c +++ b/hunt/hunt/playit.c @@ -1,18 +1,25 @@ +/* $NetBSD: playit.c,v 1.2 1997/10/10 16:32:43 lukem Exp $ */ /* * Hunt * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold * San Francisco, California */ -# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) -# include <termios.h> -# endif +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: playit.c,v 1.2 1997/10/10 16:32:43 lukem Exp $"); +#endif /* not lint */ + +# include <sys/file.h> +# include <errno.h> # include <curses.h> # include <ctype.h> # include <signal.h> -# include <errno.h> +# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) +# include <termios.h> +# include <unistd.h> +# endif # include "hunt.h" -# include <sys/file.h> # ifndef FREAD # define FREAD 1 @@ -31,9 +38,7 @@ # define put_str addstr # endif -int input(); static int nchar_send; -static int in = FREAD; # ifndef USE_CURSES char screen[SCREEN_HEIGHT][SCREEN_WIDTH2], blanks[SCREEN_WIDTH]; int cur_row, cur_col; @@ -55,7 +60,6 @@ static char otto_face; */ static int icnt = 0; static unsigned char ibuf[256], *iptr = ibuf; -static unsigned char getchr(); #define GETCHR() (--icnt < 0 ? getchr() : *iptr++) @@ -63,16 +67,19 @@ static unsigned char getchr(); extern int _putchar(); #endif +static unsigned char getchr __P((void)); +static void send_stuff __P((void)); + /* * playit: * Play a given game, handling all the curses commands from * the driver. */ +void playit() { - register int ch; - register int y, x; - extern int errno; + int ch; + int y, x; long version; if (read(Socket, (char *) &version, LONGLEN) != LONGLEN) { @@ -206,17 +213,14 @@ out: * When this routine is called by GETCHR, we already know there are * no characters in the input buffer. */ -static -unsigned char +static unsigned char getchr() { - long readfds, s_readfds; - int driver_mask, stdin_mask; + fd_set readfds, s_readfds; int nfds, s_nfds; - driver_mask = 1L << Socket; - stdin_mask = 1L << STDIN; - s_readfds = driver_mask | stdin_mask; + FD_SET(Socket, &s_readfds); + FD_SET(STDIN, &s_readfds); s_nfds = (Socket > STDIN) ? Socket : STDIN; s_nfds++; @@ -228,9 +232,9 @@ one_more_time: nfds = select(nfds, &readfds, NULL, NULL, NULL); } while (nfds <= 0 && errno == EINTR); - if (readfds & stdin_mask) + if (FD_ISSET(STDIN, &readfds)) send_stuff(); - if ((readfds & driver_mask) == 0) + if (! FD_ISSET(Socket, &readfds)) goto one_more_time; icnt = read(Socket, ibuf, sizeof ibuf); if (icnt < 0) { @@ -248,10 +252,11 @@ one_more_time: * send_stuff: * Send standard input characters to the driver */ +static void send_stuff() { - register int count; - register char *sp, *nsp; + int count; + char *sp, *nsp; static char inp[sizeof Buf]; count = read(STDIN, Buf, sizeof Buf); @@ -270,8 +275,8 @@ send_stuff() Buf[count] = '\0'; nsp = inp; for (sp = Buf; *sp != '\0'; sp++) - if ((*nsp = map_key[*sp]) == 'q') - intr(); + if ((*nsp = map_key[(int)*sp]) == 'q') + intr(0); else nsp++; count = nsp - inp; @@ -290,11 +295,11 @@ send_stuff() * quit: * Handle the end of the game when the player dies */ -long +int quit(old_status) -long old_status; + int old_status; { - register int explain, ch; + int explain, ch; if (Last_player) return Q_QUIT; @@ -468,6 +473,7 @@ get_message: } # ifndef USE_CURSES +void put_ch(ch) char ch; { @@ -486,6 +492,7 @@ put_ch(ch) } } +void put_str(s) char *s; { @@ -494,6 +501,7 @@ put_str(s) } # endif +void clear_the_screen() { # ifdef USE_CURSES @@ -501,7 +509,7 @@ clear_the_screen() move(0, 0); refresh(); # else - register int i; + int i; if (blanks[0] == '\0') for (i = 0; i < SCREEN_WIDTH; i++) @@ -529,6 +537,7 @@ clear_the_screen() } #ifndef USE_CURSES +void clear_eol() { if (CE != NULL) @@ -550,13 +559,14 @@ clear_eol() } # endif +void redraw_screen() { # ifdef USE_CURSES clearok(stdscr, TRUE); touchwin(stdscr); # else - register int i; + int i; # ifndef NOCURSES static int first = 1; @@ -574,7 +584,8 @@ redraw_screen() } # if defined(BSD_RELEASE) && BSD_RELEASE >= 44 for (i = 0; i < SCREEN_HEIGHT; i++) { - register int j; + int j; + for (j = 0; j < SCREEN_WIDTH; j++) curscr->lines[i]->line[j].ch = screen[i][j]; } @@ -605,10 +616,10 @@ redraw_screen() * do_message: * Send a message to the driver and return */ +void do_message() { - extern int errno; - long version; + long version; if (read(Socket, (char *) &version, LONGLEN) != LONGLEN) { bad_con(); |