From 99ba48ce3e222d5ce297348830be24cd47a1222d Mon Sep 17 00:00:00 2001 From: ehouse Date: Tue, 2 May 2006 13:28:07 +0000 Subject: [PATCH] add poolsize and fsize args to better warn users when dict is too big. Later need to modify the build process to specify the size needed. --- xwords4/dawg/dict2dawg.cpp | 17 ++++++++++++++--- xwords4/dawg/dict2dawg.pl | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/xwords4/dawg/dict2dawg.cpp b/xwords4/dawg/dict2dawg.cpp index 98f268d1e..5dd3286b7 100644 --- a/xwords4/dawg/dict2dawg.cpp +++ b/xwords4/dawg/dict2dawg.cpp @@ -78,7 +78,8 @@ bool gKillIfMissing = true; char gTermChar = '\n'; bool gDumpText = false; // dump the dict as text after? char* gCountFile = NULL; -char* gBytesPerNodeFile = NULL; // where to write whether node size 3 or 4 +char* gBytesPerNodeFile = NULL; // where to write whether node + // size 3 or 4 int gWordCount = 0; std::map gTableHash; int gBlankIndex; @@ -88,12 +89,13 @@ bool gDebug = false; #endif std::map gSubsHash; bool gForceFour = false; // use four bytes regardless of need? +static int gFileSize = 0; int gNBytesPerNode; bool gUseUnicode; // OWL is 1.7M -#define MAX_POOL_SIZE 3000000 +#define MAX_POOL_SIZE (3 * 0x100000) #define ERROR_EXIT(...) error_exit( __LINE__, __VA_ARGS__ ); static char* parseARGV( int argc, char** argv, const char** inFileName ); @@ -581,7 +583,10 @@ parseAndSort( FILE* infile ) // allocate storage for the actual chars. wordlist's char* // elements will point into this. It'll leak. So what. - int memleft = MAX_POOL_SIZE; + int memleft = gFileSize; + if ( memleft == 0 ) { + memleft = MAX_POOL_SIZE; + } char* str = (char*)malloc( memleft ); if ( NULL == str ) { ERROR_EXIT( "can't allocate main string storage" ); @@ -985,6 +990,7 @@ usage( const char* name ) { fprintf( stderr, "usage: %s \n" "\t[-v] (print version and exit)\n" + "\t[-poolsize] (print size of hardcoded pool and exit)\n" "\t[-b bytesPerFile] (default = 0xFFFFFFFF)\n" "\t-m mapFile\n" "\t-mn mapFile (unicode)\n" @@ -1030,6 +1036,9 @@ parseARGV( int argc, char** argv, const char** inFileName ) fprintf( stderr, "%s (Subversion revision %s)\n", argv[0], VERSION_STR ); exit( 0 ); + } else if ( 0 == strcmp( arg, "-poolsize" ) ) { + printf( "%d", MAX_POOL_SIZE ); + exit( 0 ); } else if ( 0 == strcmp( arg, "-b" ) ) { gNBytesPerOutfile = atol( argv[index++] ); } else if ( 0 == strcmp( arg, "-mn" ) ) { @@ -1059,6 +1068,8 @@ parseARGV( int argc, char** argv, const char** inFileName ) gBytesPerNodeFile = argv[index++]; } else if ( 0 == strcmp( arg, "-force4" ) ) { gForceFour = true; + } else if ( 0 == strcmp( arg, "-fsize" ) ) { + gFileSize = (char)atoi(argv[index++]); #ifdef DEBUG } else if ( 0 == strcmp( arg, "-debug" ) ) { gDebug = true; diff --git a/xwords4/dawg/dict2dawg.pl b/xwords4/dawg/dict2dawg.pl index 56784b730..064dff84e 100755 --- a/xwords4/dawg/dict2dawg.pl +++ b/xwords4/dawg/dict2dawg.pl @@ -838,6 +838,8 @@ sub parseARGV { if ($arg =~ /-wc/) {$gCountFile = shift(@ARGV); last SWITCH;} if ($arg =~ /-ns/) {$gBytesPerNodeFile = shift(@ARGV); last SWITCH;} if ($arg =~ /-force4/) {$gForceFour = 1; last SWITCH;} + # accept -fsize for compatibility with c++ version (but drop it) + if ($arg =~ /-fsize/) {shift(@ARGV); last SWITCH;} if ($arg =~ /-debug/) {$debug = 1; last SWITCH;} die "unexpected arg $arg\n"; }