# define CTRL(X) ('X' - 'A' + 1)
# define erasechar() _tty.sg_erase
# define killchar() _tty.sg_kill
char linebuf
[ LINESIZE
];
char *rankname
[ RANKS
] = { "ACE", "TWO", "THREE", "FOUR",
"FIVE", "SIX", "SEVEN", "EIGHT",
"NINE", "TEN", "JACK", "QUEEN",
char *rankchar
[ RANKS
] = { "A", "2", "3", "4", "5", "6", "7",
"8", "9", "T", "J", "Q", "K" };
char *suitname
[ SUITS
] = { "SPADES", "HEARTS", "DIAMONDS",
char *suitchar
[ SUITS
] = { "S", "H", "D", "C" };
* Call msgcrd in one of two forms
return msgcrd(c
, TRUE
, (char *) NULL
, TRUE
);
return msgcrd(c
, FALSE
, " of ", FALSE
);
* Print the value of a card in ascii
msgcrd(c
, brfrank
, mid
, brfsuit
)
BOOLEAN brfrank
, brfsuit
;
if (c
.rank
== EMPTY
|| c
.suit
== EMPTY
)
addmsg("%1.1s", rankchar
[c
.rank
]);
addmsg(rankname
[c
.rank
]);
addmsg("%1.1s", suitchar
[c
.suit
]);
addmsg(suitname
[c
.suit
]);
printcard(win
, cardno
, c
)
prcard(win
, cardno
* 2, cardno
, c
, FALSE
);
* Print out a card on the window at the specified location
prcard(win
, y
, x
, c
, blank
)
mvwaddstr(win
, y
+ 0, x
, "+-----+");
mvwaddstr(win
, y
+ 1, x
, "| |");
mvwaddstr(win
, y
+ 2, x
, "| |");
mvwaddstr(win
, y
+ 3, x
, "| |");
mvwaddstr(win
, y
+ 4, x
, "+-----+");
mvwaddch(win
, y
+ 1, x
+ 1, rankchar
[c
.rank
][0]);
waddch(win
, suitchar
[c
.suit
][0]);
mvwaddch(win
, y
+ 3, x
+ 4, rankchar
[c
.rank
][0]);
waddch(win
, suitchar
[c
.suit
][0]);
* Print a hand of n cards
* reads a card, supposedly in hand, accepting unambigous brief
* input, returns the index of the card found...
printf("\nINFROM: %d = n < 1!!\n", n
);
if (incard(&crd
)) { /* if card is full card */
if (!isone(crd
, hand
, n
))
msg("That's not in your hand");
if (hand
[i
].rank
== crd
.rank
&&
hand
[i
].suit
== crd
.suit
)
printf("\nINFROM: isone or something messed up\n");
else /* if not full card... */
if (hand
[i
].rank
== crd
.rank
)
msg("No such rank in your hand");
for (j
= i
+ 1; j
< n
; j
++)
if (hand
[j
].rank
== crd
.rank
)
msg("Sorry, I missed that");
* Inputs a card in any format. It reads a line ending with a CR
while( *p1
!= ' ' && *p1
!= NULL
) ++p1
;
if( *p
== NULL
) goto gotit
;
/* IMPORTANT: no real card has 2 char first name */
if( strlen(p
) == 2 ) { /* check for short form */
for( i
= 0; i
< RANKS
; i
++ ) {
if( *p
== *rankchar
[i
] ) {
if( rnk
== EMPTY
) goto gotit
; /* it's nothing... */
++p
; /* advance to next char */
for( i
= 0; i
< SUITS
; i
++ ) {
if( *p
== *suitchar
[i
] ) {
if( sut
!= EMPTY
) retval
= TRUE
;
for( i
= 0; i
< RANKS
; i
++ ) {
if( !strcmp( p
, rankname
[i
] ) || !strcmp( p
, rankchar
[i
] ) ) {
if( rnk
== EMPTY
) goto gotit
;
while( *p1
!= ' ' && *p1
!= NULL
) ++p1
;
if( *p
== NULL
) goto gotit
;
if( !strcmp( "OF", p
) ) {
while( *p1
!= ' ' && *p1
!= NULL
) ++p1
;
if( *p
== NULL
) goto gotit
;
for( i
= 0; i
< SUITS
; i
++ ) {
if( !strcmp( p
, suitname
[i
] ) || !strcmp( p
, suitchar
[i
] ) ) {
if( sut
!= EMPTY
) retval
= TRUE
;
* Reads and converts to upper case
* Reads in a decimal number and makes sure it is between "lo" and
if(!(p
= getline()) || *p
== NULL
) {
msg(quiet
? "Not a number" : "That doesn't look like a number");
sum
= 10 * sum
+ (*p
- '0');
if (*p
!= ' ' && *p
!= '\t' && *p
!= NULL
)
if (sum
>= lo
&& sum
<= hi
)
msg("that doesn't look like a number, try again --> ");
msg("%d is not between %d and %d inclusive, try again --> ",
* Display a message at the top of the screen.
char Msgbuf
[BUFSIZ
] = "";
* if the string is "", just clear the line
* otherwise add to the message and flush it out
* Add things to the current message
* Display a new msg (giving him a chance to see the previous one
* if it is up there with the --More--)
* All messages should start with uppercase, except ones that
* start with a pack addressing character
if (islower(Msgbuf
[0]) && Msgbuf
[1] != ')')
Msgbuf
[0] = toupper(Msgbuf
[0]);
mvaddstr(LINES
- 1, 0, Msgbuf
);
* Perform an add onto the message buffer
* Do the printf into Msgbuf
junk
._flag
= _IOWRT
+ _IOSTRG
;
junk
._ptr
= &Msgbuf
[Newpos
];
_doprnt(fmt
, args
, &junk
);
* Sit around until the guy types the right key
while ((c
= readchar()) != '\n')
* Reads and returns a character, checking for gross input errors
while (read(0, &c
, 1) <= 0)
if (cnt
++ > 100) /* if we are getting infinite EOFs */
bye(); /* quit the game */
* Reads the next line up to '\n' or EOF. Multiple spaces are
* compressed to one space; a space is inserted before a ','
* loop reading in the string, and put it in a temporary buffer
for (sp
= linebuf
; (c
= readchar()) != '\n'; clrtoeol(), refresh()) {
else if (c
== erasechar()) { /* process erase character */
for (i
= strlen(unctrl(*sp
)); i
; i
--)
else if (c
== killchar()) { /* process kill character */
else if (sp
== linebuf
&& c
== ' ')
if (sp
>= &linebuf
[LINESIZE
-1] || !(isprint(c
) || c
== ' '))
/*###366 [cc] Mpos undefined %%%*/