From e7c96290eaf44a84cf79ea9891e87b94586b3419 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 28 Apr 2020 14:06:09 -0700 Subject: [PATCH] name change only It was confusing using dict_ as the prefix for two "classes" --- .../android/xw4/DictBrowseDelegate.java | 28 +++++----- .../org/eehouse/android/xw4/jni/XwJNI.java | 34 ++++++------ xwords4/android/jni/xwjni.c | 42 +++++++-------- xwords4/common/dictiter.c | 54 +++++++++---------- xwords4/common/dictiter.h | 24 ++++----- xwords4/common/dictnry.c | 4 +- xwords4/linux/linuxmain.c | 54 +++++++++---------- 7 files changed, 118 insertions(+), 122 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java index 6f0db2441..6f9475a16 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DictBrowseDelegate.java @@ -83,9 +83,9 @@ public class DictBrowseDelegate extends DelegateBase { super(); - XwJNI.dict_iter_setMinMax( m_dictClosure, m_browseState.m_minShown, + XwJNI.di_setMinMax( m_dictClosure, m_browseState.m_minShown, m_browseState.m_maxShown ); - m_nWords = XwJNI.dict_iter_wordCount( m_dictClosure ); + m_nWords = XwJNI.di_wordCount( m_dictClosure ); int format = m_browseState.m_minShown == m_browseState.m_maxShown ? R.string.dict_browse_title1_fmt : R.string.dict_browse_title_fmt; @@ -98,7 +98,7 @@ public class DictBrowseDelegate extends DelegateBase { TextView text = (TextView) inflate( android.R.layout.simple_list_item_1 ); - String str = XwJNI.dict_iter_nthWord( m_dictClosure, position, null ); + String str = XwJNI.di_nthWord( m_dictClosure, position, null ); if ( null != str ) { text.setText( str ); text.setOnClickListener( DictBrowseDelegate.this ); @@ -141,8 +141,8 @@ public class DictBrowseDelegate extends DelegateBase @Override public Object[] getSections() { - m_prefixes = XwJNI.dict_iter_getPrefixes( m_dictClosure ); - m_indices = XwJNI.dict_iter_getIndices( m_dictClosure ); + m_prefixes = XwJNI.di_getPrefixes( m_dictClosure ); + m_indices = XwJNI.di_getIndices( m_dictClosure ); return m_prefixes; } } @@ -169,10 +169,10 @@ public class DictBrowseDelegate extends DelegateBase String[] names = { name }; DictUtils.DictPairs pairs = DictUtils.openDicts( m_activity, names ); - m_dictClosure = XwJNI.dict_iter_init( pairs.m_bytes[0], + m_dictClosure = XwJNI.di_init( pairs.m_bytes[0], name, pairs.m_paths[0] ); - String desc = XwJNI.dict_iter_getDesc( m_dictClosure ); + String desc = XwJNI.di_getDesc( m_dictClosure ); Log.d( TAG, "got desc: %s", desc ); if ( null != desc ) { TextView view = (TextView)findViewById( R.id.desc ); @@ -190,7 +190,7 @@ public class DictBrowseDelegate extends DelegateBase } if ( null == m_browseState.m_counts ) { m_browseState.m_counts = - XwJNI.dict_iter_getCounts( m_dictClosure ); + XwJNI.di_getCounts( m_dictClosure ); } if ( null == m_browseState.m_counts ) { @@ -249,7 +249,7 @@ public class DictBrowseDelegate extends DelegateBase @Override protected void onDestroy() { - XwJNI.dict_iter_destroy( m_dictClosure ); + XwJNI.di_destroy( m_dictClosure ); m_dictClosure = 0; } @@ -258,7 +258,7 @@ public class DictBrowseDelegate extends DelegateBase public void finalize() { Assert.assertTrueNR( m_dictClosure == 0 ); - XwJNI.dict_iter_destroy( m_dictClosure ); + XwJNI.di_destroy( m_dictClosure ); try { super.finalize(); } catch ( java.lang.Throwable err ){ @@ -276,7 +276,7 @@ public class DictBrowseDelegate extends DelegateBase final byte[][] choices = (byte[][])params[0]; final String[] strs = new String[choices.length]; for ( int ii = 0; ii < choices.length; ++ii ) { - strs[ii] = XwJNI.dict_iter_tilesToStr( m_dictClosure, choices[ii], "." ); + strs[ii] = XwJNI.di_tilesToStr( m_dictClosure, choices[ii], "." ); } final int[] chosen = {0}; dialog = makeAlertBuilder() @@ -374,7 +374,7 @@ public class DictBrowseDelegate extends DelegateBase if ( null != text && 0 < text.length() ) { m_browseState.m_prefix = text; - byte[][] choices = XwJNI.dict_iter_strToTiles( m_dictClosure, text ); + byte[][] choices = XwJNI.di_strToTiles( m_dictClosure, text ); if ( null == choices || 0 == choices.length ) { String msg = getString( R.string.no_tiles_exist, text, m_name ); makeOkOnlyBuilder( msg ).show(); @@ -402,11 +402,11 @@ public class DictBrowseDelegate extends DelegateBase { if ( null != prefix && 0 < prefix.length ) { // Here's the search - int pos = XwJNI.dict_iter_getStartsWith( m_dictClosure, prefix ); + int pos = XwJNI.di_getStartsWith( m_dictClosure, prefix ); if ( 0 <= pos ) { m_list.setSelection( pos ); } else { - String text = XwJNI.dict_iter_tilesToStr( m_dictClosure, prefix, null ); + String text = XwJNI.di_tilesToStr( m_dictClosure, prefix, null ); DbgUtils.showf( m_activity, R.string.dict_browse_nowords_fmt, m_name, text ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java index 5cd1e08f3..1f8aa1900 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/XwJNI.java @@ -514,25 +514,21 @@ public class XwJNI { // Dict iterator public final static int MAX_COLS_DICT = 15; // from dictiter.h - public static long dict_iter_init( byte[] dict, String name, - String path ) + public static long di_init( byte[] dict, String name, String path ) { - return dict_iter_init( getJNI().m_ptrGlobals, dict, name, path ); + return di_init( getJNI().m_ptrGlobals, dict, name, path ); } - public static native void dict_iter_setMinMax( long closure, - int min, int max ); - public static native void dict_iter_destroy( long closure ); - public static native int dict_iter_wordCount( long closure ); - public static native int[] dict_iter_getCounts( long closure ); - public static native String dict_iter_nthWord( long closure, int nn, String delim ); - public static native String[] dict_iter_getPrefixes( long closure ); - public static native int[] dict_iter_getIndices( long closure ); - public static native byte[][] dict_iter_strToTiles( long closure, - String str ); - public static native int dict_iter_getStartsWith( long closure, - byte[] prefix ); - public static native String dict_iter_getDesc( long closure ); - public static native String dict_iter_tilesToStr( long closure, byte[] tiles, String delim ); + public static native void di_setMinMax( long closure, int min, int max ); + public static native void di_destroy( long closure ); + public static native int di_wordCount( long closure ); + public static native int[] di_getCounts( long closure ); + public static native String di_nthWord( long closure, int nn, String delim ); + public static native String[] di_getPrefixes( long closure ); + public static native int[] di_getIndices( long closure ); + public static native byte[][] di_strToTiles( long closure, String str ); + public static native int di_getStartsWith( long closure, byte[] prefix ); + public static native String di_getDesc( long closure ); + public static native String di_tilesToStr( long closure, byte[] tiles, String delim ); // Private methods -- called only here private static native long initGlobals( DUtilCtxt dutil, JNIUtils jniu ); @@ -551,8 +547,8 @@ public class XwJNI { String name, String path, boolean check, DictInfo info ); - private static native long dict_iter_init( long jniState, byte[] dict, - String name, String path ); + private static native long di_init( long jniState, byte[] dict, + String name, String path ); private static native byte[][] smsproto_prepOutbound( long jniState, SMS_CMD cmd, int gameID, byte[] buf, diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index 437173c4d..47881298f 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -2414,7 +2414,7 @@ static void makeIndex( DictIterData* data ); static void freeIndices( DictIterData* data ); JNIEXPORT jlong JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init +Java_org_eehouse_android_xw4_jni_XwJNI_di_1init ( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes, jstring jname, jstring jpath ) { @@ -2443,19 +2443,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init } JNIEXPORT void JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1setMinMax +Java_org_eehouse_android_xw4_jni_XwJNI_di_1setMinMax ( JNIEnv* env, jclass C, jlong closure, jint min, jint max ) { DictIterData* data = (DictIterData*)closure; if ( NULL != data ) { - dict_initIter( &data->iter, data->dict, min, max ); + di_initIter( &data->iter, data->dict, min, max ); makeIndex( data ); - (void)dict_firstWord( &data->iter ); + (void)di_firstWord( &data->iter ); } } JNIEXPORT void JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy +Java_org_eehouse_android_xw4_jni_XwJNI_di_1destroy ( JNIEnv* env, jclass C, jlong closure ) { DictIterData* data = (DictIterData*)closure; @@ -2474,7 +2474,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy } JNIEXPORT jint JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount +Java_org_eehouse_android_xw4_jni_XwJNI_di_1wordCount (JNIEnv* env, jclass C, jlong closure ) { jint result = 0; @@ -2486,17 +2486,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount } JNIEXPORT jintArray JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts +Java_org_eehouse_android_xw4_jni_XwJNI_di_1getCounts (JNIEnv* env, jclass C, jlong closure ) { jintArray result = NULL; DictIterData* data = (DictIterData*)closure; if ( NULL != data ) { DictIter iter; - dict_initIter( &iter, data->dict, 0, MAX_COLS_DICT ); + di_initIter( &iter, data->dict, 0, MAX_COLS_DICT ); LengthsArray lens; - if ( 0 < dict_countWords( &iter, &lens ) ) { + if ( 0 < di_countWords( &iter, &lens ) ) { XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) ); result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens, sizeof(lens.lens[0]) ); @@ -2506,7 +2506,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts } JNIEXPORT jobjectArray JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes +Java_org_eehouse_android_xw4_jni_XwJNI_di_1getPrefixes ( JNIEnv* env, jclass C, jlong closure ) { jobjectArray result = NULL; @@ -2529,7 +2529,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes } JNIEXPORT jintArray JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getIndices +Java_org_eehouse_android_xw4_jni_XwJNI_di_1getIndices ( JNIEnv* env, jclass C, jlong closure ) { jintArray jindices = NULL; @@ -2545,17 +2545,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getIndices } JNIEXPORT jstring JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord +Java_org_eehouse_android_xw4_jni_XwJNI_di_1nthWord ( JNIEnv* env, jclass C, jlong closure, jint nn, jstring jdelim ) { jstring result = NULL; DictIterData* data = (DictIterData*)closure; if ( NULL != data ) { - if ( dict_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) { + if ( di_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) { XP_UCHAR buf[64]; const XP_UCHAR* delim = NULL == jdelim ? NULL : (*env)->GetStringUTFChars( env, jdelim, NULL ); - dict_wordToString( &data->iter, buf, VSIZE(buf), delim ); + di_wordToString( &data->iter, buf, VSIZE(buf), delim ); result = (*env)->NewStringUTF( env, buf ); if ( !!delim ) { (*env)->ReleaseStringUTFChars( env, jdelim, delim ); @@ -2581,7 +2581,7 @@ onFoundTiles( void* closure, const Tile* tiles, int nTiles ) } JNIEXPORT jobjectArray JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1strToTiles +Java_org_eehouse_android_xw4_jni_XwJNI_di_1strToTiles ( JNIEnv* env, jclass C, jlong closure, jstring jstr ) { jobjectArray result = NULL; @@ -2605,7 +2605,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1strToTiles } JNIEXPORT jint JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith +Java_org_eehouse_android_xw4_jni_XwJNI_di_1getStartsWith ( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles ) { jint result = -1; @@ -2613,8 +2613,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith XP_U16 nTiles = (*env)->GetArrayLength( env, jtiles ); jbyte* tiles = (*env)->GetByteArrayElements( env, jtiles, NULL ); - if ( 0 <= dict_findStartsWith( &data->iter, (Tile*)tiles, nTiles ) ) { - result = dict_getPosition( &data->iter ); + if ( 0 <= di_findStartsWith( &data->iter, (Tile*)tiles, nTiles ) ) { + result = di_getPosition( &data->iter ); } (*env)->ReleaseByteArrayElements( env, jtiles, tiles, 0 ); @@ -2623,7 +2623,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith } JNIEXPORT jstring JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1tilesToStr +Java_org_eehouse_android_xw4_jni_XwJNI_di_1tilesToStr ( JNIEnv* env, jclass C, jlong closure, jbyteArray jtiles, jstring jdelim ) { jstring result = NULL; @@ -2654,7 +2654,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1tilesToStr } JNIEXPORT jstring JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getDesc +Java_org_eehouse_android_xw4_jni_XwJNI_di_1getDesc ( JNIEnv* env, jclass C, jlong closure ) { jstring result = NULL; @@ -2701,7 +2701,7 @@ makeIndex( DictIterData* data ) count * sizeof(*idata->indices) ); idata->count = count; - dict_makeIndex( &data->iter, data->depth, idata ); + di_makeIndex( &data->iter, data->depth, idata ); if ( 0 < idata->count ) { idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes, idata->count * data->depth * diff --git a/xwords4/common/dictiter.c b/xwords4/common/dictiter.c index a1f91af13..188b4a804 100644 --- a/xwords4/common/dictiter.c +++ b/xwords4/common/dictiter.c @@ -224,9 +224,9 @@ wordsEqual( const DictIter* word1, const DictIter* word2 ) } static void -dict_initIterFrom( DictIter* dest, const DictIter* src ) +initIterFrom( DictIter* dest, const DictIter* src ) { - dict_initIter( dest, src->dict, + di_initIter( dest, src->dict, #ifdef XWFEATURE_WALKDICT_FILTER src->min, src->max #else @@ -249,10 +249,10 @@ firstWord( DictIter* iter ) } XP_U32 -dict_countWords( const DictIter* iter, LengthsArray* lens ) +di_countWords( const DictIter* iter, LengthsArray* lens ) { DictIter counter; - dict_initIterFrom( &counter, iter ); + initIterFrom( &counter, iter ); if ( NULL != lens ) { XP_MEMSET( lens, 0, sizeof(*lens) ); @@ -275,8 +275,8 @@ dict_countWords( const DictIter* iter, LengthsArray* lens ) #define ASSERT_INITED( iter ) XP_ASSERT( (iter)->guard == GUARD_VALUE ) void -dict_initIter( DictIter* iter, const DictionaryCtxt* dict, - XP_U16 min, XP_U16 max ) +di_initIter( DictIter* iter, const DictionaryCtxt* dict, + XP_U16 min, XP_U16 max ) { XP_MEMSET( iter, 0, sizeof(*iter) ); iter->dict = dict; @@ -364,7 +364,7 @@ indexOne( XP_U16 depth, Tile* tiles, IndexData* data, DictIter* prevIter, DictPosition* prevIndex ) { DictIter curIter; - dict_initIterFrom( &curIter, prevIter ); + initIterFrom( &curIter, prevIter ); if ( findWordStartsWith( &curIter, tiles, depth ) ) { while ( !wordsEqual( &curIter, prevIter ) ) { ++*prevIndex; @@ -401,7 +401,7 @@ doOneDepth( const Tile* allTiles, XP_U16 nTiles, Tile* prefix, } void -dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ) +di_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ) { ASSERT_INITED( iter ); const DictionaryCtxt* dict = iter->dict; @@ -433,7 +433,7 @@ dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ) */ data->count = 0; DictIter prevIter; - dict_initIterFrom( &prevIter, iter ); + initIterFrom( &prevIter, iter ); if ( firstWord( &prevIter ) ) { DictPosition prevIndex = 0; Tile prefix[depth]; @@ -452,11 +452,11 @@ dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ) static void initWord( DictIter* iter ) { - iter->nWords = dict_countWords( iter, NULL ); + iter->nWords = di_countWords( iter, NULL ); } XP_Bool -dict_firstWord( DictIter* iter ) +di_firstWord( DictIter* iter ) { ASSERT_INITED( iter ); XP_Bool success = firstWord( iter ); @@ -469,7 +469,7 @@ dict_firstWord( DictIter* iter ) } XP_Bool -dict_getNextWord( DictIter* iter ) +di_getNextWord( DictIter* iter ) { ASSERT_INITED( iter ); XP_Bool success = nextWord( iter ); @@ -480,7 +480,7 @@ dict_getNextWord( DictIter* iter ) } XP_Bool -dict_lastWord( DictIter* iter ) +di_lastWord( DictIter* iter ) { ASSERT_INITED( iter ); iter->nEdges = 1; @@ -496,7 +496,7 @@ dict_lastWord( DictIter* iter ) } XP_Bool -dict_getPrevWord( DictIter* iter ) +di_getPrevWord( DictIter* iter ) { ASSERT_INITED( iter ); XP_Bool success = prevWord( iter ); @@ -510,8 +510,8 @@ dict_getPrevWord( DictIter* iter ) sought. OR if we're father than necessary from what's sought, start over at the closer end. Then move as many steps as necessary to reach it. */ XP_Bool -dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, - const IndexData* data ) +di_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, + const IndexData* data ) { ASSERT_INITED( iter ); const DictionaryCtxt* dict = iter->dict; @@ -519,7 +519,7 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, XP_Bool validWord = 0 < iter->nEdges; if ( validWord ) { /* uninitialized */ wordCount = iter->nWords; - XP_ASSERT( wordCount == dict_countWords( iter, NULL ) ); + XP_ASSERT( wordCount == di_countWords( iter, NULL ) ); } else { wordCount = dict_getWordCount( dict ); } @@ -532,9 +532,9 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, success = XP_TRUE; /* do nothing; we're done */ } else if ( iter->position == position - 1 ) { - success = dict_getNextWord( iter ); + success = di_getNextWord( iter ); } else if ( iter->position == position + 1 ) { - success = dict_getPrevWord( iter ); + success = di_getPrevWord( iter ); } } @@ -557,9 +557,9 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, if ( !validWord ) { if ( position >= wordCount ) { - dict_lastWord( iter ); + di_lastWord( iter ); } else { - dict_firstWord( iter ); + di_firstWord( iter ); } } wordIndex = iter->position; @@ -585,14 +585,14 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, } } return success; -} /* dict_getNthWord */ +} /* di_getNthWord */ static DictPosition figurePosition( DictIter* iter ) { DictPosition result = 0; DictIter iterZero; - dict_initIterFrom( &iterZero, iter ); + initIterFrom( &iterZero, iter ); if ( !firstWord( &iterZero ) ) { XP_ASSERT( 0 ); } @@ -608,7 +608,7 @@ figurePosition( DictIter* iter ) } XP_S16 -dict_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 len ) +di_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 len ) { ASSERT_INITED( iter ); XP_S16 offset = findStartsWithTiles( iter, prefix, len ); @@ -630,15 +630,15 @@ dict_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 len ) } void -dict_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen, - const XP_UCHAR* delim ) +di_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen, + const XP_UCHAR* delim ) { ASSERT_INITED( iter ); iterToString( iter, buf, buflen, delim ); } DictPosition -dict_getPosition( const DictIter* iter ) +di_getPosition( const DictIter* iter ) { ASSERT_INITED( iter ); return iter->position; diff --git a/xwords4/common/dictiter.h b/xwords4/common/dictiter.h index 83f163751..7581b8b93 100644 --- a/xwords4/common/dictiter.h +++ b/xwords4/common/dictiter.h @@ -63,21 +63,21 @@ typedef struct _LengthsArray { XP_U32 lens[MAX_COLS_DICT+1]; } LengthsArray; -void dict_initIter( DictIter* iter, const DictionaryCtxt* dict, +void di_initIter( DictIter* iter, const DictionaryCtxt* dict, XP_U16 min, XP_U16 max ); -XP_U32 dict_countWords( const DictIter* iter, LengthsArray* lens ); -void dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ); -XP_Bool dict_firstWord( DictIter* iter ); -XP_Bool dict_lastWord( DictIter* iter ); -XP_Bool dict_getNextWord( DictIter* iter ); -XP_Bool dict_getPrevWord( DictIter* iter ); -XP_Bool dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, +XP_U32 di_countWords( const DictIter* iter, LengthsArray* lens ); +void di_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ); +XP_Bool di_firstWord( DictIter* iter ); +XP_Bool di_lastWord( DictIter* iter ); +XP_Bool di_getNextWord( DictIter* iter ); +XP_Bool di_getPrevWord( DictIter* iter ); +XP_Bool di_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, const IndexData* data ); -void dict_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen, +void di_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen, const XP_UCHAR* delim ); -XP_S16 dict_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 nTiles ); -void dict_stringToTiles( const XP_UCHAR* str, Tile out[], XP_U16* nTiles ); -DictPosition dict_getPosition( const DictIter* iter ); +XP_S16 di_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 nTiles ); +void di_stringToTiles( const XP_UCHAR* str, Tile out[], XP_U16* nTiles ); +DictPosition di_getPosition( const DictIter* iter ); #ifdef CPLUS } #endif diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 89f5e8859..ce82fd271 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -591,8 +591,8 @@ dict_getWordCount( const DictionaryCtxt* dict ) #ifdef XWFEATURE_WALKDICT if ( 0 == nWords ) { DictIter iter; - dict_initIter( &iter, dict, 0, MAX_COLS_DICT ); - nWords = dict_countWords( &iter, NULL ); + di_initIter( &iter, dict, 0, MAX_COLS_DICT ); + nWords = di_countWords( &iter, NULL ); } #endif return nWords; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 98af8f154..a53b9037d 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1903,16 +1903,16 @@ testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words), XP_U32 ii, jj; DictIter iter; - dict_initIter( &iter, dict, min, max ); - XP_U32 half = dict_countWords( &iter, NULL ) / 2; + di_initIter( &iter, dict, min, max ); + XP_U32 half = di_countWords( &iter, NULL ) / 2; XP_U32 interval = half / 100; if ( interval == 0 ) { ++interval; } for ( ii = 0, jj = half; ii < half; ii += interval, jj += interval ) { - if ( dict_getNthWord( &iter, ii, depth, data ) ) { - dict_wordToString( &iter, buf, VSIZE(buf), "." ); + if ( di_getNthWord( &iter, ii, depth, data ) ) { + di_wordToString( &iter, buf, VSIZE(buf), "." ); XP_ASSERT( 0 == strcmp( buf, words[ii] ) ); # ifdef PRINT_ALL XP_LOGF( "%s: word[%ld]: %s", __func__, ii, buf ); @@ -1920,8 +1920,8 @@ testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words), } else { XP_ASSERT( 0 ); } - if ( dict_getNthWord( &iter, jj, depth, data ) ) { - dict_wordToString( &iter, buf, VSIZE(buf), "." ); + if ( di_getNthWord( &iter, jj, depth, data ) ) { + di_wordToString( &iter, buf, VSIZE(buf), "." ); XP_ASSERT( 0 == strcmp( buf, words[jj] ) ); # ifdef PRINT_ALL XP_LOGF( "%s: word[%ld]: %s", __func__, jj, buf ); @@ -1943,25 +1943,25 @@ static XP_Bool onFoundTiles( void* closure, const Tile* tiles, int nTiles ) { FTData* ftp = (FTData*)closure; - XP_S16 lenMatched = dict_findStartsWith( ftp->iter, tiles, nTiles ); + XP_S16 lenMatched = di_findStartsWith( ftp->iter, tiles, nTiles ); if ( 0 <= lenMatched ) { XP_UCHAR buf[32]; XP_UCHAR bufPrev[32] = {0}; - dict_wordToString( ftp->iter, buf, VSIZE(buf), "." ); + di_wordToString( ftp->iter, buf, VSIZE(buf), "." ); /* This doesn't work with synonyms like "L-L" for "L·L" */ // XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) ); - DictPosition pos = dict_getPosition( ftp->iter ); + DictPosition pos = di_getPosition( ftp->iter ); XP_ASSERT( 0 == strcmp( buf, ftp->words[pos] ) ); if ( pos > 0 ) { - if ( !dict_getNthWord( ftp->iter, pos-1, ftp->depth, ftp->data ) ) { + if ( !di_getNthWord( ftp->iter, pos-1, ftp->depth, ftp->data ) ) { XP_ASSERT( 0 ); } - dict_wordToString( ftp->iter, bufPrev, VSIZE(bufPrev), "." ); + di_wordToString( ftp->iter, bufPrev, VSIZE(bufPrev), "." ); XP_ASSERT( 0 == strcmp( bufPrev, ftp->words[pos-1] ) ); } - XP_LOGF( "dict_getStartsWith(%s) => %s (prev=%s)", + XP_LOGF( "di_getStartsWith(%s) => %s (prev=%s)", ftp->prefix, buf, bufPrev ); } else { XP_LOGFF( "nothing starts with %s", ftp->prefix ); @@ -1985,9 +1985,9 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, max = MAX_COLS_DICT; } - dict_initIter( &iter, dict, min, max ); + di_initIter( &iter, dict, min, max ); LengthsArray lens; - XP_U32 count = dict_countWords( &iter, &lens ); + XP_U32 count = di_countWords( &iter, &lens ); XP_U32 sum = 0; for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) { @@ -2000,12 +2000,12 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, char** words = g_malloc( count * sizeof(char*) ); XP_ASSERT( !!words ); - for ( jj = 0, gotOne = dict_firstWord( &iter ); + for ( jj = 0, gotOne = di_firstWord( &iter ); gotOne; - gotOne = dict_getNextWord( &iter ) ) { - XP_ASSERT( dict_getPosition( &iter ) == jj ); + gotOne = di_getNextWord( &iter ) ) { + XP_ASSERT( di_getPosition( &iter ) == jj ); XP_UCHAR buf[64]; - dict_wordToString( &iter, buf, VSIZE(buf), "." ); + di_wordToString( &iter, buf, VSIZE(buf), "." ); # ifdef PRINT_ALL fprintf( stderr, "%.6ld: %s\n", jj, buf ); # endif @@ -2016,12 +2016,12 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, } XP_ASSERT( count == jj ); - for ( jj = 0, gotOne = dict_lastWord( &iter ); + for ( jj = 0, gotOne = di_lastWord( &iter ); gotOne; - ++jj, gotOne = dict_getPrevWord( &iter ) ) { - XP_ASSERT( dict_getPosition(&iter) == count-jj-1 ); + ++jj, gotOne = di_getPrevWord( &iter ) ) { + XP_ASSERT( di_getPosition(&iter) == count-jj-1 ); XP_UCHAR buf[64]; - dict_wordToString( &iter, buf, VSIZE(buf), "." ); + di_wordToString( &iter, buf, VSIZE(buf), "." ); # ifdef PRINT_ALL fprintf( stderr, "%.6ld: %s\n", jj, buf ); # endif @@ -2049,7 +2049,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, depth * data.count * sizeof(data.prefixes[0]) ); XP_LOGF( "making index..." ); - dict_makeIndex( &iter, depth, &data ); + di_makeIndex( &iter, depth, &data ); XP_LOGF( "DONE making index" ); data.indices = XP_REALLOC( mpool, data.indices, @@ -2122,12 +2122,12 @@ static void dumpDict( DictionaryCtxt* dict ) { DictIter iter; - dict_initIter( &iter, dict, 0, MAX_COLS_DICT ); - for ( XP_Bool result = dict_firstWord( &iter ); + di_initIter( &iter, dict, 0, MAX_COLS_DICT ); + for ( XP_Bool result = di_firstWord( &iter ); result; - result = dict_getNextWord( &iter ) ) { + result = di_getNextWord( &iter ) ) { XP_UCHAR buf[32]; - dict_wordToString( &iter, buf, VSIZE(buf), "." ); + di_wordToString( &iter, buf, VSIZE(buf), "." ); fprintf( stdout, "%s\n", buf ); } }