]> git.saurik.com Git - apple/icu.git/blame - icuSources/samples/udata/reader.c
ICU-6.2.13.tar.gz
[apple/icu.git] / icuSources / samples / udata / reader.c
CommitLineData
b75a7d8f 1/*
374ca955
A
2 *******************************************************************************
3 *
4 * Copyright (C) 1999-2004, 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 */
b75a7d8f
A
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"
374ca955 31#include "unicode/putil.h"
b75a7d8f
A
32#include "unicode/udata.h"
33
34#define DATA_NAME "example"
35#define DATA_TYPE "dat"
36
37/* UDataInfo cf. udata.h */
38static 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
52static UBool
53isAcceptable(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
74extern int
75main(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/pkgname" as path */
94 strcpy(curPathBuffer, currdir);
95 strcat(curPathBuffer, U_FILE_SEP_STRING);
96 strcat(curPathBuffer, "mypkg"); /* package name */
97
98 result=udata_openChoice(curPathBuffer, DATA_TYPE, DATA_NAME, isAcceptable, NULL, &status);
99
100 if(currdir != NULL) {
101 free(currdir);
102 }
103
104 if(U_FAILURE(status)){
105 printf("Failed to open data file example.dat in %s with error number %d\n", curPathBuffer, status);
106 return -1;
107 }
108
109 dataMemory = udata_getMemory(result);
110
111 intPointer = (uint16_t *)dataMemory;
112
113 printf("Read value %d from data file\n", *intPointer);
114
115 string = (char *) (intPointer+1);
116
117 printf("Read string %s from data file\n", string);
118
119 if(U_SUCCESS(status)){
120 udata_close(result);
121 }
122
123 return 0;
124}
125
126
127
128
129
130
131