2000-03-07 00:05:54 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2010-02-02 21:49:58 +00:00
|
|
|
* Copyright (C) 1999-2010, International Business Machines
|
2000-03-07 00:05:54 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
2000-03-27 21:00:28 +00:00
|
|
|
* file name: gentest.c
|
2000-03-07 00:05:54 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2000mar03
|
|
|
|
* created by: Madhu Katragadda
|
|
|
|
*
|
|
|
|
* This program writes a little data file for testing the udata API.
|
|
|
|
*/
|
|
|
|
|
2000-03-03 01:09:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "unicode/utypes.h"
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-08-14 21:34:54 +00:00
|
|
|
#include "unicode/uclean.h"
|
2000-03-03 01:09:33 +00:00
|
|
|
#include "unicode/udata.h"
|
2010-05-12 17:56:02 +00:00
|
|
|
#include "udbgutil.h"
|
2000-03-03 01:09:33 +00:00
|
|
|
#include "unewdata.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2000-04-18 21:55:53 +00:00
|
|
|
#include "uoptions.h"
|
2003-12-05 22:41:54 +00:00
|
|
|
#include "gentest.h"
|
2008-05-21 00:12:48 +00:00
|
|
|
#include "toolutil.h"
|
2000-03-03 01:09:33 +00:00
|
|
|
|
|
|
|
#define DATA_NAME "test"
|
2002-07-17 19:23:26 +00:00
|
|
|
#define DATA_TYPE "icu"
|
2000-03-03 01:09:33 +00:00
|
|
|
|
|
|
|
/* UDataInfo cf. udata.h */
|
|
|
|
static const UDataInfo dataInfo={
|
|
|
|
sizeof(UDataInfo),
|
|
|
|
0,
|
|
|
|
|
|
|
|
U_IS_BIG_ENDIAN,
|
|
|
|
U_CHARSET_FAMILY,
|
|
|
|
sizeof(UChar),
|
|
|
|
0,
|
|
|
|
|
2001-03-26 20:43:03 +00:00
|
|
|
{0x54, 0x65, 0x73, 0x74}, /* dataFormat="Test" */
|
|
|
|
{1, 0, 0, 0}, /* formatVersion */
|
|
|
|
{1, 0, 0, 0} /* dataVersion */
|
2000-03-03 01:09:33 +00:00
|
|
|
};
|
|
|
|
|
2003-12-05 22:41:54 +00:00
|
|
|
static void createData(const char*, UErrorCode *);
|
2000-03-03 01:09:33 +00:00
|
|
|
|
2007-07-12 23:57:26 +00:00
|
|
|
static int outputJavaStuff(const char * progname, const char *outputDir);
|
|
|
|
|
2000-04-18 21:55:53 +00:00
|
|
|
static UOption options[]={
|
2003-09-25 00:15:04 +00:00
|
|
|
/*0*/ UOPTION_HELP_H,
|
|
|
|
/*1*/ UOPTION_HELP_QUESTION_MARK,
|
|
|
|
/*2*/ UOPTION_DESTDIR,
|
2007-07-12 23:57:26 +00:00
|
|
|
/*3*/ UOPTION_DEF("genres", 'r', UOPT_NO_ARG),
|
|
|
|
/*4*/ UOPTION_DEF("javastuff", 'j', UOPT_NO_ARG),
|
2000-04-18 21:55:53 +00:00
|
|
|
};
|
2000-03-03 23:20:14 +00:00
|
|
|
|
2000-04-18 21:55:53 +00:00
|
|
|
extern int
|
2000-09-21 21:49:32 +00:00
|
|
|
main(int argc, char* argv[]) {
|
2003-08-14 21:34:54 +00:00
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
|
2000-04-18 21:55:53 +00:00
|
|
|
/* preset then read command line options */
|
|
|
|
options[2].value=u_getDataDirectory();
|
|
|
|
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
|
|
|
|
|
|
|
/* error handling, printing usage message */
|
|
|
|
if(argc<0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"error in command line argument \"%s\"\n",
|
|
|
|
argv[-argc]);
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
2000-04-18 21:55:53 +00:00
|
|
|
if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s [-options]\n"
|
2006-02-24 19:47:47 +00:00
|
|
|
"\tcreate the test file " DATA_NAME "." DATA_TYPE " unless the -r option is given.\n"
|
2000-04-18 21:55:53 +00:00
|
|
|
"\toptions:\n"
|
|
|
|
"\t\t-h or -? or --help this usage text\n"
|
2003-09-25 00:15:04 +00:00
|
|
|
"\t\t-d or --destdir destination directory, followed by the path\n"
|
2007-07-19 00:19:21 +00:00
|
|
|
"\t\t-r or --genres generate resource file testtable32.txt instead of UData test \n"
|
2007-07-12 23:57:26 +00:00
|
|
|
"\t\t-j or --javastuff generate Java source for DebugUtilities. \n",
|
2000-04-18 21:55:53 +00:00
|
|
|
argv[0]);
|
|
|
|
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 23:57:26 +00:00
|
|
|
if( options[4].doesOccur ) {
|
|
|
|
return outputJavaStuff( argv[0], options[2].value );
|
|
|
|
} else if ( options[3].doesOccur ) {
|
2003-12-05 22:41:54 +00:00
|
|
|
return genres32( argv[0], options[2].value );
|
2003-09-25 00:15:04 +00:00
|
|
|
} else {
|
2003-12-05 22:41:54 +00:00
|
|
|
/* printf("Generating the test memory mapped file\n"); */
|
|
|
|
createData(options[2].value, &errorCode);
|
2003-09-25 00:15:04 +00:00
|
|
|
}
|
2003-12-05 22:41:54 +00:00
|
|
|
return U_FAILURE(errorCode);
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create data file ----------------------------------------------------- */
|
|
|
|
static void
|
2003-12-05 22:41:54 +00:00
|
|
|
createData(const char* outputDirectory, UErrorCode *errorCode) {
|
2000-03-03 01:09:33 +00:00
|
|
|
UNewDataMemory *pData;
|
2000-03-07 00:05:54 +00:00
|
|
|
char stringValue[]={'Y', 'E', 'A', 'R', '\0'};
|
2000-03-03 01:09:33 +00:00
|
|
|
uint16_t intValue=2000;
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2000-03-03 01:09:33 +00:00
|
|
|
long dataLength;
|
2000-03-07 00:05:54 +00:00
|
|
|
uint32_t size;
|
2000-03-03 01:09:33 +00:00
|
|
|
|
2006-02-24 19:47:47 +00:00
|
|
|
pData=udata_create(outputDirectory, DATA_TYPE, DATA_NAME, &dataInfo,
|
2003-12-05 22:41:54 +00:00
|
|
|
U_COPYRIGHT_STRING, errorCode);
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
2009-07-18 02:35:27 +00:00
|
|
|
fprintf(stderr, "gentest: unable to create data memory, %s\n", u_errorName(*errorCode));
|
2003-12-05 22:41:54 +00:00
|
|
|
exit(*errorCode);
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write the data to the file */
|
|
|
|
/* a 16 bit value and a String*/
|
2000-03-07 00:05:54 +00:00
|
|
|
udata_write16(pData, intValue);
|
|
|
|
udata_writeString(pData, stringValue, sizeof(stringValue));
|
2000-03-03 01:09:33 +00:00
|
|
|
|
|
|
|
/* finish up */
|
2003-12-05 22:41:54 +00:00
|
|
|
dataLength=udata_finish(pData, errorCode);
|
|
|
|
if(U_FAILURE(*errorCode)) {
|
|
|
|
fprintf(stderr, "gentest: error %d writing the output file\n", *errorCode);
|
|
|
|
exit(*errorCode);
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
|
|
|
size=sizeof(stringValue) + sizeof(intValue);
|
|
|
|
|
|
|
|
|
|
|
|
if(dataLength!=(long)size) {
|
2001-03-27 19:19:53 +00:00
|
|
|
fprintf(stderr, "gentest: data length %ld != calculated size %lu\n",
|
|
|
|
dataLength, (unsigned long)size);
|
2000-03-03 01:09:33 +00:00
|
|
|
exit(U_INTERNAL_PROGRAM_ERROR);
|
|
|
|
}
|
2000-03-07 00:05:54 +00:00
|
|
|
}
|
2007-07-12 23:57:26 +00:00
|
|
|
|
|
|
|
/* Create Java file ----------------------------------------------------- */
|
|
|
|
|
|
|
|
static int
|
|
|
|
outputJavaStuff(const char* progname, const char *outputDir) {
|
2007-07-19 00:19:21 +00:00
|
|
|
int32_t i,t,count;
|
2007-07-12 23:57:26 +00:00
|
|
|
char file[512];
|
|
|
|
FILE *out;
|
2008-05-21 00:12:48 +00:00
|
|
|
int32_t year = getCurrentYear();
|
2007-07-12 23:57:26 +00:00
|
|
|
|
|
|
|
uprv_strcpy(file,outputDir);
|
|
|
|
if(*outputDir && /* don't put a trailing slash if outputDir is empty */
|
2007-07-19 00:19:21 +00:00
|
|
|
file[strlen(file)-1]!=U_FILE_SEP_CHAR) {
|
|
|
|
uprv_strcat(file,U_FILE_SEP_STRING);
|
2007-07-12 23:57:26 +00:00
|
|
|
}
|
|
|
|
uprv_strcat(file,"DebugUtilitiesData.java");
|
|
|
|
out = fopen(file, "w");
|
|
|
|
/*puts(file);*/
|
|
|
|
printf("%s: Generating %s\n", progname, file);
|
|
|
|
if(out == NULL) {
|
|
|
|
fprintf(stderr, "%s: Couldn't create resource test file %s\n",
|
2007-07-19 00:19:21 +00:00
|
|
|
progname, file);
|
2007-07-12 23:57:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-07-19 00:19:21 +00:00
|
|
|
|
2010-02-02 21:49:58 +00:00
|
|
|
fprintf(out, "/** Copyright (C) 2007-%d, International Business Machines Corporation and Others. All Rights Reserved. **/\n\n", year);
|
|
|
|
fprintf(out, "/* NOTE: this file is AUTOMATICALLY GENERATED by gentest.\n"
|
|
|
|
" * See: {ICU4C}/source/data/icu4j-readme.txt for more information. \n"
|
|
|
|
" **/\n\n");
|
2007-07-19 00:19:21 +00:00
|
|
|
fprintf(out, "package com.ibm.icu.dev.test.util;\n\n");
|
|
|
|
fprintf(out, "public class DebugUtilitiesData extends Object {\n");
|
|
|
|
fprintf(out, " public static final String ICU4C_VERSION=\"%s\";\n", U_ICU_VERSION);
|
|
|
|
for(t=0;t<UDBG_ENUM_COUNT;t++) {
|
|
|
|
fprintf(out, " public static final int %s = %d;\n", udbg_enumName(UDBG_UDebugEnumType,t), t);
|
|
|
|
}
|
|
|
|
fprintf(out, " public static final String [] TYPES = { \n");
|
|
|
|
for(t=0;t<UDBG_ENUM_COUNT;t++) {
|
|
|
|
fprintf(out, " \"%s\", /* %d */\n", udbg_enumName(UDBG_UDebugEnumType,t), t);
|
|
|
|
}
|
|
|
|
fprintf(out, " };\n\n");
|
|
|
|
|
|
|
|
fprintf(out, " public static final String [][] NAMES = { \n");
|
|
|
|
for(t=0;t<UDBG_ENUM_COUNT;t++) {
|
|
|
|
count = udbg_enumCount((UDebugEnumType)t);
|
|
|
|
fprintf(out, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType,t), t);
|
|
|
|
fprintf(out, " { \n");
|
|
|
|
for(i=0;i<count;i++) {
|
|
|
|
fprintf(out,
|
|
|
|
" \"%s\", /* %d */ \n", udbg_enumName((UDebugEnumType)t,i), i);
|
|
|
|
}
|
|
|
|
fprintf(out, " },\n");
|
|
|
|
}
|
|
|
|
fprintf(out, " };\n\n");
|
|
|
|
|
|
|
|
fprintf(out, " public static final int [][] VALUES = { \n");
|
|
|
|
for(t=0;t<UDBG_ENUM_COUNT;t++) {
|
|
|
|
count = udbg_enumCount((UDebugEnumType)t);
|
|
|
|
fprintf(out, " /* %s, %d */\n", udbg_enumName(UDBG_UDebugEnumType,t), t);
|
|
|
|
fprintf(out, " { \n");
|
|
|
|
for(i=0;i<count;i++) {
|
|
|
|
fprintf(out,
|
|
|
|
" ");
|
|
|
|
switch(t) {
|
2009-08-04 21:09:17 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
2007-07-19 00:19:21 +00:00
|
|
|
case UDBG_UCalendarDateFields:
|
|
|
|
case UDBG_UCalendarMonths:
|
2010-02-02 21:49:58 +00:00
|
|
|
/* Temporary workaround for IS_LEAP_MONTH #6051 */
|
2007-12-05 20:22:54 +00:00
|
|
|
if (t == UDBG_UCalendarDateFields && i == 22) {
|
2010-02-02 21:49:58 +00:00
|
|
|
fprintf(out, "com.ibm.icu.util.ChineseCalendar.%s, /* %d */", udbg_enumName((UDebugEnumType)t,i), i);
|
|
|
|
} else {
|
|
|
|
fprintf(out, "com.ibm.icu.util.Calendar.%s, /* %d */", udbg_enumName((UDebugEnumType)t,i), i);
|
|
|
|
}
|
2007-07-19 00:19:21 +00:00
|
|
|
break;
|
2009-08-04 21:09:17 +00:00
|
|
|
#endif
|
2007-07-19 00:19:21 +00:00
|
|
|
case UDBG_UDebugEnumType:
|
|
|
|
default:
|
|
|
|
fprintf(out,"%d, /* %s */", i, udbg_enumName((UDebugEnumType)t,i));
|
|
|
|
}
|
|
|
|
fprintf(out,"\n");
|
|
|
|
}
|
|
|
|
fprintf(out, " },\n");
|
|
|
|
}
|
|
|
|
fprintf(out, " };\n\n");
|
|
|
|
fprintf(out, "}\n");
|
|
|
|
|
|
|
|
fclose(out);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2007-07-12 23:57:26 +00:00
|
|
|
}
|