1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 1999-2009, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 * file name: reader.c
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2000sep5
14 * created by: Vladimir Weinstein
15 */
16
17 /*******************************************************************************
18 * Derived from Madhu Katragadda gentest
19 *******************************************************************************/
20
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #ifdef WIN32
26 #include <direct.h>
27 #else
28 #include <unistd.h>
29 #endif
30 #include "unicode/utypes.h"
31 #include "unicode/putil.h"
32 #include "unicode/udata.h"
33
34 #define DATA_NAME "mypkg_example"
35 #define DATA_TYPE "dat"
36
37 /* UDataInfo cf. udata.h */
38 static const UDataInfo dataInfo={
39 sizeof(UDataInfo),
40 0,
41
42 U_IS_BIG_ENDIAN,
43 U_CHARSET_FAMILY,
44 sizeof(UChar),
45 0,
46
47 0x4D, 0x79, 0x44, 0x74, /* dataFormat="MyDt" */
48 1, 0, 0, 0, /* formatVersion */
49 1, 0, 0, 0 /* dataVersion */
50 };
51
52 static UBool
isAcceptable(void * context,const char * type,const char * name,const UDataInfo * pInfo)53 isAcceptable(void *context,
54 const char *type, const char *name,
55 const UDataInfo *pInfo){
56
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 ) {
66 return TRUE;
67 } else {
68 return FALSE;
69 }
70
71
72 }
73
74 extern int
main(int argc,const char * argv[])75 main(int argc, const char *argv[]) {
76 UDataMemory *result = NULL;
77 UErrorCode status=U_ZERO_ERROR;
78
79 uint16_t intValue = 0;
80
81 char *string = NULL;
82 uint16_t *intPointer = NULL;
83
84 const void *dataMemory = NULL;
85 char curPathBuffer[1024];
86
87 #ifdef WIN32
88 char *currdir = _getcwd(NULL, 0);
89 #else
90 char *currdir = getcwd(NULL, 0);
91 #endif
92
93 /* need to put "current/dir" as path */
94 strcpy(curPathBuffer, currdir);
95
96 result=udata_openChoice(curPathBuffer, DATA_TYPE, DATA_NAME, isAcceptable, NULL, &status);
97
98 if(currdir != NULL) {
99 free(currdir);
100 }
101
102 if(U_FAILURE(status)){
103 printf("Failed to open data file example.dat in %s with error number %d\n", curPathBuffer, status);
104 return -1;
105 }
106
107 dataMemory = udata_getMemory(result);
108
109 intPointer = (uint16_t *)dataMemory;
110
111 printf("Read value %d from data file\n", *intPointer);
112
113 string = (char *) (intPointer+1);
114
115 printf("Read string %s from data file\n", string);
116
117 if(U_SUCCESS(status)){
118 udata_close(result);
119 }
120
121 return 0;
122 }
123
124
125
126
127
128
129
130