From 08aa9b66e877037ed959ef83ccbb543107cda7e6 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 26 Aug 2012 20:59:17 -0700 Subject: [PATCH] also load new desc field in android client, and add jni call to retrieve it --- xwords4/android/XWords4/jni/anddict.c | 11 +++++++++++ xwords4/android/XWords4/jni/xwjni.c | 15 +++++++++++++++ .../src/org/eehouse/android/xw4/jni/XwJNI.java | 1 + 3 files changed, 27 insertions(+) diff --git a/xwords4/android/XWords4/jni/anddict.c b/xwords4/android/XWords4/jni/anddict.c index 382736b7f..2a81f3e02 100644 --- a/xwords4/android/XWords4/jni/anddict.c +++ b/xwords4/android/XWords4/jni/anddict.c @@ -292,6 +292,16 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength, ctxt->super.nWords = n_ptr_tohl( &ptr ); headerLen -= 4; /* don't skip it */ } + + if ( 1 <= headerLen ) { /* have description? */ + XP_U16 len = 1 + XP_STRLEN( ptr ); + ctxt->super.desc = + (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, len); + XP_MEMCPY( ctxt->super.desc, ptr, len ); + ptr += len; + headerLen -= len; + } + CHECK_PTR( ptr, headerLen, end ); ptr += headerLen; } @@ -430,6 +440,7 @@ and_dictionary_destroy( DictionaryCtxt* dict ) XP_FREE( ctxt->super.mpool, ctxt->super.bitmaps ); } + XP_FREEP( ctxt->super.mpool, &ctxt->super.desc ); XP_FREEP( ctxt->super.mpool, &ctxt->super.faces ); XP_FREEP( ctxt->super.mpool, &ctxt->super.facePtrs ); XP_FREEP( ctxt->super.mpool, &ctxt->super.countsAndValues ); diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 2b31ff89c..5ba7f4cc2 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -1581,6 +1581,21 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith return result; } +JNIEXPORT jstring JNICALL +Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getDesc +( JNIEnv* env, jclass C, jint closure ) +{ + jstring result = NULL; + DictIterData* data = (DictIterData*)closure; + if ( NULL != data ) { + const XP_UCHAR* disc = dict_getDesc( data->dict ); + if ( NULL != disc && '\0' != disc[0] ) { + result = (*env)->NewStringUTF( env, disc ); + } + } + return result; +} + #ifdef XWFEATURE_BASE64 JNIEXPORT jstring JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_base64Encode diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index a5f042bcc..9d687bf5e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -257,6 +257,7 @@ public class XwJNI { public static native int[] dict_iter_getIndices( int closure ); public static native int dict_iter_getStartsWith( int closure, String prefix ); + public static native String dict_iter_getDesc( int closure ); // base64 stuff since 2.1 doesn't support it in java public static native String base64Encode( byte[] in );