diff options
Diffstat (limited to 'hunt/hunt/playit.c')
-rw-r--r-- | hunt/hunt/playit.c | 346 |
1 files changed, 173 insertions, 173 deletions
diff --git a/hunt/hunt/playit.c b/hunt/hunt/playit.c index 6ab174a2..34393fa9 100644 --- a/hunt/hunt/playit.c +++ b/hunt/hunt/playit.c @@ -1,101 +1,101 @@ -/* $NetBSD: playit.c,v 1.11 2009/07/04 01:58:57 dholland Exp $ */ +/* $NetBSD: playit.c,v 1.12 2009/07/04 05:01:16 dholland Exp $ */ /* * Copyright (c) 1983-2003, 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 are + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are * met: - * - * + Redistributions of source code must retain the above copyright + * + * + Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the + * + 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. - * + Neither the name of the University of California, San Francisco nor - * the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written + * + Neither the name of the University of California, San Francisco nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: playit.c,v 1.11 2009/07/04 01:58:57 dholland Exp $"); +__RCSID("$NetBSD: playit.c,v 1.12 2009/07/04 05:01:16 dholland Exp $"); #endif /* not lint */ -# include <sys/file.h> -# include <sys/poll.h> -# include <err.h> -# include <errno.h> -# include <curses.h> -# include <ctype.h> -# include <signal.h> -# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) -# include <termios.h> -# include <unistd.h> -# endif -# include "hunt.h" - -# ifndef FREAD -# define FREAD 1 -# endif - -# if !defined(USE_CURSES) || !defined(TERMINFO) -# define beep() (void) putchar(CTRL('G')) -# endif -# if !defined(USE_CURSES) -# undef refresh -# define refresh() (void) fflush(stdout); -# endif -# ifdef USE_CURSES -# define clear_eol() clrtoeol() -# define put_ch addch -# define put_str addstr -# endif - -static int nchar_send; -# ifndef USE_CURSES -char screen[SCREEN_HEIGHT][SCREEN_WIDTH2], blanks[SCREEN_WIDTH]; -int cur_row, cur_col; -# endif -# ifdef OTTO -int Otto_count; -int Otto_mode; -static int otto_y, otto_x; -static char otto_face; -# endif - -# define MAX_SEND 5 -# define STDIN 0 +#include <sys/file.h> +#include <sys/poll.h> +#include <err.h> +#include <errno.h> +#include <curses.h> +#include <ctype.h> +#include <signal.h> +#if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) +#include <termios.h> +#include <unistd.h> +#endif +#include "hunt.h" + +#ifndef FREAD +#define FREAD 1 +#endif + +#if !defined(USE_CURSES) || !defined(TERMINFO) +#define beep() (void) putchar(CTRL('G')) +#endif +#if !defined(USE_CURSES) +#undef refresh +#define refresh() (void) fflush(stdout); +#endif +#ifdef USE_CURSES +#define clear_eol() clrtoeol() +#define put_ch addch +#define put_str addstr +#endif + +static int nchar_send; +#ifndef USE_CURSES +char screen[SCREEN_HEIGHT][SCREEN_WIDTH2], blanks[SCREEN_WIDTH]; +int cur_row, cur_col; +#endif +#ifdef OTTO +int Otto_count; +int Otto_mode; +static int otto_y, otto_x; +static char otto_face; +#endif + +#define MAX_SEND 5 +#define STDIN 0 /* * ibuf is the input buffer used for the stream from the driver. * It is small because we do not check for user input when there * are characters in the input buffer. */ -static int icnt = 0; -static unsigned char ibuf[256], *iptr = ibuf; +static int icnt = 0; +static unsigned char ibuf[256], *iptr = ibuf; -#define GETCHR() (--icnt < 0 ? getchr() : *iptr++) +#define GETCHR() (--icnt < 0 ? getchr() : *iptr++) #if !defined(BSD_RELEASE) || BSD_RELEASE < 44 -extern int _putchar(); +extern int _putchar(); #endif -static unsigned char getchr(void); -static void send_stuff(void); +static unsigned char getchr(void); +static void send_stuff(void); /* * playit: @@ -105,9 +105,9 @@ static void send_stuff(void); void playit(void) { - int ch; - int y, x; - u_int32_t version; + int ch; + int y, x; + u_int32_t version; if (read(Socket, &version, LONGLEN) != LONGLEN) { bad_con(); @@ -118,29 +118,29 @@ playit(void) /* NOTREACHED */ } errno = 0; -# ifdef OTTO +#ifdef OTTO Otto_count = 0; -# endif +#endif nchar_send = MAX_SEND; while ((ch = GETCHR()) != EOF) { -# ifdef DEBUG +#ifdef DEBUG fputc(ch, stderr); -# endif +#endif switch (ch & 0377) { case MOVE: y = GETCHR(); x = GETCHR(); -# ifdef USE_CURSES +#ifdef USE_CURSES move(y, x); -# else +#else mvcur(cur_row, cur_col, y, x); cur_row = y; cur_col = x; -# endif +#endif break; case ADDCH: ch = GETCHR(); -# ifdef OTTO +#ifdef OTTO switch (ch) { case '<': @@ -148,15 +148,15 @@ playit(void) case '^': case 'v': otto_face = ch; -# ifdef USE_CURSES +#ifdef USE_CURSES getyx(stdscr, otto_y, otto_x); -# else +#else otto_y = cur_row; otto_x = cur_col; -# endif +#endif break; } -# endif +#endif put_ch(ch); break; case CLRTOEOL: @@ -184,31 +184,31 @@ playit(void) case READY: refresh(); if (nchar_send < 0) -# if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) +#if defined(HPUX) || (defined(BSD_RELEASE) && BSD_RELEASE >= 44) tcflush(STDIN, TCIFLUSH); -# else -# ifndef TCFLSH +#else +#ifndef TCFLSH (void) ioctl(STDIN, TIOCFLUSH, &in); -# else +#else (void) ioctl(STDIN, TCFLSH, 0); -# endif -# endif +#endif +#endif nchar_send = MAX_SEND; -# ifndef OTTO +#ifndef OTTO (void) GETCHR(); -# else +#else Otto_count -= (GETCHR() & 0xff); if (!Am_monitor) { -# ifdef DEBUG +#ifdef DEBUG fputc('0' + Otto_count, stderr); -# endif +#endif if (Otto_count == 0 && Otto_mode) otto(otto_y, otto_x, otto_face); } -# endif +#endif break; default: -# ifdef OTTO +#ifdef OTTO switch (ch) { case '<': @@ -216,15 +216,15 @@ playit(void) case '^': case 'v': otto_face = ch; -# ifdef USE_CURSES +#ifdef USE_CURSES getyx(stdscr, otto_y, otto_x); -# else +#else otto_y = cur_row; otto_x = cur_col; -# endif +#endif break; } -# endif +#endif put_ch(ch); break; } @@ -243,8 +243,8 @@ out: static unsigned char getchr(void) { - struct pollfd set[2]; - int nfds; + struct pollfd set[2]; + int nfds; set[0].fd = Socket; set[0].events = POLLIN; @@ -280,9 +280,9 @@ one_more_time: static void send_stuff(void) { - int count; - char *sp, *nsp; - static char inp[sizeof Buf]; + int count; + char *sp, *nsp; + static char inp[sizeof Buf]; count = read(STDIN, Buf, sizeof Buf); if (count <= 0) @@ -306,9 +306,9 @@ send_stuff(void) nsp++; count = nsp - inp; if (count) { -# ifdef OTTO +#ifdef OTTO Otto_count += count; -# endif +#endif nchar_send -= count; if (nchar_send < 0) count += nchar_send; @@ -323,21 +323,21 @@ send_stuff(void) int quit(int old_status) { - int explain, ch; + int explain, ch; if (Last_player) return Q_QUIT; -# ifdef OTTO +#ifdef OTTO if (Otto_mode) return Q_CLOAK; -# endif -# ifdef USE_CURSES +#endif +#ifdef USE_CURSES move(HEIGHT, 0); -# else +#else mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; -# endif +#endif put_str("Re-enter game [ynwo]? "); clear_eol(); explain = FALSE; @@ -350,16 +350,16 @@ quit(int old_status) else if (ch == 'o') break; else if (ch == 'n') { -# ifndef INTERNET +#ifndef INTERNET return Q_QUIT; -# else -# ifdef USE_CURSES +#else +#ifdef USE_CURSES move(HEIGHT, 0); -# else +#else mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; -# endif +#endif put_str("Write a parting message [yn]? "); clear_eol(); refresh(); @@ -371,22 +371,22 @@ quit(int old_status) if (ch == 'n') return Q_QUIT; } -# endif +#endif } -# ifdef INTERNET +#ifdef INTERNET else if (ch == 'w') { - static char buf[WIDTH + WIDTH % 2]; - char *cp, c; + static char buf[WIDTH + WIDTH % 2]; + char *cp, c; get_message: c = ch; /* save how we got here */ -# ifdef USE_CURSES +#ifdef USE_CURSES move(HEIGHT, 0); -# else +#else mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; -# endif +#endif put_str("Message: "); clear_eol(); refresh(); @@ -395,42 +395,42 @@ get_message: refresh(); if ((ch = getchar()) == '\n' || ch == '\r') break; -# if defined(TERMINFO) || BSD_RELEASE >= 44 +#if defined(TERMINFO) || BSD_RELEASE >= 44 if (ch == erasechar()) -# else +#else if (ch == _tty.sg_erase) -# endif +#endif { if (cp > buf) { -# ifdef USE_CURSES +#ifdef USE_CURSES int y, x; getyx(stdscr, y, x); move(y, x - 1); -# else +#else mvcur(cur_row, cur_col, cur_row, cur_col - 1); cur_col -= 1; -# endif +#endif cp -= 1; clear_eol(); } continue; } -# if defined(TERMINFO) || BSD_RELEASE >= 44 +#if defined(TERMINFO) || BSD_RELEASE >= 44 else if (ch == killchar()) -# else +#else else if (ch == _tty.sg_kill) -# endif +#endif { -# ifdef USE_CURSES +#ifdef USE_CURSES int y, x; getyx(stdscr, y, x); move(y, x - (cp - buf)); -# else +#else mvcur(cur_row, cur_col, cur_row, cur_col - (cp - buf)); cur_col -= cp - buf; -# endif +#endif cp = buf; clear_eol(); continue; @@ -447,7 +447,7 @@ get_message: Send_message = buf; return (c == 'w') ? old_status : Q_MESSAGE; } -# endif +#endif beep(); if (!explain) { put_str("(Yes, No, Write message, or Options) "); @@ -455,18 +455,18 @@ get_message: } } -# ifdef USE_CURSES +#ifdef USE_CURSES move(HEIGHT, 0); -# else +#else mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; -# endif -# ifdef FLY +#endif +#ifdef FLY put_str("Scan, Cloak, Flying, or Quit? "); -# else +#else put_str("Scan, Cloak, or Quit? "); -# endif +#endif clear_eol(); refresh(); explain = FALSE; @@ -477,26 +477,26 @@ get_message: return Q_SCAN; else if (ch == 'c') return Q_CLOAK; -# ifdef FLY +#ifdef FLY else if (ch == 'f') return Q_FLY; -# endif +#endif else if (ch == 'q') return Q_QUIT; beep(); if (!explain) { -# ifdef FLY +#ifdef FLY put_str("[SCFQ] "); -# else +#else put_str("[SCQ] "); -# endif +#endif explain = TRUE; } refresh(); } } -# ifndef USE_CURSES +#ifndef USE_CURSES void put_ch(char ch) { @@ -521,17 +521,17 @@ put_str(char *s) while (*s) put_ch(*s++); } -# endif +#endif void clear_the_screen(void) { -# ifdef USE_CURSES +#ifdef USE_CURSES clear(); move(0, 0); refresh(); -# else - int i; +#else + int i; if (blanks[0] == '\0') for (i = 0; i < SCREEN_WIDTH; i++) @@ -579,42 +579,42 @@ clear_eol(void) } memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col); } -# endif +#endif void redraw_screen(void) { -# ifdef USE_CURSES +#ifdef USE_CURSES clearok(stdscr, TRUE); touchwin(stdscr); -# else - int i; -# ifndef NOCURSES - static int first = 1; +#else + int i; +#ifndef NOCURSES + static int first = 1; if (first) { curscr = newwin(SCREEN_HEIGHT, SCREEN_WIDTH, 0, 0); if (curscr == NULL) errx(1, "Can't create curscr"); -# if !defined(BSD_RELEASE) || BSD_RELEASE < 44 +#if !defined(BSD_RELEASE) || BSD_RELEASE < 44 for (i = 0; i < SCREEN_HEIGHT; i++) curscr->_y[i] = screen[i]; -# endif +#endif first = 0; } -# if defined(BSD_RELEASE) && BSD_RELEASE >= 44 +#if defined(BSD_RELEASE) && BSD_RELEASE >= 44 for (i = 0; i < SCREEN_HEIGHT; i++) { - int j; + int j; for (j = 0; j < SCREEN_WIDTH; j++) curscr->lines[i]->line[j].ch = screen[i][j]; } curscr->cury = cur_row; curscr->curx = cur_col; -# else +#else curscr->_cury = cur_row; curscr->_curx = cur_col; -# endif +#endif clearok(curscr, TRUE); touchwin(curscr); wrefresh(curscr); @@ -639,7 +639,7 @@ redraw_screen(void) void do_message(void) { - u_int32_t version; + u_int32_t version; if (read(Socket, &version, LONGLEN) != LONGLEN) { bad_con(); @@ -649,11 +649,11 @@ do_message(void) bad_ver(); /* NOTREACHED */ } -# ifdef INTERNET +#ifdef INTERNET if (write(Socket, Send_message, strlen(Send_message)) < 0) { bad_con(); /* NOTREACHED */ } -# endif +#endif (void) close(Socket); } |