-/* $NetBSD: io.c,v 1.23 2009/07/13 19:05:40 roy Exp $ */
+/* $NetBSD: io.c,v 1.27 2012/10/13 20:36:06 dholland Exp $ */
/*-
* Copyright (c) 1980, 1993
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: io.c,v 1.23 2009/07/13 19:05:40 roy Exp $");
+__RCSID("$NetBSD: io.c,v 1.27 2012/10/13 20:36:06 dholland Exp $");
#endif
#endif /* not lint */
#endif
#define CTRL(X) (X - 'A' + 1)
-char linebuf[LINESIZE];
+static int msgcrd(CARD, BOOLEAN, const char *, BOOLEAN);
+static void printcard(WINDOW *, unsigned, CARD, BOOLEAN);
+static int incard(CARD *);
+static void wait_for(int);
+static int readchar(void);
-const char *const rankname[RANKS] = {
+static char linebuf[LINESIZE];
+
+static const char *const rankname[RANKS] = {
"ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
"EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"
};
-const char *const rankchar[RANKS] = {
+static const char *const rankchar[RANKS] = {
"A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"
};
-const char *const suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"};
+static const char *const suitname[SUITS] = {
+ "SPADES", "HEARTS", "DIAMONDS", "CLUBS"
+};
-const char *const suitchar[SUITS] = {"S", "H", "D", "C"};
+static const char *const suitchar[SUITS] = {"S", "H", "D", "C"};
/*
* msgcard:
* Call msgcrd in one of two forms
*/
int
-msgcard(c, brief)
- CARD c;
- BOOLEAN brief;
+msgcard(CARD c, BOOLEAN brief)
{
if (brief)
return (msgcrd(c, TRUE, NULL, TRUE));
* msgcrd:
* Print the value of a card in ascii
*/
-int
+static int
msgcrd(CARD c, BOOLEAN brfrank, const char *mid, BOOLEAN brfsuit)
{
if (c.rank == EMPTY || c.suit == EMPTY)
if (brfrank)
addmsg("%1.1s", rankchar[c.rank]);
else
- addmsg(rankname[c.rank]);
+ addmsg("%s", rankname[c.rank]);
if (mid != NULL)
- addmsg(mid);
+ addmsg("%s", mid);
if (brfsuit)
addmsg("%1.1s", suitchar[c.suit]);
else
- addmsg(suitname[c.suit]);
+ addmsg("%s", suitname[c.suit]);
return (TRUE);
}
* printcard:
* Print out a card.
*/
-void
-printcard(WINDOW *win, int cardno, CARD c, BOOLEAN blank)
+static void
+printcard(WINDOW *win, unsigned cardno, CARD c, BOOLEAN blank)
{
prcard(win, cardno * 2, cardno, c, blank);
}
* Print a hand of n cards
*/
void
-prhand(const CARD h[], int n, WINDOW *win, BOOLEAN blank)
+prhand(const CARD h[], unsigned n, WINDOW *win, BOOLEAN blank)
{
- int i;
+ unsigned i;
werase(win);
for (i = 0; i < n; i++)
exit(74);
}
for (;;) {
- msg(prompt);
+ msg("%s", prompt);
if (incard(&crd)) { /* if card is full card */
if (!is_one(crd, hand, n))
msg("That's not in your hand");
* Inputs a card in any format. It reads a line ending with a CR
* and then parses it.
*/
-int
+static int
incard(CARD *crd)
{
int i;
int sum;
for (sum = 0;;) {
- msg(prompt);
+ msg("%s", prompt);
if (!(p = get_line()) || *p == '\0') {
msg(quiet ? "Not a number" :
"That doesn't look like a number");
* msg:
* Display a message at the top of the screen.
*/
-char Msgbuf[BUFSIZ] = {'\0'};
-int Mpos = 0;
+static char Msgbuf[BUFSIZ] = {'\0'};
+static int Mpos = 0;
static int Newpos = 0;
void
* endmsg:
* Display a new msg.
*/
-int Lineno = 0;
+static int Lineno = 0;
void
endmsg(void)
* wait_for
* Sit around until the guy types the right key
*/
-void
+static void
wait_for(int ch)
{
int c;
* readchar:
* Reads and returns a character, checking for gross input errors
*/
-int
+static int
readchar(void)
{
int cnt;
char *
get_line(void)
{
- char *sp;
+ size_t pos;
int c, oy, ox;
WINDOW *oscr;
getyx(stdscr, oy, ox);
refresh();
/* loop reading in the string, and put it in a temporary buffer */
- for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
+ for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
if (c == erasechar()) { /* process erase character */
- if (sp > linebuf) {
+ if (pos > 0) {
int i;
- sp--;
- for (i = strlen(unctrl(*sp)); i; i--)
+ pos--;
+ for (i = strlen(unctrl(linebuf[pos])); i; i--)
addch('\b');
}
continue;
} else
if (c == killchar()) { /* process kill
* character */
- sp = linebuf;
+ pos = 0;
move(oy, ox);
continue;
} else
- if (sp == linebuf && c == ' ')
+ if (pos == 0 && c == ' ')
continue;
- if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' '))
+ if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' '))
putchar(CTRL('G'));
else {
if (islower(c))
c = toupper(c);
- *sp++ = c;
+ linebuf[pos++] = c;
addstr(unctrl(c));
Mpos++;
}
}
- *sp = '\0';
+ linebuf[pos] = '\0';
stdscr = oscr;
return (linebuf);
}