This is io.c in view mode; [Download] [Up]
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#ifndef lint
static char sccsid[] = "@(#)io.c 5.3 (Berkeley) 3/10/88";
#endif /* not lint */
#define IO_C
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# include <stdarg.h>
# include "deck.h"
# include "cribbage.h"
# include "gui.h"
# include "LocalizableStrings.h"
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
static void doadd( const char *, va_list ap );
char *rankname[ RANKS ] = { "ACE", "TWO", "THREE", "FOUR",
"FIVE", "SIX", "SEVEN", "EIGHT",
"NINE", "TEN", "JACK", "QUEEN",
"KING" };
char *rankchar[ RANKS ] = { "A", "2", "3", "4", "5", "6", "7",
"8", "9", "T", "J", "Q", "K" };
char *suitname[ SUITS ] = { "SPADES", "HEARTS", "DIAMONDS",
"CLUBS" };
char *suitchar[ SUITS ] = { "S", "H", "D", "C" };
/*
* msgcard:
* Call msgcrd in one of two forms
*/
BOOLEAN msgcard( CARD c, BOOLEAN brief )
{
if (brief)
return msgcrd(c, TRUE, (char *) NULL, TRUE);
else
return msgcrd(c, FALSE, " of ", FALSE);
}
/*
* msgcrd:
* Print the value of a card in ascii
*/
BOOLEAN msgcrd( CARD c, BOOLEAN brfrank, char *mid, BOOLEAN brfsuit )
{
const char *l_rank, *l_suit, *l_mid = NULL;
if (c.rank == EMPTY || c.suit == EMPTY)
return FALSE;
if (brfrank)
l_rank = NXLocalizedString(rankchar[c.rank],NULL,-);
else
l_rank = NXLocalizedString(rankname[c.rank],NULL,-);
if (brfsuit)
l_suit = NXLocalizedString(suitchar[c.suit],NULL,-);
else
l_suit = NXLocalizedString(suitname[c.suit],NULL,-);
if (mid) {
l_mid = NXLocalizedString(mid,NULL,-);
if (l_mid[0] == '~') /* swap rank and suit */
addmsg ("%s%s%s", l_suit, l_mid+1, l_rank);
else
addmsg ("%s%s%s", l_rank, l_mid, l_suit);
} else {
addmsg ("%s%s", l_rank, l_suit);
}
return TRUE;
}
/*
* msg:
* Display a message at the top of the screen.
*/
char Msgbuf[BUFSIZ] = { '\0' };
int Mpos = 0;
static int Newpos = 0;
void msg( const char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
doadd( fmt, ap );
va_end( ap );
endmsg();
}
/*
* addmsg:
* Add things to the current message
*/
void addmsg( const char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
doadd( fmt, ap );
va_end( ap );
}
/*
* endmsg:
* Display a new msg.
*/
void endmsg()
{
/*
* All messages should start with uppercase
*/
if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
Msgbuf[0] = toupper(Msgbuf[0]);
gui_msg(Msgbuf);
Newpos = 0;
}
/*
* doadd:
* Perform an add onto the message buffer
*/
/*void doadd( char *fmt, va_list ap )*/
static void doadd( const char *fmt, va_list ap )
{
/*
* Do the printf into Msgbuf
*/
vsprintf( Msgbuf+Newpos, fmt, ap );
Newpos = strlen(Msgbuf);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.