add option to dump an .xwd file, meant to replace dawg2dict.pl which

is becoming a pain to maintain.
This commit is contained in:
Eric House 2013-04-09 21:05:35 -07:00 committed by Eric House
parent 07cfdad699
commit 195e6bfad3
2 changed files with 208 additions and 167 deletions

View file

@ -257,6 +257,9 @@ debcheck:
all: debcheck $(TARGET) all: debcheck $(TARGET)
dawg2dict: $(TARGET)
ln -sf $< $@
help: help:
@echo "make [MEMDEBUG=TRUE] [CURSES_ONLY=TRUE] [GTK_ONLY=TRUE]" @echo "make [MEMDEBUG=TRUE] [CURSES_ONLY=TRUE] [GTK_ONLY=TRUE]"

View file

@ -1423,6 +1423,20 @@ walk_dict_test_all( const LaunchParams* params, GSList* testDicts,
} }
#endif #endif
static void
dumpDict( DictionaryCtxt* dict )
{
DictIter iter;
dict_initIter( &iter, dict, 0, MAX_COLS_DICT );
for ( XP_Bool result = dict_firstWord( &iter );
result;
result = dict_getNextWord( &iter ) ) {
XP_UCHAR buf[32];
dict_wordToString( &iter, buf, VSIZE(buf) );
fprintf( stdout, "%s\n", buf );
}
}
static void static void
trimDictPath( const char* input, char* buf, int bufsiz, char** path, char** dict ) trimDictPath( const char* input, char* buf, int bufsiz, char** path, char** dict )
{ {
@ -1506,6 +1520,23 @@ listDicts( const LaunchParams *params )
return result; return result;
} }
static int
dawg2dict( const LaunchParams* params, GSList* testDicts )
{
guint count = g_slist_length( testDicts );
for ( int ii = 0; ii < count; ++ii ) {
DictionaryCtxt* dict =
linux_dictionary_make( MPPARM(params->util->mpool) params,
g_slist_nth_data( testDicts, ii ),
params->useMmap );
if ( NULL != dict ) {
dumpDict( dict );
dict_destroy( dict );
}
}
return 0;
}
int int
main( int argc, char** argv ) main( int argc, char** argv )
{ {
@ -1925,211 +1956,218 @@ main( int argc, char** argv )
} }
} }
XP_ASSERT( mainParams.gi.nPlayers == mainParams.nLocalPlayers int result;
+ mainParams.info.serverInfo.nRemotePlayers ); if ( g_str_has_suffix( argv[0], "dawg2dict" ) ) {
result = dawg2dict( &mainParams, testDicts );
if ( isServer ) {
if ( mainParams.info.serverInfo.nRemotePlayers == 0 ) {
mainParams.gi.serverRole = SERVER_STANDALONE;
} else {
mainParams.gi.serverRole = SERVER_ISSERVER;
}
} else { } else {
mainParams.gi.serverRole = SERVER_ISCLIENT; XP_ASSERT( mainParams.gi.nPlayers == mainParams.nLocalPlayers
} + mainParams.info.serverInfo.nRemotePlayers );
/* sanity checks */ if ( isServer ) {
totalPlayerCount = mainParams.nLocalPlayers if ( mainParams.info.serverInfo.nRemotePlayers == 0 ) {
+ mainParams.info.serverInfo.nRemotePlayers; mainParams.gi.serverRole = SERVER_STANDALONE;
if ( !mainParams.fileName } else {
mainParams.gi.serverRole = SERVER_ISSERVER;
}
} else {
mainParams.gi.serverRole = SERVER_ISCLIENT;
}
/* sanity checks */
totalPlayerCount = mainParams.nLocalPlayers
+ mainParams.info.serverInfo.nRemotePlayers;
if ( !mainParams.fileName
#ifdef USE_SQLITE #ifdef USE_SQLITE
&& !mainParams.dbFileName && !mainParams.dbFileName
#endif #endif
) { ) {
if ( (totalPlayerCount < 1) || if ( (totalPlayerCount < 1) ||
(totalPlayerCount > MAX_NUM_PLAYERS) ) { (totalPlayerCount > MAX_NUM_PLAYERS) ) {
mainParams.needsNewGame = XP_TRUE; mainParams.needsNewGame = XP_TRUE;
}
}
if ( !!mainParams.gi.dictName ) {
/* char path[256]; */
/* getDictPath( &mainParams, mainParams.gi.dictName, path, VSIZE(path) ); */
mainParams.dict =
linux_dictionary_make( MPPARM(mainParams.util->mpool) &mainParams,
mainParams.gi.dictName,
mainParams.useMmap );
XP_ASSERT( !!mainParams.dict );
mainParams.gi.dictLang = dict_getLangCode( mainParams.dict );
} else if ( isServer ) {
#ifdef STUBBED_DICT
mainParams.dict = make_stubbed_dict(
MPPARM_NOCOMMA(mainParams.util->mpool) );
XP_WARNF( "no dictionary provided: using English stub dict\n" );
mainParams.gi.dictLang = dict_getLangCode( mainParams.dict );
#else
if ( 0 == nPlayerDicts ) {
mainParams.needsNewGame = XP_TRUE;
}
#endif
} else if ( robotCount > 0 ) {
mainParams.needsNewGame = XP_TRUE;
}
if ( 0 < mainParams.info.serverInfo.nRemotePlayers
&& SERVER_STANDALONE == mainParams.gi.serverRole ) {
mainParams.needsNewGame = XP_TRUE;
}
/* per-player dicts are for local players only. Assign in the order
given. It's an error to give too many, or not to give enough if
there's no game-dict */
if ( 0 < nPlayerDicts ) {
XP_U16 nextDict = 0;
for ( ii = 0; ii < mainParams.gi.nPlayers; ++ii ) {
if ( mainParams.gi.players[ii].isLocal ) {
const XP_UCHAR* name = mainParams.playerDictNames[nextDict++];
XP_ASSERT( !!name );
mainParams.dicts.dicts[ii] =
linux_dictionary_make( MPPARM(mainParams.util->mpool)
&mainParams, name, mainParams.useMmap );
} }
} }
if ( nextDict < nPlayerDicts ) {
usage( argv[0], " --player-dict used more times than there are "
"local players" );
}
}
/* if ( !isServer ) { */ if ( !!mainParams.gi.dictName ) {
/* if ( mainParams.info.serverInfo.nRemotePlayers > 0 ) { */ /* char path[256]; */
/* mainParams.needsNewGame = XP_TRUE; */ /* getDictPath( &mainParams, mainParams.gi.dictName, path, VSIZE(path) ); */
/* } */ mainParams.dict =
/* } */ linux_dictionary_make( MPPARM(mainParams.util->mpool) &mainParams,
#ifdef XWFEATURE_WALKDICT mainParams.gi.dictName,
if ( !!testDicts ) { mainParams.useMmap );
walk_dict_test_all( &mainParams, testDicts, testPrefixes, testMinMax ); XP_ASSERT( !!mainParams.dict );
exit( 0 ); mainParams.gi.dictLang = dict_getLangCode( mainParams.dict );
} } else if ( isServer ) {
#ifdef STUBBED_DICT
mainParams.dict = make_stubbed_dict(
MPPARM_NOCOMMA(mainParams.util->mpool) );
XP_WARNF( "no dictionary provided: using English stub dict\n" );
mainParams.gi.dictLang = dict_getLangCode( mainParams.dict );
#else
if ( 0 == nPlayerDicts ) {
mainParams.needsNewGame = XP_TRUE;
}
#endif #endif
if ( 0 ) { } else if ( robotCount > 0 ) {
#ifdef XWFEATURE_RELAY mainParams.needsNewGame = XP_TRUE;
} else if ( conType == COMMS_CONN_RELAY ) {
mainParams.connInfo.relay.relayName = hostName;
if ( NULL == portNum ) {
portNum = "10997";
} }
mainParams.connInfo.relay.defaultSendPort = atoi( portNum );
if ( 0 < mainParams.info.serverInfo.nRemotePlayers
&& SERVER_STANDALONE == mainParams.gi.serverRole ) {
mainParams.needsNewGame = XP_TRUE;
}
/* per-player dicts are for local players only. Assign in the order
given. It's an error to give too many, or not to give enough if
there's no game-dict */
if ( 0 < nPlayerDicts ) {
XP_U16 nextDict = 0;
for ( ii = 0; ii < mainParams.gi.nPlayers; ++ii ) {
if ( mainParams.gi.players[ii].isLocal ) {
const XP_UCHAR* name = mainParams.playerDictNames[nextDict++];
XP_ASSERT( !!name );
mainParams.dicts.dicts[ii] =
linux_dictionary_make( MPPARM(mainParams.util->mpool)
&mainParams, name, mainParams.useMmap );
}
}
if ( nextDict < nPlayerDicts ) {
usage( argv[0], " --player-dict used more times than there are "
"local players" );
}
}
/* if ( !isServer ) { */
/* if ( mainParams.info.serverInfo.nRemotePlayers > 0 ) { */
/* mainParams.needsNewGame = XP_TRUE; */
/* } */
/* } */
#ifdef XWFEATURE_WALKDICT
if ( !!testDicts ) {
walk_dict_test_all( &mainParams, testDicts, testPrefixes, testMinMax );
exit( 0 );
}
#endif
if ( 0 ) {
#ifdef XWFEATURE_RELAY
} else if ( conType == COMMS_CONN_RELAY ) {
mainParams.connInfo.relay.relayName = hostName;
if ( NULL == portNum ) {
portNum = "10997";
}
mainParams.connInfo.relay.defaultSendPort = atoi( portNum );
#endif #endif
#ifdef XWFEATURE_IP_DIRECT #ifdef XWFEATURE_IP_DIRECT
} else if ( conType == COMMS_CONN_IP_DIRECT ) { } else if ( conType == COMMS_CONN_IP_DIRECT ) {
mainParams.connInfo.ip.hostName = hostName; mainParams.connInfo.ip.hostName = hostName;
if ( NULL == portNum ) { if ( NULL == portNum ) {
portNum = "10999"; portNum = "10999";
} }
mainParams.connInfo.ip.port = atoi( portNum ); mainParams.connInfo.ip.port = atoi( portNum );
#endif #endif
#ifdef XWFEATURE_SMS #ifdef XWFEATURE_SMS
} else if ( conType == COMMS_CONN_SMS ) { } else if ( conType == COMMS_CONN_SMS ) {
mainParams.connInfo.sms.serverPhone = serverPhone; mainParams.connInfo.sms.serverPhone = serverPhone;
if ( !portNum ) { if ( !portNum ) {
portNum = "1"; portNum = "1";
} }
mainParams.connInfo.sms.port = atoi(portNum); mainParams.connInfo.sms.port = atoi(portNum);
#endif #endif
#ifdef XWFEATURE_BLUETOOTH #ifdef XWFEATURE_BLUETOOTH
} else if ( conType == COMMS_CONN_BT ) { } else if ( conType == COMMS_CONN_BT ) {
bdaddr_t ba; bdaddr_t ba;
XP_Bool success; XP_Bool success;
XP_ASSERT( btaddr ); XP_ASSERT( btaddr );
if ( isServer ) { if ( isServer ) {
success = XP_TRUE;
/* any format is ok */
} else if ( btaddr[1] == ':' ) {
success = XP_FALSE;
if ( btaddr[0] == 'n' ) {
if ( !nameToBtAddr( btaddr+2, &ba ) ) {
fprintf( stderr, "fatal error: unable to find device %s\n",
btaddr + 2 );
exit(0);
}
success = XP_TRUE; success = XP_TRUE;
} else if ( btaddr[0] == 'a' ) { /* any format is ok */
success = 0 == str2ba( &btaddr[2], &ba ); } else if ( btaddr[1] == ':' ) {
XP_ASSERT( success ); success = XP_FALSE;
if ( btaddr[0] == 'n' ) {
if ( !nameToBtAddr( btaddr+2, &ba ) ) {
fprintf( stderr, "fatal error: unable to find device %s\n",
btaddr + 2 );
exit(0);
}
success = XP_TRUE;
} else if ( btaddr[0] == 'a' ) {
success = 0 == str2ba( &btaddr[2], &ba );
XP_ASSERT( success );
}
} }
} if ( !success ) {
if ( !success ) { usage( argv[0], "bad format for -B param" );
usage( argv[0], "bad format for -B param" ); }
} XP_MEMCPY( &mainParams.connInfo.bt.hostAddr, &ba,
XP_MEMCPY( &mainParams.connInfo.bt.hostAddr, &ba, sizeof(mainParams.connInfo.bt.hostAddr) );
sizeof(mainParams.connInfo.bt.hostAddr) );
#endif #endif
} }
mainParams.conType = conType; mainParams.conType = conType;
/* mainParams.pipe = linuxCommPipeCtxtMake( isServer ); */ /* mainParams.pipe = linuxCommPipeCtxtMake( isServer ); */
/* mainParams.util->vtable->m_util_makeStreamFromAddr = */ /* mainParams.util->vtable->m_util_makeStreamFromAddr = */
/* linux_util_makeStreamFromAddr; */ /* linux_util_makeStreamFromAddr; */
mainParams.util->gameInfo = &mainParams.gi; mainParams.util->gameInfo = &mainParams.gi;
linux_util_vt_init( MPPARM(mainParams.util->mpool) mainParams.util ); linux_util_vt_init( MPPARM(mainParams.util->mpool) mainParams.util );
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
mainParams.util->vtable->m_util_informMissing = linux_util_informMissing; mainParams.util->vtable->m_util_informMissing = linux_util_informMissing;
mainParams.util->vtable->m_util_addrChange = linux_util_addrChange; mainParams.util->vtable->m_util_addrChange = linux_util_addrChange;
mainParams.util->vtable->m_util_setIsServer = linux_util_setIsServer; mainParams.util->vtable->m_util_setIsServer = linux_util_setIsServer;
#endif #endif
srandom( seed ); /* init linux random number generator */ srandom( seed ); /* init linux random number generator */
XP_LOGF( "seeded srandom with %d", seed ); XP_LOGF( "seeded srandom with %d", seed );
if ( closeStdin ) { if ( closeStdin ) {
fclose( stdin ); fclose( stdin );
if ( mainParams.quitAfter < 0 ) { if ( mainParams.quitAfter < 0 ) {
fprintf( stderr, "stdin closed; you'll need some way to quit\n" ); fprintf( stderr, "stdin closed; you'll need some way to quit\n" );
}
} }
}
if ( isServer ) { if ( isServer ) {
if ( mainParams.info.serverInfo.nRemotePlayers == 0 ) { if ( mainParams.info.serverInfo.nRemotePlayers == 0 ) {
mainParams.serverRole = SERVER_STANDALONE; mainParams.serverRole = SERVER_STANDALONE;
} else {
mainParams.serverRole = SERVER_ISSERVER;
}
} else { } else {
mainParams.serverRole = SERVER_ISSERVER; mainParams.serverRole = SERVER_ISCLIENT;
} }
} else {
mainParams.serverRole = SERVER_ISCLIENT;
}
if ( mainParams.needsNewGame ) { if ( mainParams.needsNewGame ) {
gi_initPlayerInfo( MPPARM(mainParams.util->mpool) gi_initPlayerInfo( MPPARM(mainParams.util->mpool)
&mainParams.gi, NULL ); &mainParams.gi, NULL );
} }
/* curses doesn't have newgame dialog */ /* curses doesn't have newgame dialog */
if ( useCurses && !mainParams.needsNewGame ) { if ( useCurses && !mainParams.needsNewGame ) {
#if defined PLATFORM_NCURSES #if defined PLATFORM_NCURSES
cursesmain( isServer, &mainParams ); cursesmain( isServer, &mainParams );
#endif #endif
} else if ( !useCurses ) { } else if ( !useCurses ) {
#if defined PLATFORM_GTK #if defined PLATFORM_GTK
gtkmain( &mainParams, argc, argv ); gtkmain( &mainParams, argc, argv );
#endif #endif
} else { } else {
usage( argv[0], "rtfm" ); usage( argv[0], "rtfm" );
}
vtmgr_destroy( MPPARM(mainParams.util->mpool) mainParams.vtMgr );
linux_util_vt_destroy( mainParams.util );
mpool_destroy( mainParams.util->mpool );
free( mainParams.util );
result = 0;
} }
vtmgr_destroy( MPPARM(mainParams.util->mpool) mainParams.vtMgr );
linux_util_vt_destroy( mainParams.util );
mpool_destroy( mainParams.util->mpool );
free( mainParams.util );
XP_LOGF( "%s exiting main", argv[0] ); XP_LOGF( "%s exiting main", argv[0] );
return 0; return result;
} /* main */ } /* main */