2 *******************************************************************************
4 * Copyright (C) 1999-2006, 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_NAME "test"
32 #define DATA_TYPE "icu"
34 /* UDataInfo cf. udata.h */
35 static const UDataInfo dataInfo
={
44 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
45 {1, 0, 0, 0}, /* formatVersion */
46 {1, 0, 0, 0} /* dataVersion */
49 static void createData(const char*, UErrorCode
*);
51 static UOption options
[]={
53 /*1*/ UOPTION_HELP_QUESTION_MARK
,
54 /*2*/ UOPTION_DESTDIR
,
55 /*3*/ UOPTION_DEF("genres", 'r', UOPT_NO_ARG
)
59 main(int argc
, char* argv
[]) {
60 UErrorCode errorCode
= U_ZERO_ERROR
;
62 /* preset then read command line options */
63 options
[2].value
=u_getDataDirectory();
64 argc
=u_parseArgs(argc
, argv
, sizeof(options
)/sizeof(options
[0]), options
);
66 /* error handling, printing usage message */
69 "error in command line argument \"%s\"\n",
72 if(argc
<0 || options
[0].doesOccur
|| options
[1].doesOccur
) {
74 "usage: %s [-options]\n"
75 "\tcreate the test file " DATA_NAME
"." DATA_TYPE
" unless the -r option is given.\n"
77 "\t\t-h or -? or --help this usage text\n"
78 "\t\t-d or --destdir destination directory, followed by the path\n"
79 "\t\t-r or --genres generate resource file testtable32.txt instead of UData test \n",
81 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
84 if ( options
[3].doesOccur
) {
85 return genres32( argv
[0], options
[2].value
);
87 /* printf("Generating the test memory mapped file\n"); */
88 createData(options
[2].value
, &errorCode
);
90 return U_FAILURE(errorCode
);
93 /* Create data file ----------------------------------------------------- */
95 createData(const char* outputDirectory
, UErrorCode
*errorCode
) {
96 UNewDataMemory
*pData
;
97 char stringValue
[]={'Y', 'E', 'A', 'R', '\0'};
98 uint16_t intValue
=2000;
103 pData
=udata_create(outputDirectory
, DATA_TYPE
, DATA_NAME
, &dataInfo
,
104 U_COPYRIGHT_STRING
, errorCode
);
105 if(U_FAILURE(*errorCode
)) {
106 fprintf(stderr
, "gentest: unable to create data memory, error %d\n", *errorCode
);
110 /* write the data to the file */
111 /* a 16 bit value and a String*/
112 udata_write16(pData
, intValue
);
113 udata_writeString(pData
, stringValue
, sizeof(stringValue
));
116 dataLength
=udata_finish(pData
, errorCode
);
117 if(U_FAILURE(*errorCode
)) {
118 fprintf(stderr
, "gentest: error %d writing the output file\n", *errorCode
);
121 size
=sizeof(stringValue
) + sizeof(intValue
);
124 if(dataLength
!=(long)size
) {
125 fprintf(stderr
, "gentest: data length %ld != calculated size %lu\n",
126 dataLength
, (unsigned long)size
);
127 exit(U_INTERNAL_PROGRAM_ERROR
);