]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/udata/reader.c
2 *******************************************************************************
4 * Copyright (C) 1999-2009, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 2000sep5
14 * created by: Vladimir Weinstein
17 /*******************************************************************************
18 * Derived from Madhu Katragadda gentest
19 *******************************************************************************/
30 #include "unicode/utypes.h"
31 #include "unicode/putil.h"
32 #include "unicode/udata.h"
34 #define DATA_NAME "mypkg_example"
35 #define DATA_TYPE "dat"
37 /* UDataInfo cf. udata.h */
38 static const UDataInfo dataInfo
={
47 0x4D, 0x79, 0x44, 0x74, /* dataFormat="MyDt" */
48 1, 0, 0, 0, /* formatVersion */
49 1, 0, 0, 0 /* dataVersion */
53 isAcceptable(void *context
,
54 const char *type
, const char *name
,
55 const UDataInfo
*pInfo
){
57 if( pInfo
->size
>=20 &&
58 pInfo
->isBigEndian
==U_IS_BIG_ENDIAN
&&
59 pInfo
->charsetFamily
==U_CHARSET_FAMILY
&&
60 pInfo
->dataFormat
[0]==0x4D && /* dataFormat="MyDt" */
61 pInfo
->dataFormat
[1]==0x79 &&
62 pInfo
->dataFormat
[2]==0x44 &&
63 pInfo
->dataFormat
[3]==0x74 &&
64 pInfo
->formatVersion
[0]==1 &&
65 pInfo
->dataVersion
[0]==1 ) {
75 main(int argc
, const char *argv
[]) {
76 UDataMemory
*result
= NULL
;
77 UErrorCode status
=U_ZERO_ERROR
;
79 uint16_t intValue
= 0;
82 uint16_t *intPointer
= NULL
;
84 const void *dataMemory
= NULL
;
85 char curPathBuffer
[1024];
88 char *currdir
= _getcwd(NULL
, 0);
90 char *currdir
= getcwd(NULL
, 0);
93 /* need to put "current/dir" as path */
94 strcpy(curPathBuffer
, currdir
);
96 result
=udata_openChoice(curPathBuffer
, DATA_TYPE
, DATA_NAME
, isAcceptable
, NULL
, &status
);
102 if(U_FAILURE(status
)){
103 printf("Failed to open data file example.dat in %s with error number %d\n", curPathBuffer
, status
);
107 dataMemory
= udata_getMemory(result
);
109 intPointer
= (uint16_t *)dataMemory
;
111 printf("Read value %d from data file\n", *intPointer
);
113 string
= (char *) (intPointer
+1);
115 printf("Read string %s from data file\n", string
);
117 if(U_SUCCESS(status
)){