mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-29 10:26:36 +01:00
fix to compile and produce correct output on 64-bit system
This commit is contained in:
parent
a72932486b
commit
f50c1191b5
1 changed files with 16 additions and 24 deletions
|
@ -90,7 +90,7 @@ static char* gCountFile = NULL;
|
||||||
static const char* gLang = NULL;
|
static const char* gLang = NULL;
|
||||||
static char* gBytesPerNodeFile = NULL; // where to write whether node
|
static char* gBytesPerNodeFile = NULL; // where to write whether node
|
||||||
// size 3 or 4
|
// size 3 or 4
|
||||||
int gWordCount = 0;
|
uint32_t gWordCount = 0;
|
||||||
std::map<wchar_t,Letter> gTableHash;
|
std::map<wchar_t,Letter> gTableHash;
|
||||||
int gBlankIndex;
|
int gBlankIndex;
|
||||||
std::vector<wchar_t> gRevMap;
|
std::vector<wchar_t> gRevMap;
|
||||||
|
@ -133,13 +133,12 @@ static void TrieNodeSetFirstChildOffset( Node* nodeR, int fco );
|
||||||
static int TrieNodeGetFirstChildOffset( Node node );
|
static int TrieNodeGetFirstChildOffset( Node node );
|
||||||
static int findSubArray( NodeList& newedgesR );
|
static int findSubArray( NodeList& newedgesR );
|
||||||
static void registerSubArray( NodeList& edgesR, int nodeLoc );
|
static void registerSubArray( NodeList& edgesR, int nodeLoc );
|
||||||
|
static void write32( const char* fileName, uint32_t value );
|
||||||
static Node MakeTrieNode( Letter letter, bool isTerminal,
|
static Node MakeTrieNode( Letter letter, bool isTerminal,
|
||||||
int firstChildOffset, bool isLastSibling );
|
int firstChildOffset, bool isLastSibling );
|
||||||
static void printNodes( NodeList& nodesR );
|
static void printNodes( NodeList& nodesR );
|
||||||
static void printNode( int index, Node node );
|
static void printNode( int index, Node node );
|
||||||
static void moveTopToFront( int* firstRef );
|
static void moveTopToFront( int* firstRef );
|
||||||
static void writeOutStartNode( const char* startNodeOut,
|
|
||||||
int firstRootChildOffset );
|
|
||||||
static void emitNodes( unsigned int nBytesPerOutfile, const char* outFileBase );
|
static void emitNodes( unsigned int nBytesPerOutfile, const char* outFileBase );
|
||||||
static void outputNode( Node node, int nBytes, FILE* outfile );
|
static void outputNode( Node node, int nBytes, FILE* outfile );
|
||||||
static void printOneLevel( int index, char* str, int curlen );
|
static void printOneLevel( int index, char* str, int curlen );
|
||||||
|
@ -203,7 +202,7 @@ main( int argc, char** argv )
|
||||||
moveTopToFront( &firstRootChildOffset );
|
moveTopToFront( &firstRootChildOffset );
|
||||||
|
|
||||||
if ( gStartNodeOut ) {
|
if ( gStartNodeOut ) {
|
||||||
writeOutStartNode( gStartNodeOut, firstRootChildOffset );
|
write32( gStartNodeOut, firstRootChildOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -214,11 +213,7 @@ main( int argc, char** argv )
|
||||||
#endif
|
#endif
|
||||||
// write out the number of nodes if requested
|
// write out the number of nodes if requested
|
||||||
if ( gCountFile ) {
|
if ( gCountFile ) {
|
||||||
FILE* OFILE;
|
write32( gCountFile, gWordCount );
|
||||||
OFILE = fopen( gCountFile, "w" );
|
|
||||||
unsigned long be = htonl( gWordCount );
|
|
||||||
fwrite( &be, sizeof(be), 1, OFILE );
|
|
||||||
fclose( OFILE );
|
|
||||||
fprintf( stderr, "Wrote %d (word count) to %s\n", gWordCount,
|
fprintf( stderr, "Wrote %d (word count) to %s\n", gWordCount,
|
||||||
gCountFile );
|
gCountFile );
|
||||||
}
|
}
|
||||||
|
@ -897,18 +892,6 @@ MakeTrieNode( Letter letter, bool isTerminal, int firstChildOffset,
|
||||||
return result;
|
return result;
|
||||||
} // MakeTrieNode
|
} // MakeTrieNode
|
||||||
|
|
||||||
// Caller may need to know the offset of the first top-level node.
|
|
||||||
// Write it here.
|
|
||||||
static void
|
|
||||||
writeOutStartNode( const char* startNodeOut, int firstRootChildOffset )
|
|
||||||
{
|
|
||||||
FILE* nodeout;
|
|
||||||
nodeout = fopen( startNodeOut, "w" );
|
|
||||||
unsigned long be = htonl( firstRootChildOffset );
|
|
||||||
(void)fwrite( &be, sizeof(be), 1, nodeout );
|
|
||||||
fclose( nodeout );
|
|
||||||
} // writeOutStartNode
|
|
||||||
|
|
||||||
// build the hash for translating. I'm using a hash assuming it'll be fast.
|
// build the hash for translating. I'm using a hash assuming it'll be fast.
|
||||||
// Key is the letter; value is the 0..31 value to be output. Note that input
|
// Key is the letter; value is the 0..31 value to be output. Note that input
|
||||||
// may be in the format "A a" rather than just "A"
|
// may be in the format "A a" rather than just "A"
|
||||||
|
@ -992,7 +975,7 @@ emitNodes( unsigned int nBytesPerOutfile, const char* outFileBase )
|
||||||
// now do the emit.
|
// now do the emit.
|
||||||
|
|
||||||
// is 17 bits enough?
|
// is 17 bits enough?
|
||||||
fprintf( stderr, "There are %d (0x%x) nodes in this DAWG.\n",
|
fprintf( stderr, "There are %zd (0x%zx) nodes in this DAWG.\n",
|
||||||
gNodes.size(), gNodes.size() );
|
gNodes.size(), gNodes.size() );
|
||||||
int nTiles = gTableHash.size(); // blank is not included in this count!
|
int nTiles = gTableHash.size(); // blank is not included in this count!
|
||||||
if ( gNodes.size() > 0x1FFFF || gForceFour || nTiles > 32 ) {
|
if ( gNodes.size() > 0x1FFFF || gForceFour || nTiles > 32 ) {
|
||||||
|
@ -1175,6 +1158,15 @@ outputNode( Node node, int nBytes, FILE* outfile )
|
||||||
}
|
}
|
||||||
} // outputNode
|
} // outputNode
|
||||||
|
|
||||||
|
static void
|
||||||
|
write32( const char* fileName, uint32_t value )
|
||||||
|
{
|
||||||
|
FILE* OFILE = fopen( fileName, "w" );
|
||||||
|
value = htonl( value );
|
||||||
|
fwrite( &value, sizeof(value), 1, OFILE );
|
||||||
|
fclose( OFILE );
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage( const char* name )
|
usage( const char* name )
|
||||||
{
|
{
|
||||||
|
@ -1199,7 +1191,7 @@ usage( const char* name )
|
||||||
#endif
|
#endif
|
||||||
"\t[-force4] # always use 4 bytes per node\n"
|
"\t[-force4] # always use 4 bytes per node\n"
|
||||||
"\t[-lang lang] # e.g. en_US\n"
|
"\t[-lang lang] # e.g. en_US\n"
|
||||||
"\t[-fsize nBytes] # max buffer [default %d]\n"
|
"\t[-fsize nBytes] # max buffer [default %zd]\n"
|
||||||
"\t[-r] # drop words with letters not in mapfile\n"
|
"\t[-r] # drop words with letters not in mapfile\n"
|
||||||
"\t[-k] # (default) exit on any letter not in mapfile \n",
|
"\t[-k] # (default) exit on any letter not in mapfile \n",
|
||||||
name, MAX_POOL_SIZE
|
name, MAX_POOL_SIZE
|
||||||
|
@ -1233,7 +1225,7 @@ parseARGV( int argc, char** argv, const char** inFileName )
|
||||||
VERSION_STR );
|
VERSION_STR );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
} else if ( 0 == strcmp( arg, "-poolsize" ) ) {
|
} else if ( 0 == strcmp( arg, "-poolsize" ) ) {
|
||||||
printf( "%d", MAX_POOL_SIZE );
|
printf( "%zd", MAX_POOL_SIZE );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
} else if ( 0 == strcmp( arg, "-b" ) ) {
|
} else if ( 0 == strcmp( arg, "-b" ) ) {
|
||||||
gNBytesPerOutfile = atol( argv[index++] );
|
gNBytesPerOutfile = atol( argv[index++] );
|
||||||
|
|
Loading…
Reference in a new issue