1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/udataswp.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,349 @@
1.4 +/*
1.5 +*******************************************************************************
1.6 +*
1.7 +* Copyright (C) 2003-2005, International Business Machines
1.8 +* Corporation and others. All Rights Reserved.
1.9 +*
1.10 +*******************************************************************************
1.11 +* file name: udataswp.h
1.12 +* encoding: US-ASCII
1.13 +* tab size: 8 (not used)
1.14 +* indentation:4
1.15 +*
1.16 +* created on: 2003jun05
1.17 +* created by: Markus W. Scherer
1.18 +*
1.19 +* Definitions for ICU data transformations for different platforms,
1.20 +* changing between big- and little-endian data and/or between
1.21 +* charset families (ASCII<->EBCDIC).
1.22 +*/
1.23 +
1.24 +#ifndef __UDATASWP_H__
1.25 +#define __UDATASWP_H__
1.26 +
1.27 +#include <stdarg.h>
1.28 +#include "unicode/utypes.h"
1.29 +
1.30 +/* forward declaration */
1.31 +
1.32 +U_CDECL_BEGIN
1.33 +
1.34 +struct UDataSwapper;
1.35 +typedef struct UDataSwapper UDataSwapper;
1.36 +
1.37 +/**
1.38 + * Function type for data transformation.
1.39 + * Transforms data, or just returns the length of the data if
1.40 + * the input length is -1.
1.41 + * Swap functions assume that their data pointers are aligned properly.
1.42 + *
1.43 + * Quick implementation outline:
1.44 + * (best to copy and adapt and existing swapper implementation)
1.45 + * check that the data looks like the expected format
1.46 + * if(length<0) {
1.47 + * preflight:
1.48 + * never dereference outData
1.49 + * read inData and determine the data size
1.50 + * assume that inData is long enough for this
1.51 + * } else {
1.52 + * outData can be NULL if length==0
1.53 + * inData==outData (in-place swapping) possible but not required!
1.54 + * verify that length>=(actual size)
1.55 + * if there is a chance that not every byte up to size is reached
1.56 + * due to padding etc.:
1.57 + * if(inData!=outData) {
1.58 + * memcpy(outData, inData, actual size);
1.59 + * }
1.60 + * swap contents
1.61 + * }
1.62 + * return actual size
1.63 + *
1.64 + * Further implementation notes:
1.65 + * - read integers from inData before swapping them
1.66 + * because in-place swapping can make them unreadable
1.67 + * - compareInvChars compares a local Unicode string with already-swapped
1.68 + * output charset strings
1.69 + *
1.70 + * @param ds Pointer to UDataSwapper containing global data about the
1.71 + * transformation and function pointers for handling primitive
1.72 + * types.
1.73 + * @param inData Pointer to the input data to be transformed or examined.
1.74 + * @param length Length of the data, counting bytes. May be -1 for preflighting.
1.75 + * If length>=0, then transform the data.
1.76 + * If length==-1, then only determine the length of the data.
1.77 + * The length cannot be determined from the data itself for all
1.78 + * types of data (e.g., not for simple arrays of integers).
1.79 + * @param outData Pointer to the output data buffer.
1.80 + * If length>=0 (transformation), then the output buffer must
1.81 + * have a capacity of at least length.
1.82 + * If length==-1, then outData will not be used and can be NULL.
1.83 + * @param pErrorCode ICU UErrorCode parameter, must not be NULL and must
1.84 + * fulfill U_SUCCESS on input.
1.85 + * @return The actual length of the data.
1.86 + *
1.87 + * @see UDataSwapper
1.88 + * @internal ICU 2.8
1.89 + */
1.90 +typedef int32_t U_CALLCONV
1.91 +UDataSwapFn(const UDataSwapper *ds,
1.92 + const void *inData, int32_t length, void *outData,
1.93 + UErrorCode *pErrorCode);
1.94 +
1.95 +/**
1.96 + * Convert one uint16_t from input to platform endianness.
1.97 + * @internal ICU 2.8
1.98 + */
1.99 +typedef uint16_t U_CALLCONV
1.100 +UDataReadUInt16(uint16_t x);
1.101 +
1.102 +/**
1.103 + * Convert one uint32_t from input to platform endianness.
1.104 + * @internal ICU 2.8
1.105 + */
1.106 +typedef uint32_t U_CALLCONV
1.107 +UDataReadUInt32(uint32_t x);
1.108 +
1.109 +/**
1.110 + * Convert one uint16_t from platform to input endianness.
1.111 + * @internal ICU 2.8
1.112 + */
1.113 +typedef void U_CALLCONV
1.114 +UDataWriteUInt16(uint16_t *p, uint16_t x);
1.115 +
1.116 +/**
1.117 + * Convert one uint32_t from platform to input endianness.
1.118 + * @internal ICU 2.8
1.119 + */
1.120 +typedef void U_CALLCONV
1.121 +UDataWriteUInt32(uint32_t *p, uint32_t x);
1.122 +
1.123 +/**
1.124 + * Compare invariant-character strings, one in the output data and the
1.125 + * other one caller-provided in Unicode.
1.126 + * An output data string is compared because strings are usually swapped
1.127 + * before the rest of the data, to allow for sorting of string tables
1.128 + * according to the output charset.
1.129 + * You can use -1 for the length parameters of NUL-terminated strings as usual.
1.130 + * Returns Unicode code point order for invariant characters.
1.131 + * @internal ICU 2.8
1.132 + */
1.133 +typedef int32_t U_CALLCONV
1.134 +UDataCompareInvChars(const UDataSwapper *ds,
1.135 + const char *outString, int32_t outLength,
1.136 + const UChar *localString, int32_t localLength);
1.137 +
1.138 +/**
1.139 + * Function for message output when an error occurs during data swapping.
1.140 + * A format string and variable number of arguments are passed
1.141 + * like for vprintf().
1.142 + *
1.143 + * @param context A function-specific context pointer.
1.144 + * @param fmt The format string.
1.145 + * @param args The arguments for format string inserts.
1.146 + *
1.147 + * @internal ICU 2.8
1.148 + */
1.149 +typedef void U_CALLCONV
1.150 +UDataPrintError(void *context, const char *fmt, va_list args);
1.151 +
1.152 +struct UDataSwapper {
1.153 + /** Input endianness. @internal ICU 2.8 */
1.154 + UBool inIsBigEndian;
1.155 + /** Input charset family. @see U_CHARSET_FAMILY @internal ICU 2.8 */
1.156 + uint8_t inCharset;
1.157 + /** Output endianness. @internal ICU 2.8 */
1.158 + UBool outIsBigEndian;
1.159 + /** Output charset family. @see U_CHARSET_FAMILY @internal ICU 2.8 */
1.160 + uint8_t outCharset;
1.161 +
1.162 + /* basic functions for reading data values */
1.163 +
1.164 + /** Convert one uint16_t from input to platform endianness. @internal ICU 2.8 */
1.165 + UDataReadUInt16 *readUInt16;
1.166 + /** Convert one uint32_t from input to platform endianness. @internal ICU 2.8 */
1.167 + UDataReadUInt32 *readUInt32;
1.168 + /** Compare an invariant-character output string with a local one. @internal ICU 2.8 */
1.169 + UDataCompareInvChars *compareInvChars;
1.170 +
1.171 + /* basic functions for writing data values */
1.172 +
1.173 + /** Convert one uint16_t from platform to input endianness. @internal ICU 2.8 */
1.174 + UDataWriteUInt16 *writeUInt16;
1.175 + /** Convert one uint32_t from platform to input endianness. @internal ICU 2.8 */
1.176 + UDataWriteUInt32 *writeUInt32;
1.177 +
1.178 + /* basic functions for data transformations */
1.179 +
1.180 + /** Transform an array of 16-bit integers. @internal ICU 2.8 */
1.181 + UDataSwapFn *swapArray16;
1.182 + /** Transform an array of 32-bit integers. @internal ICU 2.8 */
1.183 + UDataSwapFn *swapArray32;
1.184 + /** Transform an invariant-character string. @internal ICU 2.8 */
1.185 + UDataSwapFn *swapInvChars;
1.186 +
1.187 + /**
1.188 + * Function for message output when an error occurs during data swapping.
1.189 + * Can be NULL.
1.190 + * @internal ICU 2.8
1.191 + */
1.192 + UDataPrintError *printError;
1.193 + /** Context pointer for printError. @internal ICU 2.8 */
1.194 + void *printErrorContext;
1.195 +};
1.196 +
1.197 +U_CDECL_END
1.198 +
1.199 +U_CAPI UDataSwapper * U_EXPORT2
1.200 +udata_openSwapper(UBool inIsBigEndian, uint8_t inCharset,
1.201 + UBool outIsBigEndian, uint8_t outCharset,
1.202 + UErrorCode *pErrorCode);
1.203 +
1.204 +/**
1.205 + * Open a UDataSwapper for the given input data and the specified output
1.206 + * characteristics.
1.207 + * Values of -1 for any of the characteristics mean the local platform's
1.208 + * characteristics.
1.209 + *
1.210 + * @see udata_swap
1.211 + * @internal ICU 2.8
1.212 + */
1.213 +U_CAPI UDataSwapper * U_EXPORT2
1.214 +udata_openSwapperForInputData(const void *data, int32_t length,
1.215 + UBool outIsBigEndian, uint8_t outCharset,
1.216 + UErrorCode *pErrorCode);
1.217 +
1.218 +U_CAPI void U_EXPORT2
1.219 +udata_closeSwapper(UDataSwapper *ds);
1.220 +
1.221 +/**
1.222 + * Read the beginning of an ICU data piece, recognize magic bytes,
1.223 + * swap the structure.
1.224 + * Set a U_UNSUPPORTED_ERROR if it does not look like an ICU data piece.
1.225 + *
1.226 + * @return The size of the data header, in bytes.
1.227 + *
1.228 + * @internal ICU 2.8
1.229 + */
1.230 +U_CAPI int32_t U_EXPORT2
1.231 +udata_swapDataHeader(const UDataSwapper *ds,
1.232 + const void *inData, int32_t length, void *outData,
1.233 + UErrorCode *pErrorCode);
1.234 +
1.235 +/**
1.236 + * Convert one int16_t from input to platform endianness.
1.237 + * @internal ICU 2.8
1.238 + */
1.239 +U_CAPI int16_t U_EXPORT2
1.240 +udata_readInt16(const UDataSwapper *ds, int16_t x);
1.241 +
1.242 +/**
1.243 + * Convert one int32_t from input to platform endianness.
1.244 + * @internal ICU 2.8
1.245 + */
1.246 +U_CAPI int32_t U_EXPORT2
1.247 +udata_readInt32(const UDataSwapper *ds, int32_t x);
1.248 +
1.249 +/**
1.250 + * Swap a block of invariant, NUL-terminated strings, but not padding
1.251 + * bytes after the last string.
1.252 + * @internal
1.253 + */
1.254 +U_CAPI int32_t U_EXPORT2
1.255 +udata_swapInvStringBlock(const UDataSwapper *ds,
1.256 + const void *inData, int32_t length, void *outData,
1.257 + UErrorCode *pErrorCode);
1.258 +
1.259 +U_CAPI void U_EXPORT2
1.260 +udata_printError(const UDataSwapper *ds,
1.261 + const char *fmt,
1.262 + ...);
1.263 +
1.264 +/* internal exports from putil.c -------------------------------------------- */
1.265 +
1.266 +/* declared here to keep them out of the public putil.h */
1.267 +
1.268 +/**
1.269 + * Swap invariant char * strings ASCII->EBCDIC.
1.270 + * @internal
1.271 + */
1.272 +U_CFUNC int32_t
1.273 +uprv_ebcdicFromAscii(const UDataSwapper *ds,
1.274 + const void *inData, int32_t length, void *outData,
1.275 + UErrorCode *pErrorCode);
1.276 +
1.277 +/**
1.278 + * Copy invariant ASCII char * strings and verify they are invariant.
1.279 + * @internal
1.280 + */
1.281 +U_CFUNC int32_t
1.282 +uprv_copyAscii(const UDataSwapper *ds,
1.283 + const void *inData, int32_t length, void *outData,
1.284 + UErrorCode *pErrorCode);
1.285 +
1.286 +/**
1.287 + * Swap invariant char * strings EBCDIC->ASCII.
1.288 + * @internal
1.289 + */
1.290 +U_CFUNC int32_t
1.291 +uprv_asciiFromEbcdic(const UDataSwapper *ds,
1.292 + const void *inData, int32_t length, void *outData,
1.293 + UErrorCode *pErrorCode);
1.294 +
1.295 +/**
1.296 + * Copy invariant EBCDIC char * strings and verify they are invariant.
1.297 + * @internal
1.298 + */
1.299 +U_CFUNC int32_t
1.300 +uprv_copyEbcdic(const UDataSwapper *ds,
1.301 + const void *inData, int32_t length, void *outData,
1.302 + UErrorCode *pErrorCode);
1.303 +
1.304 +/**
1.305 + * Compare ASCII invariant char * with Unicode invariant UChar *
1.306 + * @internal
1.307 + */
1.308 +U_CFUNC int32_t
1.309 +uprv_compareInvAscii(const UDataSwapper *ds,
1.310 + const char *outString, int32_t outLength,
1.311 + const UChar *localString, int32_t localLength);
1.312 +
1.313 +/**
1.314 + * Compare EBCDIC invariant char * with Unicode invariant UChar *
1.315 + * @internal
1.316 + */
1.317 +U_CFUNC int32_t
1.318 +uprv_compareInvEbcdic(const UDataSwapper *ds,
1.319 + const char *outString, int32_t outLength,
1.320 + const UChar *localString, int32_t localLength);
1.321 +
1.322 +/* material... -------------------------------------------------------------- */
1.323 +
1.324 +#if 0
1.325 +
1.326 +/* udata.h */
1.327 +
1.328 +/**
1.329 + * Public API function in udata.c
1.330 + *
1.331 + * Same as udata_openChoice() but automatically swaps the data.
1.332 + * isAcceptable, if not NULL, may accept data with endianness and charset family
1.333 + * different from the current platform's properties.
1.334 + * If the data is acceptable and the platform properties do not match, then
1.335 + * the swap function is called to swap an allocated version of the data.
1.336 + * Preflighting may or may not be performed depending on whether the size of
1.337 + * the loaded data item is known.
1.338 + *
1.339 + * @param isAcceptable Same as for udata_openChoice(). May be NULL.
1.340 + *
1.341 + * @internal ICU 2.8
1.342 + */
1.343 +U_CAPI UDataMemory * U_EXPORT2
1.344 +udata_openSwap(const char *path, const char *type, const char *name,
1.345 + UDataMemoryIsAcceptable *isAcceptable, void *isAcceptableContext,
1.346 + UDataSwapFn *swap,
1.347 + UDataPrintError *printError, void *printErrorContext,
1.348 + UErrorCode *pErrorCode);
1.349 +
1.350 +#endif
1.351 +
1.352 +#endif