mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
separate UI-specific code so that a non-UI linux library can be compiled, e.g. for use with a toolkit not gtk or ncurses
This commit is contained in:
parent
ebc481ddc0
commit
ad52e63ff0
9 changed files with 383 additions and 278 deletions
|
@ -45,10 +45,18 @@ ifdef GTK_ONLY
|
|||
DO_CURSES =
|
||||
PLATFORM := $(PLATFORM)_gtk
|
||||
endif
|
||||
ifdef LIB_NO_UI
|
||||
DO_CURSES =
|
||||
DO_GTK =
|
||||
endif
|
||||
|
||||
DEFINES += $(DO_CURSES) $(DO_GTK) $(SVNDEF)
|
||||
|
||||
ifdef LIB_NO_UI
|
||||
TARGET=$(PLATFORM)/libxwords.so.0
|
||||
else
|
||||
TARGET=$(PLATFORM)/xwords
|
||||
endif
|
||||
|
||||
include ../common/config.mk
|
||||
|
||||
|
@ -100,25 +108,36 @@ DEFINES += -DPERIMETER_FOCUS
|
|||
# INCLUDES += -I/usr/lib/glib/include
|
||||
INCLUDES += ${EXTRAINCS}
|
||||
|
||||
OBJ = $(PLATFORM)/linuxmain.o \
|
||||
$(PLATFORM)/linuxdict.o \
|
||||
ifdef DO_GTK
|
||||
GTK_OBJS = \
|
||||
$(PLATFORM)/gtkmain.o \
|
||||
$(PLATFORM)/gtkdraw.o \
|
||||
$(PLATFORM)/gtkask.o \
|
||||
$(PLATFORM)/gtkletterask.o \
|
||||
$(PLATFORM)/gtkpasswdask.o \
|
||||
$(PLATFORM)/gtknewgame.o \
|
||||
$(PLATFORM)/gtkntilesask.o \
|
||||
$(PLATFORM)/gtkntilesask.o
|
||||
endif
|
||||
ifdef DO_CURSES
|
||||
CURSES_OBJS = \
|
||||
$(PLATFORM)/cursesmain.o \
|
||||
$(PLATFORM)/cursesdraw.o \
|
||||
$(PLATFORM)/cursesask.o \
|
||||
$(PLATFORM)/cursesdlgutil.o \
|
||||
$(PLATFORM)/cursesletterask.o \
|
||||
$(PLATFORM)/cursesletterask.o
|
||||
endif
|
||||
ifndef LIB_NO_UI
|
||||
MAIN_OBJS = $(PLATFORM)/linuxmain.o
|
||||
endif
|
||||
|
||||
|
||||
OBJ = \
|
||||
$(PLATFORM)/filestream.o \
|
||||
$(PLATFORM)/linuxbt.o \
|
||||
$(PLATFORM)/linuxudp.o \
|
||||
|
||||
# $(PLATFORM)/linuxcommpipe.o \
|
||||
$(PLATFORM)/linuxdict.o \
|
||||
$(PLATFORM)/linuxutl.o \
|
||||
$(CURSES_OBJS) $(GTK_OBJS) $(MAIN_OBJS)
|
||||
|
||||
LIBS = -lm -lmcheck $(GPROFFLAG)
|
||||
ifdef BLUETOOTH
|
||||
|
@ -138,6 +157,8 @@ endif
|
|||
# provides an all: target
|
||||
include ../common/rules.mk
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
help:
|
||||
@echo "make [MEMDEBUG=TRUE] [CURSES_ONLY=TRUE] [GTK_ONLY=TRUE]"
|
||||
|
||||
|
@ -161,10 +182,14 @@ gprof:
|
|||
$(MAKE) GPROFFLAG=-pg MEMDEBUG=TRUE
|
||||
|
||||
|
||||
$(TARGET): $(COMMONOBJ) $(OBJ) *.h Makefile
|
||||
$(PLATFORM)/xwords: $(COMMONOBJ) $(OBJ) *.h Makefile
|
||||
mkdir -p $(PLATFORM)
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(COMMONOBJ) $(OBJ) $(LIBS) -o $@
|
||||
|
||||
$(PLATFORM)/libxwords.so.0: $(COMMONOBJ) $(OBJ) *.h Makefile
|
||||
mkdir -p $(PLATFORM)
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(COMMONOBJ) $(OBJ) -shared -o $@ -Wl,-soname,libxwords.so.0
|
||||
|
||||
$(PLATFORM)/%.o: %.c
|
||||
mkdir -p $(PLATFORM)
|
||||
$(CC) -c $(INCLUDES) $(DEFINES) -DPLATFORM=$(PLATFORM) $(CFLAGS) $< -o $@
|
||||
|
@ -175,3 +200,10 @@ clean:
|
|||
|
||||
install: $(TARGET)
|
||||
cp $< $(DESTDIR)/usr/local/bin
|
||||
|
||||
tarball:
|
||||
tar cvfz xwords_$(shell svnversion ..).tgz \
|
||||
../linux/Makefile ../linux/*.c ../linux/*.h \
|
||||
../relay/*.h \
|
||||
../common/*.c ../common/*.h ../common/rules.mk ../common/config.mk
|
||||
md5sum xwords_$(shell svnversion ..).tgz > xwords_$(shell svnversion ..).tgz.md5
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#ifdef PLATFORM_NCURSES
|
||||
|
||||
#include "linuxutl.h"
|
||||
#include "cursesletterask.h"
|
||||
#include "cursesdlgutil.h"
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <netinet/in.h>
|
||||
|
||||
#include "linuxmain.h"
|
||||
#include "linuxutl.h"
|
||||
#include "cursesmain.h"
|
||||
#include "cursesask.h"
|
||||
#include "cursesletterask.h"
|
||||
|
@ -255,7 +256,7 @@ curses_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
|
|||
{
|
||||
CursesAppGlobals* globals;
|
||||
char* question;
|
||||
char* answers[3];
|
||||
char* answers[3] = {NULL};
|
||||
short numAnswers = 0;
|
||||
XP_Bool freeMe = XP_FALSE;
|
||||
XP_Bool result;
|
||||
|
@ -968,7 +969,7 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
|
|||
|
||||
if ( nBytes != -1 ) {
|
||||
XWStreamCtxt* inboundS;
|
||||
struct sockaddr_in addr_sock;
|
||||
struct sockaddr_in addr_sock = {0};
|
||||
redraw = XP_FALSE;
|
||||
|
||||
XP_STATUSF( "linuxReceive=>%d", nBytes );
|
||||
|
@ -1398,7 +1399,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
|||
board_draw( g_globals.cGlobals.game.board );
|
||||
|
||||
while ( !g_globals.timeToExit ) {
|
||||
int ch;
|
||||
int ch = 0;
|
||||
if ( blocking_gotEvent( &g_globals, &ch ) ) {
|
||||
remapKey( &ch );
|
||||
if (
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "linuxmain.h"
|
||||
#include "linuxutl.h"
|
||||
#include "linuxbt.h"
|
||||
#include "linuxudp.h"
|
||||
/* #include "gtkmain.h" */
|
||||
|
@ -341,14 +342,11 @@ createOrLoadObjects( GtkAppGlobals* globals )
|
|||
}
|
||||
|
||||
if ( !opened ) {
|
||||
XP_U16 gameID;
|
||||
CommsAddrRec addr;
|
||||
|
||||
XP_MEMSET( &addr, 0, sizeof(addr) );
|
||||
addr.conType = params->conType;
|
||||
|
||||
gameID = (XP_U16)util_getCurSeconds( globals->cGlobals.params->util );
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
if ( addr.conType == COMMS_CONN_RELAY ) {
|
||||
XP_ASSERT( !!params->connInfo.relay.relayName );
|
||||
|
@ -362,7 +360,7 @@ createOrLoadObjects( GtkAppGlobals* globals )
|
|||
|
||||
game_makeNewGame( MEMPOOL &globals->cGlobals.game, ¶ms->gi,
|
||||
params->util, (DrawCtx*)globals->draw,
|
||||
gameID, &globals->cp, LINUX_SEND,
|
||||
params->gi.gameID, &globals->cp, LINUX_SEND,
|
||||
IF_CH(linux_reset) globals );
|
||||
|
||||
addr.conType = params->conType;
|
||||
|
@ -938,7 +936,7 @@ handle_nhint_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
|||
&redo ) ) {
|
||||
board_draw( globals->cGlobals.game.board );
|
||||
}
|
||||
} /* handle_hint_button */
|
||||
} /* handle_nhint_button */
|
||||
|
||||
static void
|
||||
handle_colors_button( GtkWidget* XP_UNUSED(widget),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "linuxutl.h"
|
||||
#include "gtknewgame.h"
|
||||
#include "strutils.h"
|
||||
#include "nwgamest.h"
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
# include <bluetooth/bluetooth.h>
|
||||
|
@ -41,6 +42,7 @@
|
|||
/* #include <pthread.h> */
|
||||
|
||||
#include "linuxmain.h"
|
||||
#include "linuxutl.h"
|
||||
#include "linuxbt.h"
|
||||
#include "linuxudp.h"
|
||||
#include "main.h"
|
||||
|
@ -61,35 +63,6 @@
|
|||
#define DEFAULT_PORT 10999
|
||||
#define DEFAULT_LISTEN_PORT 4998
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
linux_debugf( const char* format, ... )
|
||||
{
|
||||
char buf[1000];
|
||||
va_list ap;
|
||||
// time_t tim;
|
||||
struct tm* timp;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
/* pthread_t me = pthread_self(); */
|
||||
|
||||
gettimeofday( &tv, &tz );
|
||||
timp = localtime( &tv.tv_sec );
|
||||
|
||||
sprintf( buf, /* "<%p>" */ "%d:%d:%d: ", /* (void*)me, */
|
||||
timp->tm_hour, timp->tm_min, timp->tm_sec );
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
vsprintf(buf+strlen(buf), format, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
fprintf( stderr, buf );
|
||||
fprintf( stderr, "\n" );
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
catOnClose( XWStreamCtxt* stream, void* XP_UNUSED(closure) )
|
||||
{
|
||||
|
@ -136,102 +109,6 @@ strFromStream( XWStreamCtxt* stream )
|
|||
} /* strFromStream */
|
||||
|
||||
|
||||
const XP_UCHAR*
|
||||
linux_getErrString( UtilErrID id, XP_Bool* silent )
|
||||
{
|
||||
*silent = XP_FALSE;
|
||||
const char* message = NULL;
|
||||
|
||||
switch( id ) {
|
||||
case ERR_TILES_NOT_IN_LINE:
|
||||
message = "All tiles played must be in a line.";
|
||||
break;
|
||||
case ERR_NO_EMPTIES_IN_TURN:
|
||||
message = "Empty squares cannot separate tiles played.";
|
||||
break;
|
||||
|
||||
case ERR_TOO_FEW_TILES_LEFT_TO_TRADE:
|
||||
message = "Too few tiles left to trade.";
|
||||
break;
|
||||
|
||||
case ERR_TWO_TILES_FIRST_MOVE:
|
||||
message = "Must play two or more pieces on the first move.";
|
||||
break;
|
||||
case ERR_TILES_MUST_CONTACT:
|
||||
message = "New pieces must contact others already in place (or "
|
||||
"the middle square on the first move).";
|
||||
break;
|
||||
case ERR_NOT_YOUR_TURN:
|
||||
message = "You can't do that; it's not your turn!";
|
||||
break;
|
||||
case ERR_NO_PEEK_ROBOT_TILES:
|
||||
message = "No peeking at the robot's tiles!";
|
||||
break;
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
case ERR_NO_PEEK_REMOTE_TILES:
|
||||
message = "No peeking at remote players' tiles!";
|
||||
break;
|
||||
case ERR_REG_UNEXPECTED_USER:
|
||||
message = "Refused attempt to register unexpected user[s].";
|
||||
break;
|
||||
case ERR_SERVER_DICT_WINS:
|
||||
message = "Conflict between Host and Guest dictionaries; Host wins.";
|
||||
XP_WARNF( "GTK may have problems here." );
|
||||
break;
|
||||
case ERR_REG_SERVER_SANS_REMOTE:
|
||||
message = "At least one player must be marked remote for a game "
|
||||
"started as Host.";
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ERR_CANT_TRADE_MID_MOVE:
|
||||
message = "Remove played tiles before trading.";
|
||||
break;
|
||||
|
||||
case ERR_CANT_UNDO_TILEASSIGN:
|
||||
message = "Tile assignment can't be undone.";
|
||||
break;
|
||||
|
||||
/* case INFO_REMOTE_CONNECTED: */
|
||||
/* message = "Another device has joined the game"; */
|
||||
/* break; */
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_LOST_OTHER:
|
||||
*silent = XP_TRUE;
|
||||
message = "XWRELAY_ERROR_LOST_OTHER";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
|
||||
message = "The relay timed you out; other players "
|
||||
"have left or never showed up.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_YOU:
|
||||
message = "You were disconnected from relay because it didn't "
|
||||
"hear from you in too long.";
|
||||
break;
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_OTHER:
|
||||
/* *silent = XP_TRUE; */
|
||||
message = "The relay has lost contact with a device in this game.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_OLDFLAGS:
|
||||
message = "You need to upgrade your copy of Crosswords.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_SHUTDOWN:
|
||||
message = "Relay disconnected you to shut down (and probably reboot).";
|
||||
break;
|
||||
|
||||
default:
|
||||
XP_LOGF( "no code for error: %d", id );
|
||||
message = "<unrecognized error code reported>";
|
||||
}
|
||||
|
||||
return (XP_UCHAR*)message;
|
||||
} /* linux_getErrString */
|
||||
|
||||
static void
|
||||
usage( char* appName, char* msg )
|
||||
{
|
||||
|
@ -322,7 +199,7 @@ linShiftFocus( CommonGlobals* cGlobals, XP_Key key, const BoardObjectType* order
|
|||
XP_Bool handled = XP_FALSE;
|
||||
BoardObjectType nxt = OBJ_NONE;
|
||||
BoardObjectType cur;
|
||||
XP_U16 i, curIndex;
|
||||
XP_U16 i, curIndex = 0;
|
||||
|
||||
cur = board_getFocusOwner( board );
|
||||
if ( cur == OBJ_NONE ) {
|
||||
|
@ -615,128 +492,6 @@ linuxFireTimer( CommonGlobals* cGlobals, XWTimerReason why )
|
|||
(*proc)( closure, why );
|
||||
} /* fireTimer */
|
||||
|
||||
static DictionaryCtxt*
|
||||
linux_util_makeEmptyDict( XW_UtilCtxt* uctx )
|
||||
{
|
||||
XP_DEBUGF( "linux_util_makeEmptyDict called\n" );
|
||||
return linux_dictionary_make( MPPARM(uctx->mpool) NULL );
|
||||
} /* linux_util_makeEmptyDict */
|
||||
|
||||
#define EM BONUS_NONE
|
||||
#define DL BONUS_DOUBLE_LETTER
|
||||
#define DW BONUS_DOUBLE_WORD
|
||||
#define TL BONUS_TRIPLE_LETTER
|
||||
#define TW BONUS_TRIPLE_WORD
|
||||
|
||||
static XWBonusType
|
||||
linux_util_getSquareBonus( XW_UtilCtxt* XP_UNUSED(uc),
|
||||
const ModelCtxt* XP_UNUSED(model),
|
||||
XP_U16 col, XP_U16 row )
|
||||
{
|
||||
XP_U16 index;
|
||||
/* This must be static or won't compile under multilink (for Palm).
|
||||
Fix! */
|
||||
static char scrabbleBoard[8*8] = {
|
||||
TW,EM,EM,DL,EM,EM,EM,TW,
|
||||
EM,DW,EM,EM,EM,TL,EM,EM,
|
||||
|
||||
EM,EM,DW,EM,EM,EM,DL,EM,
|
||||
DL,EM,EM,DW,EM,EM,EM,DL,
|
||||
|
||||
EM,EM,EM,EM,DW,EM,EM,EM,
|
||||
EM,TL,EM,EM,EM,TL,EM,EM,
|
||||
|
||||
EM,EM,DL,EM,EM,EM,DL,EM,
|
||||
TW,EM,EM,DL,EM,EM,EM,DW,
|
||||
}; /* scrabbleBoard */
|
||||
|
||||
if ( col > 7 ) col = 14 - col;
|
||||
if ( row > 7 ) row = 14 - row;
|
||||
index = (row*8) + col;
|
||||
if ( index >= 8*8 ) {
|
||||
return (XWBonusType)EM;
|
||||
} else {
|
||||
return (XWBonusType)scrabbleBoard[index];
|
||||
}
|
||||
} /* linux_util_getSquareBonus */
|
||||
|
||||
static XP_U32
|
||||
linux_util_getCurSeconds( XW_UtilCtxt* XP_UNUSED(uc) )
|
||||
{
|
||||
return (XP_U32)time(NULL);//tv.tv_sec;
|
||||
} /* gtk_util_getCurSeconds */
|
||||
|
||||
static const XP_UCHAR*
|
||||
linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
|
||||
{
|
||||
switch( code ) {
|
||||
case STRD_REMAINING_TILES_ADD:
|
||||
return (XP_UCHAR*)"+ %d [all remaining tiles]";
|
||||
case STRD_UNUSED_TILES_SUB:
|
||||
return (XP_UCHAR*)"- %d [unused tiles]";
|
||||
case STR_COMMIT_CONFIRM:
|
||||
return (XP_UCHAR*)"Are you sure you want to commit the current move?\n";
|
||||
case STRD_TURN_SCORE:
|
||||
return (XP_UCHAR*)"Score for turn: %d\n";
|
||||
case STR_BONUS_ALL:
|
||||
return (XP_UCHAR*)"Bonus for using all tiles: 50\n";
|
||||
case STR_LOCAL_NAME:
|
||||
return (XP_UCHAR*)"%s";
|
||||
case STR_NONLOCAL_NAME:
|
||||
return (XP_UCHAR*)"%s (remote)";
|
||||
case STRD_TIME_PENALTY_SUB:
|
||||
return (XP_UCHAR*)" - %d [time]";
|
||||
/* added.... */
|
||||
case STRD_CUMULATIVE_SCORE:
|
||||
return (XP_UCHAR*)"Cumulative score: %d\n";
|
||||
case STRS_TRAY_AT_START:
|
||||
return (XP_UCHAR*)"Tray at start: %s\n";
|
||||
case STRS_MOVE_DOWN:
|
||||
return (XP_UCHAR*)"move (from %s down)\n";
|
||||
case STRS_MOVE_ACROSS:
|
||||
return (XP_UCHAR*)"move (from %s across)\n";
|
||||
case STRS_NEW_TILES:
|
||||
return (XP_UCHAR*)"New tiles: %s\n";
|
||||
case STRSS_TRADED_FOR:
|
||||
return (XP_UCHAR*)"Traded %s for %s.";
|
||||
case STR_PASS:
|
||||
return (XP_UCHAR*)"pass\n";
|
||||
case STR_PHONY_REJECTED:
|
||||
return (XP_UCHAR*)"Illegal word in move; turn lost!\n";
|
||||
|
||||
case STRD_ROBOT_TRADED:
|
||||
return (XP_UCHAR*)"%d tiles traded this turn.";
|
||||
case STR_ROBOT_MOVED:
|
||||
return (XP_UCHAR*)"The robot moved:\n";
|
||||
case STR_REMOTE_MOVED:
|
||||
return (XP_UCHAR*)"Remote player moved:\n";
|
||||
|
||||
case STR_PASSED:
|
||||
return (XP_UCHAR*)"Passed";
|
||||
case STRSD_SUMMARYSCORED:
|
||||
return (XP_UCHAR*)"%s:%d";
|
||||
case STRD_TRADED:
|
||||
return (XP_UCHAR*)"Traded %d";
|
||||
case STR_LOSTTURN:
|
||||
return (XP_UCHAR*)"Lost turn";
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
case STR_LOCALPLAYERS:
|
||||
return (XP_UCHAR*)"Local players";
|
||||
case STR_REMOTE:
|
||||
return (XP_UCHAR*)"Remote";
|
||||
#endif
|
||||
case STR_TOTALPLAYERS:
|
||||
return (XP_UCHAR*)"Total players";
|
||||
|
||||
case STRS_VALUES_HEADER:
|
||||
return (XP_UCHAR*)"%s counts/values:\n";
|
||||
|
||||
default:
|
||||
return (XP_UCHAR*)"unknown code to linux_util_getUserString";
|
||||
}
|
||||
} /* linux_util_getUserString */
|
||||
|
||||
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
|
||||
static void
|
||||
linux_util_addrChange( XW_UtilCtxt* uc,
|
||||
|
@ -1144,20 +899,13 @@ main( int argc, char** argv )
|
|||
|
||||
/* mainParams.pipe = linuxCommPipeCtxtMake( isServer ); */
|
||||
|
||||
mainParams.util->vtable = malloc( sizeof(UtilVtable) );
|
||||
/* mainParams.util->vtable->m_util_makeStreamFromAddr = */
|
||||
/* linux_util_makeStreamFromAddr; */
|
||||
|
||||
mainParams.util->gameInfo = &mainParams.gi;
|
||||
|
||||
mainParams.util->vtable->m_util_makeEmptyDict =
|
||||
linux_util_makeEmptyDict;
|
||||
mainParams.util->vtable->m_util_getSquareBonus =
|
||||
linux_util_getSquareBonus;
|
||||
mainParams.util->vtable->m_util_getCurSeconds =
|
||||
linux_util_getCurSeconds;
|
||||
mainParams.util->vtable->m_util_getUserString =
|
||||
linux_util_getUserString;
|
||||
linux_util_vt_init( MPPARM(mainParams.util->mpool) mainParams.util );
|
||||
|
||||
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
||||
mainParams.util->vtable->m_util_addrChange = linux_util_addrChange;
|
||||
#endif
|
||||
|
|
|
@ -34,8 +34,6 @@ typedef struct LinuxBMStruct {
|
|||
XP_U8 nBytes;
|
||||
} LinuxBMStruct;
|
||||
|
||||
DictionaryCtxt* linux_dictionary_make( MPFORMAL const char* dictFileName );
|
||||
|
||||
int initListenerSocket( int port );
|
||||
XP_S16 linux_send( const XP_U8* buf, XP_U16 buflen,
|
||||
const CommsAddrRec* addrRec, void* closure );
|
||||
|
@ -56,7 +54,6 @@ void linuxFireTimer( CommonGlobals* cGlobals, XWTimerReason why );
|
|||
|
||||
XWStreamCtxt* stream_from_msgbuf( CommonGlobals* cGlobals,
|
||||
unsigned char* bufPtr, XP_U16 nBytes );
|
||||
const XP_UCHAR* linux_getErrString( UtilErrID id, XP_Bool* silent );
|
||||
XP_UCHAR* strFromStream( XWStreamCtxt* stream );
|
||||
|
||||
void catGameHistory( CommonGlobals* cGlobals );
|
||||
|
|
287
xwords4/linux/linuxutl.c
Normal file
287
xwords4/linux/linuxutl.c
Normal file
|
@ -0,0 +1,287 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
||||
/*
|
||||
* Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "linuxutl.h"
|
||||
#include "LocalizedStrIncludes.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
linux_debugf( const char* format, ... )
|
||||
{
|
||||
char buf[1000];
|
||||
va_list ap;
|
||||
// time_t tim;
|
||||
struct tm* timp;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
/* pthread_t me = pthread_self(); */
|
||||
|
||||
gettimeofday( &tv, &tz );
|
||||
timp = localtime( &tv.tv_sec );
|
||||
|
||||
sprintf( buf, /* "<%p>" */ "%d:%d:%d: ", /* (void*)me, */
|
||||
timp->tm_hour, timp->tm_min, timp->tm_sec );
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
vsprintf(buf+strlen(buf), format, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
fprintf( stderr, buf );
|
||||
fprintf( stderr, "\n" );
|
||||
}
|
||||
#endif
|
||||
|
||||
static DictionaryCtxt*
|
||||
linux_util_makeEmptyDict( XW_UtilCtxt* uctx )
|
||||
{
|
||||
XP_DEBUGF( "linux_util_makeEmptyDict called\n" );
|
||||
return linux_dictionary_make( MPPARM(uctx->mpool) NULL );
|
||||
} /* linux_util_makeEmptyDict */
|
||||
|
||||
#define EM BONUS_NONE
|
||||
#define DL BONUS_DOUBLE_LETTER
|
||||
#define DW BONUS_DOUBLE_WORD
|
||||
#define TL BONUS_TRIPLE_LETTER
|
||||
#define TW BONUS_TRIPLE_WORD
|
||||
|
||||
static XWBonusType
|
||||
linux_util_getSquareBonus( XW_UtilCtxt* XP_UNUSED(uc),
|
||||
const ModelCtxt* XP_UNUSED(model),
|
||||
XP_U16 col, XP_U16 row )
|
||||
{
|
||||
XP_U16 index;
|
||||
/* This must be static or won't compile under multilink (for Palm).
|
||||
Fix! */
|
||||
static char scrabbleBoard[8*8] = {
|
||||
TW,EM,EM,DL,EM,EM,EM,TW,
|
||||
EM,DW,EM,EM,EM,TL,EM,EM,
|
||||
|
||||
EM,EM,DW,EM,EM,EM,DL,EM,
|
||||
DL,EM,EM,DW,EM,EM,EM,DL,
|
||||
|
||||
EM,EM,EM,EM,DW,EM,EM,EM,
|
||||
EM,TL,EM,EM,EM,TL,EM,EM,
|
||||
|
||||
EM,EM,DL,EM,EM,EM,DL,EM,
|
||||
TW,EM,EM,DL,EM,EM,EM,DW,
|
||||
}; /* scrabbleBoard */
|
||||
|
||||
if ( col > 7 ) col = 14 - col;
|
||||
if ( row > 7 ) row = 14 - row;
|
||||
index = (row*8) + col;
|
||||
if ( index >= 8*8 ) {
|
||||
return (XWBonusType)EM;
|
||||
} else {
|
||||
return (XWBonusType)scrabbleBoard[index];
|
||||
}
|
||||
} /* linux_util_getSquareBonus */
|
||||
|
||||
static XP_U32
|
||||
linux_util_getCurSeconds( XW_UtilCtxt* XP_UNUSED(uc) )
|
||||
{
|
||||
return (XP_U32)time(NULL);//tv.tv_sec;
|
||||
} /* gtk_util_getCurSeconds */
|
||||
|
||||
static const XP_UCHAR*
|
||||
linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
|
||||
{
|
||||
switch( code ) {
|
||||
case STRD_REMAINING_TILES_ADD:
|
||||
return (XP_UCHAR*)"+ %d [all remaining tiles]";
|
||||
case STRD_UNUSED_TILES_SUB:
|
||||
return (XP_UCHAR*)"- %d [unused tiles]";
|
||||
case STR_COMMIT_CONFIRM:
|
||||
return (XP_UCHAR*)"Are you sure you want to commit the current move?\n";
|
||||
case STRD_TURN_SCORE:
|
||||
return (XP_UCHAR*)"Score for turn: %d\n";
|
||||
case STR_BONUS_ALL:
|
||||
return (XP_UCHAR*)"Bonus for using all tiles: 50\n";
|
||||
case STR_LOCAL_NAME:
|
||||
return (XP_UCHAR*)"%s";
|
||||
case STR_NONLOCAL_NAME:
|
||||
return (XP_UCHAR*)"%s (remote)";
|
||||
case STRD_TIME_PENALTY_SUB:
|
||||
return (XP_UCHAR*)" - %d [time]";
|
||||
/* added.... */
|
||||
case STRD_CUMULATIVE_SCORE:
|
||||
return (XP_UCHAR*)"Cumulative score: %d\n";
|
||||
case STRS_TRAY_AT_START:
|
||||
return (XP_UCHAR*)"Tray at start: %s\n";
|
||||
case STRS_MOVE_DOWN:
|
||||
return (XP_UCHAR*)"move (from %s down)\n";
|
||||
case STRS_MOVE_ACROSS:
|
||||
return (XP_UCHAR*)"move (from %s across)\n";
|
||||
case STRS_NEW_TILES:
|
||||
return (XP_UCHAR*)"New tiles: %s\n";
|
||||
case STRSS_TRADED_FOR:
|
||||
return (XP_UCHAR*)"Traded %s for %s.";
|
||||
case STR_PASS:
|
||||
return (XP_UCHAR*)"pass\n";
|
||||
case STR_PHONY_REJECTED:
|
||||
return (XP_UCHAR*)"Illegal word in move; turn lost!\n";
|
||||
|
||||
case STRD_ROBOT_TRADED:
|
||||
return (XP_UCHAR*)"%d tiles traded this turn.";
|
||||
case STR_ROBOT_MOVED:
|
||||
return (XP_UCHAR*)"The robot moved:\n";
|
||||
case STR_REMOTE_MOVED:
|
||||
return (XP_UCHAR*)"Remote player moved:\n";
|
||||
|
||||
case STR_PASSED:
|
||||
return (XP_UCHAR*)"Passed";
|
||||
case STRSD_SUMMARYSCORED:
|
||||
return (XP_UCHAR*)"%s:%d";
|
||||
case STRD_TRADED:
|
||||
return (XP_UCHAR*)"Traded %d";
|
||||
case STR_LOSTTURN:
|
||||
return (XP_UCHAR*)"Lost turn";
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
case STR_LOCALPLAYERS:
|
||||
return (XP_UCHAR*)"Local players";
|
||||
case STR_REMOTE:
|
||||
return (XP_UCHAR*)"Remote";
|
||||
#endif
|
||||
case STR_TOTALPLAYERS:
|
||||
return (XP_UCHAR*)"Total players";
|
||||
|
||||
case STRS_VALUES_HEADER:
|
||||
return (XP_UCHAR*)"%s counts/values:\n";
|
||||
|
||||
default:
|
||||
return (XP_UCHAR*)"unknown code to linux_util_getUserString";
|
||||
}
|
||||
} /* linux_util_getUserString */
|
||||
|
||||
void
|
||||
linux_util_vt_init( MPFORMAL XW_UtilCtxt* util )
|
||||
{
|
||||
util->vtable = XP_MALLOC( mpool, sizeof(UtilVtable) );
|
||||
|
||||
util->vtable->m_util_makeEmptyDict = linux_util_makeEmptyDict;
|
||||
util->vtable->m_util_getSquareBonus = linux_util_getSquareBonus;
|
||||
util->vtable->m_util_getCurSeconds = linux_util_getCurSeconds;
|
||||
util->vtable->m_util_getUserString = linux_util_getUserString;
|
||||
|
||||
}
|
||||
|
||||
const XP_UCHAR*
|
||||
linux_getErrString( UtilErrID id, XP_Bool* silent )
|
||||
{
|
||||
*silent = XP_FALSE;
|
||||
const char* message = NULL;
|
||||
|
||||
switch( id ) {
|
||||
case ERR_TILES_NOT_IN_LINE:
|
||||
message = "All tiles played must be in a line.";
|
||||
break;
|
||||
case ERR_NO_EMPTIES_IN_TURN:
|
||||
message = "Empty squares cannot separate tiles played.";
|
||||
break;
|
||||
|
||||
case ERR_TOO_FEW_TILES_LEFT_TO_TRADE:
|
||||
message = "Too few tiles left to trade.";
|
||||
break;
|
||||
|
||||
case ERR_TWO_TILES_FIRST_MOVE:
|
||||
message = "Must play two or more pieces on the first move.";
|
||||
break;
|
||||
case ERR_TILES_MUST_CONTACT:
|
||||
message = "New pieces must contact others already in place (or "
|
||||
"the middle square on the first move).";
|
||||
break;
|
||||
case ERR_NOT_YOUR_TURN:
|
||||
message = "You can't do that; it's not your turn!";
|
||||
break;
|
||||
case ERR_NO_PEEK_ROBOT_TILES:
|
||||
message = "No peeking at the robot's tiles!";
|
||||
break;
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
case ERR_NO_PEEK_REMOTE_TILES:
|
||||
message = "No peeking at remote players' tiles!";
|
||||
break;
|
||||
case ERR_REG_UNEXPECTED_USER:
|
||||
message = "Refused attempt to register unexpected user[s].";
|
||||
break;
|
||||
case ERR_SERVER_DICT_WINS:
|
||||
message = "Conflict between Host and Guest dictionaries; Host wins.";
|
||||
XP_WARNF( "GTK may have problems here." );
|
||||
break;
|
||||
case ERR_REG_SERVER_SANS_REMOTE:
|
||||
message = "At least one player must be marked remote for a game "
|
||||
"started as Host.";
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ERR_CANT_TRADE_MID_MOVE:
|
||||
message = "Remove played tiles before trading.";
|
||||
break;
|
||||
|
||||
case ERR_CANT_UNDO_TILEASSIGN:
|
||||
message = "Tile assignment can't be undone.";
|
||||
break;
|
||||
|
||||
/* case INFO_REMOTE_CONNECTED: */
|
||||
/* message = "Another device has joined the game"; */
|
||||
/* break; */
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_LOST_OTHER:
|
||||
*silent = XP_TRUE;
|
||||
message = "XWRELAY_ERROR_LOST_OTHER";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
|
||||
message = "The relay timed you out; other players "
|
||||
"have left or never showed up.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_YOU:
|
||||
message = "You were disconnected from relay because it didn't "
|
||||
"hear from you in too long.";
|
||||
break;
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_OTHER:
|
||||
/* *silent = XP_TRUE; */
|
||||
message = "The relay has lost contact with a device in this game.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_OLDFLAGS:
|
||||
message = "You need to upgrade your copy of Crosswords.";
|
||||
break;
|
||||
|
||||
case ERR_RELAY_BASE + XWRELAY_ERROR_SHUTDOWN:
|
||||
message = "Relay disconnected you to shut down (and probably reboot).";
|
||||
break;
|
||||
|
||||
default:
|
||||
XP_LOGF( "no code for error: %d", id );
|
||||
message = "<unrecognized error code reported>";
|
||||
}
|
||||
|
||||
return (XP_UCHAR*)message;
|
||||
} /* linux_getErrString */
|
40
xwords4/linux/linuxutl.h
Normal file
40
xwords4/linux/linuxutl.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
||||
/*
|
||||
* Copyright 2000-2008 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _LINUXUTL_H_
|
||||
#define _LINUXUTL_H_
|
||||
|
||||
#include "xptypes.h"
|
||||
#include "dictnry.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
void linux_debugf(const char*, ...)
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
#endif
|
||||
|
||||
DictionaryCtxt* linux_dictionary_make( MPFORMAL const char* dictFileName );
|
||||
|
||||
void linux_util_vt_init( MPFORMAL XW_UtilCtxt* util );
|
||||
|
||||
const XP_UCHAR* linux_getErrString( UtilErrID id, XP_Bool* silent );
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue