// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * * Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************/ /*------------------------------------------------------------------------------ * * UCommonData An abstract interface for dealing with ICU Common Data Files. * ICU Common Data Files are a grouping of a number of individual * data items (resources, converters, tables, anything) into a * single file or dll. The combined format includes a table of * contents for locating the individual items by name. * * Two formats for the table of contents are supported, which is * why there is an abstract interface involved. * */ #include "unicode/utypes.h" #include "unicode/udata.h" #include "cstring.h" #include "ucmndata.h" #include "udatamem.h" #if defined(UDATA_DEBUG) || defined(UDATA_DEBUG_DUMP) # include <stdio.h> #endif U_CFUNC uint16_t udata_getHeaderSize(const DataHeader *udh) { … } U_CFUNC uint16_t udata_getInfoSize(const UDataInfo *info) { … } /*-----------------------------------------------------------------------------* * * * Pointer TOCs. TODO: This form of table-of-contents should be removed * * because DLLs must be relocated on loading to correct the * * pointer values and this operation makes shared memory * * mapping of the data much less likely to work. * * * *-----------------------------------------------------------------------------*/ PointerTOCEntry; PointerTOC; /* definition of OffsetTOC struct types moved to ucmndata.h */ /*-----------------------------------------------------------------------------* * * * entry point lookup implementations * * * *-----------------------------------------------------------------------------*/ #ifndef MIN #define MIN(a,b) … #endif /** * Compare strings where we know the shared prefix length, * and advance the prefix length as we find that the strings share even more characters. */ static int32_t strcmpAfterPrefix(const char *s1, const char *s2, int32_t *pPrefixLength) { … } static int32_t offsetTOCPrefixBinarySearch(const char *s, const char *names, const UDataOffsetTOCEntry *toc, int32_t count) { … } static int32_t pointerTOCPrefixBinarySearch(const char *s, const PointerTOCEntry *toc, int32_t count) { … } U_CDECL_BEGIN static uint32_t U_CALLCONV offsetTOCEntryCount(const UDataMemory *pData) { … } static const DataHeader * U_CALLCONV offsetTOCLookupFn(const UDataMemory *pData, const char *tocEntryName, int32_t *pLength, UErrorCode *pErrorCode) { … } static uint32_t U_CALLCONV pointerTOCEntryCount(const UDataMemory *pData) { … } static const DataHeader * U_CALLCONV pointerTOCLookupFn(const UDataMemory *pData, const char *name, int32_t *pLength, UErrorCode *pErrorCode) { … } U_CDECL_END static const commonDataFuncs CmnDFuncs = …; static const commonDataFuncs ToCPFuncs = …; /*----------------------------------------------------------------------* * * * checkCommonData Validate the format of a common data file. * * Fill in the virtual function ptr based on TOC type * * If the data is invalid, close the UDataMemory * * and set the appropriate error code. * * * *----------------------------------------------------------------------*/ U_CFUNC void udata_checkCommonData(UDataMemory *udm, UErrorCode *err) { … } /* * TODO: Add a udata_swapPackageHeader() function that swaps an ICU .dat package * header but not its sub-items. * This function will be needed for automatic runtime swapping. * Sub-items should not be swapped to limit the swapping to the parts of the * package that are actually used. * * Since lengths of items are implicit in the order and offsets of their * ToC entries, and since offsets are relative to the start of the ToC, * a swapped version may need to generate a different data structure * with pointers to the original data items and with their lengths * (-1 for the last one if it is not known), and maybe even pointers to the * swapped versions of the items. * These pointers to swapped versions would establish a cache; * instead, each open data item could simply own the storage for its swapped * data. This fits better with the current design. * * markus 2003sep18 Jitterbug 2235 */