2 *******************************************************************************
4 * Copyright (C) 1999-2010, 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"
33 #define DATA_NAME "test"
34 #define DATA_TYPE "icu"
36 /* UDataInfo cf. udata.h */
37 static const UDataInfo dataInfo
={
46 {0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
47 {1, 0, 0, 0}, /* formatVersion */
48 {1, 0, 0, 0} /* dataVersion */
51 static void createData(const char*, UErrorCode
*);
53 static int outputJavaStuff(const char * progname
, const char *outputDir
);
55 static UOption options
[]={
57 /*1*/ UOPTION_HELP_QUESTION_MARK
,
58 /*2*/ UOPTION_DESTDIR
,
59 /*3*/ UOPTION_DEF("genres", 'r', UOPT_NO_ARG
),
60 /*4*/ UOPTION_DEF("javastuff", 'j', UOPT_NO_ARG
),
64 main(int argc
, char* argv
[]) {
65 UErrorCode errorCode
= U_ZERO_ERROR
;
67 /* preset then read command line options */
68 options
[2].value
=u_getDataDirectory();
69 argc
=u_parseArgs(argc
, argv
, sizeof(options
)/sizeof(options
[0]), options
);
71 /* error handling, printing usage message */
74 "error in command line argument \"%s\"\n",
77 if(argc
<0 || options
[0].doesOccur
|| options
[1].doesOccur
) {
79 "usage: %s [-options]\n"
80 "\tcreate the test file " DATA_NAME
"." DATA_TYPE
" unless the -r option is given.\n"
82 "\t\t-h or -? or --help this usage text\n"
83 "\t\t-d or --destdir destination directory, followed by the path\n"
84 "\t\t-r or --genres generate resource file testtable32.txt instead of UData test \n"
85 "\t\t-j or --javastuff generate Java source for DebugUtilities. \n",
87 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
90 if( options
[4].doesOccur
) {
91 return outputJavaStuff( argv
[0], options
[2].value
);
92 } else if ( options
[3].doesOccur
) {
93 return genres32( argv
[0], options
[2].value
);
95 /* printf("Generating the test memory mapped file\n"); */
96 createData(options
[2].value
, &errorCode
);
98 return U_FAILURE(errorCode
);
101 /* Create data file ----------------------------------------------------- */
103 createData(const char* outputDirectory
, UErrorCode
*errorCode
) {
104 UNewDataMemory
*pData
;
105 char stringValue
[]={'Y', 'E', 'A', 'R', '\0'};
106 uint16_t intValue
=2000;
111 pData
=udata_create(outputDirectory
, DATA_TYPE
, DATA_NAME
, &dataInfo
,
112 U_COPYRIGHT_STRING
, errorCode
);
113 if(U_FAILURE(*errorCode
)) {
114 fprintf(stderr
, "gentest: unable to create data memory, %s\n", u_errorName(*errorCode
));
118 /* write the data to the file */
119 /* a 16 bit value and a String*/
120 udata_write16(pData
, intValue
);
121 udata_writeString(pData
, stringValue
, sizeof(stringValue
));
124 dataLength
=udata_finish(pData
, errorCode
);
125 if(U_FAILURE(*errorCode
)) {
126 fprintf(stderr
, "gentest: error %d writing the output file\n", *errorCode
);
129 size
=sizeof(stringValue
) + sizeof(intValue
);
132 if(dataLength
!=(long)size
) {
133 fprintf(stderr
, "gentest: data length %ld != calculated size %lu\n",
134 dataLength
, (unsigned long)size
);
135 exit(U_INTERNAL_PROGRAM_ERROR
);
139 /* Create Java file ----------------------------------------------------- */
142 outputJavaStuff(const char* progname
, const char *outputDir
) {
146 int32_t year
= getCurrentYear();
148 uprv_strcpy(file
,outputDir
);
149 if(*outputDir
&& /* don't put a trailing slash if outputDir is empty */
150 file
[strlen(file
)-1]!=U_FILE_SEP_CHAR
) {
151 uprv_strcat(file
,U_FILE_SEP_STRING
);
153 uprv_strcat(file
,"DebugUtilitiesData.java");
154 out
= fopen(file
, "w");
156 printf("%s: Generating %s\n", progname
, file
);
158 fprintf(stderr
, "%s: Couldn't create resource test file %s\n",
163 fprintf(out
, "/** Copyright (C) 2007-%d, International Business Machines Corporation and Others. All Rights Reserved. **/\n\n", year
);
164 fprintf(out
, "/* NOTE: this file is AUTOMATICALLY GENERATED by gentest.\n"
165 " * See: {ICU4C}/source/data/icu4j-readme.txt for more information. \n"
167 fprintf(out
, "package com.ibm.icu.dev.test.util;\n\n");
168 fprintf(out
, "public class DebugUtilitiesData extends Object {\n");
169 fprintf(out
, " public static final String ICU4C_VERSION=\"%s\";\n", U_ICU_VERSION
);
170 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
171 fprintf(out
, " public static final int %s = %d;\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
173 fprintf(out
, " public static final String [] TYPES = { \n");
174 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
175 fprintf(out
, " \"%s\", /* %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
177 fprintf(out
, " };\n\n");
179 fprintf(out
, " public static final String [][] NAMES = { \n");
180 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
181 count
= udbg_enumCount((UDebugEnumType
)t
);
182 fprintf(out
, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
183 fprintf(out
, " { \n");
184 for(i
=0;i
<count
;i
++) {
186 " \"%s\", /* %d */ \n", udbg_enumName((UDebugEnumType
)t
,i
), i
);
188 fprintf(out
, " },\n");
190 fprintf(out
, " };\n\n");
192 fprintf(out
, " public static final int [][] VALUES = { \n");
193 for(t
=0;t
<UDBG_ENUM_COUNT
;t
++) {
194 count
= udbg_enumCount((UDebugEnumType
)t
);
195 fprintf(out
, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType
,t
), t
);
196 fprintf(out
, " { \n");
197 for(i
=0;i
<count
;i
++) {
201 #if !UCONFIG_NO_FORMATTING
202 case UDBG_UCalendarDateFields
:
203 case UDBG_UCalendarMonths
:
204 /* Temporary workaround for IS_LEAP_MONTH #6051 */
205 if (t
== UDBG_UCalendarDateFields
&& i
== 22) {
206 fprintf(out
, "com.ibm.icu.util.ChineseCalendar.%s, /* %d */", udbg_enumName((UDebugEnumType
)t
,i
), i
);
208 fprintf(out
, "com.ibm.icu.util.Calendar.%s, /* %d */", udbg_enumName((UDebugEnumType
)t
,i
), i
);
212 case UDBG_UDebugEnumType
:
214 fprintf(out
,"%d, /* %s */", i
, udbg_enumName((UDebugEnumType
)t
,i
));
218 fprintf(out
, " },\n");
220 fprintf(out
, " };\n\n");