-/* $NetBSD: io.c,v 1.11 1999/09/08 21:17:47 jsm 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.
*
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: io.c,v 1.11 1999/09/08 21:17:47 jsm 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"
* Print the value of a card in ascii
*/
int
-msgcrd(c, brfrank, mid, brfsuit)
- CARD c;
- BOOLEAN brfrank, brfsuit;
- const 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)
- const CARD h[];
- int n;
- WINDOW *win;
- BOOLEAN blank;
+prhand(const CARD h[], int n, WINDOW *win, BOOLEAN blank)
{
int i;
* input, returns the index of the card found...
*/
int
-infrom(hand, n, prompt)
- const CARD hand[];
- int n;
- const char *prompt;
+infrom(const CARD hand[], int n, const char *prompt)
{
int i, j;
CARD crd;
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)
{
int i;
int rnk, sut;
* Reads and converts to upper case
*/
int
-getuchar()
+getuchar(void)
{
int c;
* "hi" inclusive.
*/
int
-number(lo, hi, prompt)
- int lo, hi;
- const char *prompt;
+number(int lo, int hi, const char *prompt)
{
char *p;
int sum;
}
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;
}
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);
* 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;
int len;
/* 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 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)
- int ch;
+wait_for(int ch)
{
- 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)
{
int cnt;
- char c;
+ 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)
{
char *sp;
int c, oy, ox;
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) {
int 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);