]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/udata/writer.c
2 *******************************************************************************
4 * Copyright (C) 1999-2000, 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 * A program to write simple binary data readable by udata - example for
20 ******************************************************************************/
30 #include "unicode/utypes.h"
31 #include "unicode/udata.h"
33 /* this is private - available only through toolutil */
36 #define DATA_NAME "mypkg_example"
37 #define DATA_TYPE "dat"
39 /* UDataInfo cf. udata.h */
40 static const UDataInfo dataInfo
={
49 0x4D, 0x79, 0x44, 0x74, /* dataFormat="MyDt" */
50 1, 0, 0, 0, /* formatVersion */
51 1, 0, 0, 0 /* dataVersion */
55 /* Excersise: add writing out other data types */
56 /* see icu/source/tools/toolutil/unewdata.h */
57 /* for other possibilities */
60 main(int argc
, const char *argv
[]) {
61 UNewDataMemory
*pData
;
62 UErrorCode errorCode
=U_ZERO_ERROR
;
63 char stringValue
[]={'E', 'X', 'A', 'M', 'P', 'L', 'E', '\0'};
64 uint16_t intValue
=2000;
69 char *currdir
= _getcwd(NULL
, 0);
71 char *currdir
= getcwd(NULL
, 0);
74 pData
=udata_create(getcwd(NULL
, 0), DATA_TYPE
, DATA_NAME
, &dataInfo
,
75 U_COPYRIGHT_STRING
, &errorCode
);
82 if(U_FAILURE(errorCode
)) {
83 fprintf(stderr
, "Error: unable to create data memory, error %d\n", errorCode
);
87 /* write the data to the file */
88 /* a 16 bit value and a String*/
89 printf("Writing uint16_t value of %d\n", intValue
);
90 udata_write16(pData
, intValue
);
91 printf("Writing string value of %s\n", stringValue
);
92 udata_writeString(pData
, stringValue
, sizeof(stringValue
));
95 dataLength
=udata_finish(pData
, &errorCode
);
96 if(U_FAILURE(errorCode
)) {
97 fprintf(stderr
, "Error: error %d writing the output file\n", errorCode
);
100 size
=sizeof(stringValue
) + sizeof(intValue
);
103 if(dataLength
!=(long)size
) {
104 fprintf(stderr
, "Error: data length %ld != calculated size %lu\n", dataLength
, size
);
105 exit(U_INTERNAL_PROGRAM_ERROR
);