-/* $NetBSD: io.c,v 1.7 1995/03/21 15:08:53 cgd Exp $ */
+/* $NetBSD: io.c,v 1.21 2007/12/15 19:44:39 perry Exp $ */
/*-
* Copyright (c) 1980, 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.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: io.c,v 1.7 1995/03/21 15:08:53 cgd Exp $";
+__RCSID("$NetBSD: io.c,v 1.21 2007/12/15 19:44:39 perry Exp $");
#endif
#endif /* not lint */
#include <ctype.h>
#include <curses.h>
#include <signal.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
#include "deck.h"
#include "cribbage.h"
#include "cribcur.h"
char linebuf[LINESIZE];
-char *rankname[RANKS] = {
+const char *const rankname[RANKS] = {
"ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
"EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"
};
-char *rankchar[RANKS] = {
+const char *const rankchar[RANKS] = {
"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"
};
-char *suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"};
+const char *const suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"};
-char *suitchar[SUITS] = {"S", "H", "D", "C"};
+const char *const suitchar[SUITS] = {"S", "H", "D", "C"};
/*
* msgcard:
* Print the value of a card in ascii
*/
int
-msgcrd(c, brfrank, mid, brfsuit)
- CARD c;
- BOOLEAN brfrank, brfsuit;
- char *mid;
+msgcrd(CARD c, BOOLEAN brfrank, const char *mid, BOOLEAN brfsuit)
{
if (c.rank == EMPTY || c.suit == EMPTY)
return (FALSE);
* Print out a card.
*/
void
-printcard(win, cardno, c, blank)
- WINDOW *win;
- int cardno;
- CARD c;
- BOOLEAN blank;
+printcard(WINDOW *win, int cardno, CARD c, BOOLEAN blank)
{
prcard(win, cardno * 2, cardno, c, blank);
}
* Print out a card on the window at the specified location
*/
void
-prcard(win, y, x, c, blank)
- WINDOW *win;
- int y, x;
- CARD c;
- BOOLEAN blank;
+prcard(WINDOW *win, int y, int x, CARD c, BOOLEAN blank)
{
if (c.rank == EMPTY)
return;
* Print a hand of n cards
*/
void
-prhand(h, n, win, blank)
- CARD h[];
- int n;
- WINDOW *win;
- BOOLEAN blank;
+prhand(const CARD h[], int n, WINDOW *win, BOOLEAN blank)
{
- register int i;
+ int i;
werase(win);
for (i = 0; i < n; i++)
* input, returns the index of the card found...
*/
int
-infrom(hand, n, prompt)
- CARD hand[];
- int n;
- char *prompt;
+infrom(const CARD hand[], int n, const char *prompt)
{
- register int i, j;
+ int i, j;
CARD crd;
if (n < 1) {
for (;;) {
msg(prompt);
if (incard(&crd)) { /* if card is full card */
- if (!isone(crd, hand, n))
+ if (!is_one(crd, hand, n))
msg("That's not in your hand");
else {
for (i = 0; i < n; i++)
hand[i].suit == crd.suit)
break;
if (i >= n) {
- printf("\nINFROM: isone or something messed up\n");
+ printf("\nINFROM: is_one or something messed up\n");
exit(77);
}
return (i);
* and then parses it.
*/
int
-incard(crd)
- CARD *crd;
+incard(CARD *crd)
{
- register int i;
+ int i;
int rnk, sut;
char *line, *p, *p1;
BOOLEAN retval;
if (!(line = getline()))
goto gotit;
p = p1 = line;
- while (*p1 != ' ' && *p1 != NULL)
+ while (*p1 != ' ' && *p1 != '\0')
++p1;
- *p1++ = NULL;
- if (*p == NULL)
+ *p1++ = '\0';
+ if (*p == '\0')
goto gotit;
/* IMPORTANT: no real card has 2 char first name */
if (rnk == EMPTY)
goto gotit;
p = p1;
- while (*p1 != ' ' && *p1 != NULL)
+ while (*p1 != ' ' && *p1 != '\0')
++p1;
- *p1++ = NULL;
- if (*p == NULL)
+ *p1++ = '\0';
+ if (*p == '\0')
goto gotit;
if (!strcmp("OF", p)) {
p = p1;
- while (*p1 != ' ' && *p1 != NULL)
+ while (*p1 != ' ' && *p1 != '\0')
++p1;
- *p1++ = NULL;
- if (*p == NULL)
+ *p1++ = '\0';
+ if (*p == '\0')
goto gotit;
}
sut = EMPTY;
* Reads and converts to upper case
*/
int
-getuchar()
+getuchar(void)
{
- register int c;
+ int c;
c = readchar();
if (islower(c))
* "hi" inclusive.
*/
int
-number(lo, hi, prompt)
- int lo, hi;
- char *prompt;
+number(int lo, int hi, const char *prompt)
{
- register char *p;
- register int sum;
+ char *p;
+ int sum;
for (sum = 0;;) {
msg(prompt);
- if (!(p = getline()) || *p == NULL) {
+ if (!(p = getline()) || *p == '\0') {
msg(quiet ? "Not a number" :
"That doesn't look like a number");
continue;
}
sum = 0;
- if (!isdigit(*p))
+ if (!isdigit((unsigned char)*p))
sum = lo - 1;
else
- while (isdigit(*p)) {
+ while (isdigit((unsigned char)*p)) {
sum = 10 * sum + (*p - '0');
++p;
}
- if (*p != ' ' && *p != '\t' && *p != NULL)
+ if (*p != ' ' && *p != '\t' && *p != '\0')
sum = lo - 1;
if (sum >= lo && sum <= hi)
break;
static int Newpos = 0;
void
-#if __STDC__
msg(const char *fmt, ...)
-#else
-msg(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#if __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
(void)vsprintf(&Msgbuf[Newpos], fmt, ap);
+ Newpos = strlen(Msgbuf);
va_end(ap);
endmsg();
}
* Add things to the current message
*/
void
-#if __STDC__
addmsg(const char *fmt, ...)
-#else
-addmsg(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
{
va_list ap;
-#if __STDC__
va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
(void)vsprintf(&Msgbuf[Newpos], fmt, ap);
+ Newpos = strlen(Msgbuf);
va_end(ap);
}
int Lineno = 0;
void
-endmsg()
+endmsg(void)
{
static int lastline = 0;
- register int len;
- register char *mp, *omp;
+ int len;
+ char *mp, *omp;
/* All messages should start with uppercase */
mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
- if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
- Msgbuf[0] = toupper(Msgbuf[0]);
+ if (islower((unsigned char)Msgbuf[0]) && Msgbuf[1] != ')')
+ Msgbuf[0] = toupper((unsigned char)Msgbuf[0]);
mp = Msgbuf;
len = strlen(mp);
if (len / MSG_X + Lineno >= MSG_Y) {
* Wait for the user to type ' ' before doing anything else
*/
void
-do_wait()
+do_wait(void)
{
- static char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'};
+ static const char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'};
- if (Mpos + sizeof prompt < MSG_X)
+ if ((int)(Mpos + sizeof prompt) < MSG_X)
wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
else {
mvwaddch(Msgwin, Lineno, 0, ' ');
* Sit around until the guy types the right key
*/
void
-wait_for(ch)
- register int ch;
+wait_for(int ch)
{
- register char c;
+ int c;
if (ch == '\n')
while ((c = readchar()) != '\n')
* Reads and returns a character, checking for gross input errors
*/
int
-readchar()
+readchar(void)
{
- register int cnt;
- char c;
+ int cnt;
+ unsigned char c;
over:
cnt = 0;
- while (read(STDIN_FILENO, &c, sizeof(char)) <= 0)
+ while (read(STDIN_FILENO, &c, sizeof(unsigned char)) <= 0)
if (cnt++ > 100) { /* if we are getting infinite EOFs */
bye(); /* quit the game */
exit(1);
* compressed to one space; a space is inserted before a ','
*/
char *
-getline()
+getline(void)
{
- register char *sp;
- register int c, oy, ox;
- register WINDOW *oscr;
+ char *sp;
+ int c, oy, ox;
+ WINDOW *oscr;
oscr = stdscr;
stdscr = Msgwin;
refresh();
/* loop reading in the string, and put it in a temporary buffer */
for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
- if (c == -1)
- continue;
- else
if (c == erasechar()) { /* process erase character */
if (sp > linebuf) {
- register int i;
+ int i;
sp--;
for (i = strlen(unctrl(*sp)); i; i--)
}
void
-rint(signo)
- int signo;
+receive_intr(int signo __unused)
{
bye();
exit(1);
* Leave the program, cleaning things up as we go.
*/
void
-bye()
+bye(void)
{
signal(SIGINT, SIG_IGN);
mvcur(0, COLS - 1, LINES - 1, 0);