]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
4 | * Copyright (C) 1999-2000, 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/udata.h" | |
32 | ||
33 | #define DATA_NAME "example" | |
34 | #define DATA_TYPE "dat" | |
35 | ||
36 | /* UDataInfo cf. udata.h */ | |
37 | static const UDataInfo dataInfo={ | |
38 | sizeof(UDataInfo), | |
39 | 0, | |
40 | ||
41 | U_IS_BIG_ENDIAN, | |
42 | U_CHARSET_FAMILY, | |
43 | sizeof(UChar), | |
44 | 0, | |
45 | ||
46 | 0x4D, 0x79, 0x44, 0x74, /* dataFormat="MyDt" */ | |
47 | 1, 0, 0, 0, /* formatVersion */ | |
48 | 1, 0, 0, 0 /* dataVersion */ | |
49 | }; | |
50 | ||
51 | static UBool | |
52 | isAcceptable(void *context, | |
53 | const char *type, const char *name, | |
54 | const UDataInfo *pInfo){ | |
55 | ||
56 | if( pInfo->size>=20 && | |
57 | pInfo->isBigEndian==U_IS_BIG_ENDIAN && | |
58 | pInfo->charsetFamily==U_CHARSET_FAMILY && | |
59 | pInfo->dataFormat[0]==0x4D && /* dataFormat="MyDt" */ | |
60 | pInfo->dataFormat[1]==0x79 && | |
61 | pInfo->dataFormat[2]==0x44 && | |
62 | pInfo->dataFormat[3]==0x74 && | |
63 | pInfo->formatVersion[0]==1 && | |
64 | pInfo->dataVersion[0]==1 ) { | |
65 | return TRUE; | |
66 | } else { | |
67 | return FALSE; | |
68 | } | |
69 | ||
70 | ||
71 | } | |
72 | ||
73 | extern int | |
74 | main(int argc, const char *argv[]) { | |
75 | UDataMemory *result = NULL; | |
76 | UErrorCode status=U_ZERO_ERROR; | |
77 | ||
78 | uint16_t intValue = 0; | |
79 | ||
80 | char *string = NULL; | |
81 | uint16_t *intPointer = NULL; | |
82 | ||
83 | const void *dataMemory = NULL; | |
84 | char curPathBuffer[1024]; | |
85 | ||
86 | #ifdef WIN32 | |
87 | char *currdir = _getcwd(NULL, 0); | |
88 | #else | |
89 | char *currdir = getcwd(NULL, 0); | |
90 | #endif | |
91 | ||
92 | /* need to put "current/dir/pkgname" as path */ | |
93 | strcpy(curPathBuffer, currdir); | |
94 | strcat(curPathBuffer, U_FILE_SEP_STRING); | |
95 | strcat(curPathBuffer, "mypkg"); /* package name */ | |
96 | ||
97 | result=udata_openChoice(curPathBuffer, DATA_TYPE, DATA_NAME, isAcceptable, NULL, &status); | |
98 | ||
99 | if(currdir != NULL) { | |
100 | free(currdir); | |
101 | } | |
102 | ||
103 | if(U_FAILURE(status)){ | |
104 | printf("Failed to open data file example.dat in %s with error number %d\n", curPathBuffer, status); | |
105 | return -1; | |
106 | } | |
107 | ||
108 | dataMemory = udata_getMemory(result); | |
109 | ||
110 | intPointer = (uint16_t *)dataMemory; | |
111 | ||
112 | printf("Read value %d from data file\n", *intPointer); | |
113 | ||
114 | string = (char *) (intPointer+1); | |
115 | ||
116 | printf("Read string %s from data file\n", string); | |
117 | ||
118 | if(U_SUCCESS(status)){ | |
119 | udata_close(result); | |
120 | } | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | ||
126 | ||
127 | ||
128 | ||
129 | ||
130 |