2
*******************************************************************************
4
* Copyright (C) 1999-2001, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
*******************************************************************************
10
* tab size: 8 (not used)
13
* created on: 2000mar03
14
* created by: Madhu Katragadda
16
* This program writes a little data file for testing the udata API.
21
#include "unicode/utypes.h"
22
#include "unicode/putil.h"
23
#include "unicode/udata.h"
29
#define DATA_NAME "test"
30
#define DATA_TYPE "dat"
32
/* UDataInfo cf. udata.h */
33
static const UDataInfo dataInfo={
42
{0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
43
{1, 0, 0, 0}, /* formatVersion */
44
{1, 0, 0, 0} /* dataVersion */
47
static void createData(const char*);
49
static UOption options[]={
51
UOPTION_HELP_QUESTION_MARK,
56
main(int argc, char* argv[]) {
57
/* preset then read command line options */
58
options[2].value=u_getDataDirectory();
59
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
61
/* error handling, printing usage message */
64
"error in command line argument \"%s\"\n",
67
if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
69
"usage: %s [-options]\n"
70
"\tcreate the test file " DATA_NAME "." DATA_TYPE "\n"
72
"\t\t-h or -? or --help this usage text\n"
73
"\t\t-d or --destdir destination directory, followed by the path\n",
75
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
78
/* printf("Generating the test memory mapped file\n"); */
79
createData(options[2].value);
83
/* Create data file ----------------------------------------------------- */
85
createData(const char* outputDirectory) {
86
UNewDataMemory *pData;
87
UErrorCode errorCode=U_ZERO_ERROR;
88
char stringValue[]={'Y', 'E', 'A', 'R', '\0'};
89
uint16_t intValue=2000;
94
pData=udata_create(outputDirectory, DATA_TYPE, DATA_NAME, &dataInfo,
95
U_COPYRIGHT_STRING, &errorCode);
96
if(U_FAILURE(errorCode)) {
97
fprintf(stderr, "gentest: unable to create data memory, error %d\n", errorCode);
101
/* write the data to the file */
102
/* a 16 bit value and a String*/
103
udata_write16(pData, intValue);
104
udata_writeString(pData, stringValue, sizeof(stringValue));
107
dataLength=udata_finish(pData, &errorCode);
108
if(U_FAILURE(errorCode)) {
109
fprintf(stderr, "gentest: error %d writing the output file\n", errorCode);
112
size=sizeof(stringValue) + sizeof(intValue);
115
if(dataLength!=(long)size) {
116
fprintf(stderr, "gentest: data length %ld != calculated size %lu\n",
117
dataLength, (unsigned long)size);
118
exit(U_INTERNAL_PROGRAM_ERROR);