2000-03-07 00:05:54 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2001-03-21 23:22:16 +00:00
|
|
|
* Copyright (C) 1999-2001, 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"
|
2000-03-03 01:09:33 +00:00
|
|
|
#include "unicode/udata.h"
|
|
|
|
#include "unewdata.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2000-04-18 21:55:53 +00:00
|
|
|
#include "uoptions.h"
|
2000-03-03 01:09:33 +00:00
|
|
|
|
|
|
|
#define DATA_NAME "test"
|
|
|
|
#define DATA_TYPE "dat"
|
|
|
|
|
|
|
|
/* 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
|
|
|
};
|
|
|
|
|
2000-03-27 21:00:28 +00:00
|
|
|
static void createData(const char*);
|
2000-03-03 01:09:33 +00:00
|
|
|
|
2000-04-18 21:55:53 +00:00
|
|
|
static UOption options[]={
|
|
|
|
UOPTION_HELP_H,
|
|
|
|
UOPTION_HELP_QUESTION_MARK,
|
|
|
|
UOPTION_DESTDIR
|
|
|
|
};
|
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[]) {
|
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"
|
|
|
|
"\tcreate the test file " DATA_NAME "." DATA_TYPE "\n"
|
|
|
|
"\toptions:\n"
|
|
|
|
"\t\t-h or -? or --help this usage text\n"
|
|
|
|
"\t\t-d or --destdir destination directory, followed by the path\n",
|
|
|
|
argv[0]);
|
|
|
|
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
2000-03-03 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
2002-01-04 23:48:46 +00:00
|
|
|
/* printf("Generating the test memory mapped file\n"); */
|
2000-04-18 21:55:53 +00:00
|
|
|
createData(options[2].value);
|
2000-03-03 01:09:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create data file ----------------------------------------------------- */
|
|
|
|
static void
|
2000-03-03 23:20:14 +00:00
|
|
|
createData(const char* outputDirectory) {
|
2000-03-03 01:09:33 +00:00
|
|
|
UNewDataMemory *pData;
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
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
|
|
|
|
2000-03-07 00:05:54 +00:00
|
|
|
pData=udata_create(outputDirectory, DATA_TYPE, DATA_NAME, &dataInfo,
|
2000-04-18 21:55:53 +00:00
|
|
|
U_COPYRIGHT_STRING, &errorCode);
|
2000-03-03 01:09:33 +00:00
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
fprintf(stderr, "gentest: unable to create data memory, error %d\n", errorCode);
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
dataLength=udata_finish(pData, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
fprintf(stderr, "gentest: error %d writing the output file\n", errorCode);
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|