From 0e665a990e72065a99122a8b8bafc53c22b9b813 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 28 May 2022 09:00:20 -0700 Subject: [PATCH] add langName and isoCode to dict struct --- xwords4/common/dictnry.c | 20 +++++++++++++------- xwords4/common/dictnry.h | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 06b45935e..99c920eb1 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -282,13 +282,10 @@ parseCommon( DictionaryCtxt* dctx, XWEnv xwe, const XP_U8** ptrp, const XP_U8* e if ( ptr == headerEnd ) { goto done; } - XP_UCHAR* langName = NULL; - XP_UCHAR* langCode = NULL; - if ( getNullTermParam( dctx, &langName, &ptr, headerEnd ) - && getNullTermParam( dctx, &langCode, &ptr, headerEnd ) ) { - XP_LOGFF( "got langName: %s; langCode: %s", langName, langCode ); - XP_FREEP( dctx->mpool, &langName ); - XP_FREEP( dctx->mpool, &langCode ); + if ( getNullTermParam( dctx, &dctx->isoCode, &ptr, headerEnd ) + && getNullTermParam( dctx, &dctx->langName, &ptr, headerEnd ) ) { + XP_LOGFF( "got langName: %s; isoCode: %s", dctx->langName, + dctx->isoCode ); } else { goto done; } @@ -362,6 +359,12 @@ parseCommon( DictionaryCtxt* dctx, XWEnv xwe, const XP_U8** ptrp, const XP_U8* e } dctx->langCode = xloc & 0x7F; + if ( NULL == dctx->isoCode ) { + const XP_UCHAR* isoCode = lcToLocale( dctx->langCode ); + XP_ASSERT( !!isoCode ); + dctx->isoCode = copyString( dctx->mpool, isoCode ); + XP_LOGFF( "looked up isoCode %s for langCode %d", isoCode, dctx->langCode ); + } } if ( formatOk ) { @@ -1062,6 +1065,7 @@ destroy_stubbed_dict( DictionaryCtxt* dict ) XP_FREE( dict->mpool, dict->chars ); XP_FREE( dict->mpool, dict->name ); XP_FREE( dict->mpool, dict->langName ); + XP_FREE( dict->mpool, dict->isoCode ); XP_FREE( dict->mpool, dict->bitmaps ); XP_FREE( dict->mpool, dict ); } /* destroy_stubbed_dict */ @@ -1217,6 +1221,8 @@ dict_super_destroy( DictionaryCtxt* dict ) XP_FREEP( dict->mpool, &dict->faces ); XP_FREEP( dict->mpool, &dict->facePtrs ); XP_FREEP( dict->mpool, &dict->name ); + XP_FREEP( dict->mpool, &dict->isoCode ); + XP_FREEP( dict->mpool, &dict->langName ); } const XP_UCHAR* diff --git a/xwords4/common/dictnry.h b/xwords4/common/dictnry.h index 20ce061e5..36f90c22d 100644 --- a/xwords4/common/dictnry.h +++ b/xwords4/common/dictnry.h @@ -81,6 +81,7 @@ struct DictionaryCtxt { necessarily the entry point for search!! */ XP_UCHAR* name; XP_UCHAR* langName; + XP_UCHAR* isoCode; XP_UCHAR* faces; /* storage for faces */ XP_UCHAR* facesEnd; XP_UCHAR* desc;