2 *******************************************************************************
4 * Copyright (C) 1999-2004, 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/uclean.h"
24 #include "unicode/udata.h"
31 #define DATA_PKG "testdata"
32 #define DATA_NAME "test"
33 #define DATA_TYPE "icu"
35 /* UDataInfo cf. udata.h */
36 static const UDataInfo dataInfo
={
45 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
46 {1, 0, 0, 0}, /* formatVersion */
47 {1, 0, 0, 0} /* dataVersion */
50 static void createData(const char*, UErrorCode
*);
52 static UOption options
[]={
54 /*1*/ UOPTION_HELP_QUESTION_MARK
,
55 /*2*/ UOPTION_DESTDIR
,
56 /*3*/ UOPTION_DEF("genres", 'r', UOPT_NO_ARG
)
60 main(int argc
, char* argv
[]) {
61 UErrorCode errorCode
= U_ZERO_ERROR
;
63 /* preset then read command line options */
64 options
[2].value
=u_getDataDirectory();
65 argc
=u_parseArgs(argc
, argv
, sizeof(options
)/sizeof(options
[0]), options
);
67 /* error handling, printing usage message */
70 "error in command line argument \"%s\"\n",
73 if(argc
<0 || options
[0].doesOccur
|| options
[1].doesOccur
) {
75 "usage: %s [-options]\n"
76 "\tcreate the test file " DATA_PKG
"_" DATA_NAME
"." DATA_TYPE
" unless the -r option is given.\n"
78 "\t\t-h or -? or --help this usage text\n"
79 "\t\t-d or --destdir destination directory, followed by the path\n"
80 "\t\t-r or --genres generate resource file testtable32.txt instead of UData test \n",
82 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
85 if ( options
[3].doesOccur
) {
86 return genres32( argv
[0], options
[2].value
);
88 /* printf("Generating the test memory mapped file\n"); */
89 createData(options
[2].value
, &errorCode
);
91 return U_FAILURE(errorCode
);
94 /* Create data file ----------------------------------------------------- */
96 createData(const char* outputDirectory
, UErrorCode
*errorCode
) {
97 UNewDataMemory
*pData
;
98 char stringValue
[]={'Y', 'E', 'A', 'R', '\0'};
99 uint16_t intValue
=2000;
104 pData
=udata_create(outputDirectory
, DATA_TYPE
, DATA_PKG
"_" DATA_NAME
, &dataInfo
,
105 U_COPYRIGHT_STRING
, errorCode
);
106 if(U_FAILURE(*errorCode
)) {
107 fprintf(stderr
, "gentest: unable to create data memory, error %d\n", *errorCode
);
111 /* write the data to the file */
112 /* a 16 bit value and a String*/
113 udata_write16(pData
, intValue
);
114 udata_writeString(pData
, stringValue
, sizeof(stringValue
));
117 dataLength
=udata_finish(pData
, errorCode
);
118 if(U_FAILURE(*errorCode
)) {
119 fprintf(stderr
, "gentest: error %d writing the output file\n", *errorCode
);
122 size
=sizeof(stringValue
) + sizeof(intValue
);
125 if(dataLength
!=(long)size
) {
126 fprintf(stderr
, "gentest: data length %ld != calculated size %lu\n",
127 dataLength
, (unsigned long)size
);
128 exit(U_INTERNAL_PROGRAM_ERROR
);