ICU-2899 update with requests form the meeting

X-SVN-Rev: 13489
This commit is contained in:
Ram Viswanadha 2003-10-24 23:07:00 +00:00
parent c74773f5ec
commit ff0a9c0244
2 changed files with 56 additions and 39 deletions

View File

@ -49,12 +49,12 @@ enum
COPYRIGHT,
PACKAGE_NAME,
BUNDLE_NAME,
WRITE_XML,
WRITE_XLIFF,
TOUCHFILE,
STRICT,
NO_BINARY_COLLATION,
/*added by Jing*/
LANGUAGE
LANGUAGE,
};
UOption options[]={
@ -71,7 +71,7 @@ UOption options[]={
UOPTION_COPYRIGHT,
UOPTION_PACKAGE_NAME,
UOPTION_BUNDLE_NAME,
UOPTION_DEF( "write-xml", 'x', UOPT_NO_ARG),
UOPTION_DEF( "write-xliff", 'x', UOPT_OPTIONAL_ARG),
UOPTION_DEF( "touchfile", 't', UOPT_NO_ARG),
UOPTION_DEF( "strict", 'k', UOPT_NO_ARG), /* 14 */
UOPTION_DEF( "noBinaryCollation", 'C', UOPT_NO_ARG),/* 15 */
@ -80,14 +80,14 @@ UOption options[]={
};
static UBool write_java = FALSE;
static UBool write_xml = FALSE;
static UBool write_xliff = FALSE;
static UBool touchfile = FALSE;
static const char* outputEnc ="";
static const char* gPackageName=NULL;
static const char* bundleName=NULL;
/*added by Jing*/
static const char* language = NULL;
static const char* xliffOutputFileName = NULL;
int
main(int argc,
char* argv[])
@ -147,15 +147,15 @@ main(int argc,
"\t defaults to ASCII and \\uXXXX format.\n"
"\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n"
"\t defaults to com.ibm.icu.impl.data\n"
"\t For ICU4C: Package name on output. Specfiying\n"
"\t For ICU4C: Package name for the .res files on output. Specfiying\n"
"\t 'ICUDATA' defaults to the current ICU4C data name.\n");
fprintf(stderr,
"\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n"
"\t defaults to LocaleElements\n"
"\t-x or --write-xml write a XML file for the resource bundle.\n"
"\t-x or --write-xliff write a XLIFF file for the resource bundle. Followed by an optional output file name.\n"
"\t-k or --strict use pedantic parsing of syntax\n"
/*added by Jing*/
"\t-l or --language language code compliant with ISO 639.\n");
"\t-l or --language For XLIFF: language code compliant with ISO 639.\n");
return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
}
@ -230,8 +230,11 @@ main(int argc,
bundleName = options[BUNDLE_NAME].value;
}
if(options[WRITE_XML].doesOccur) {
write_xml = TRUE;
if(options[WRITE_XLIFF].doesOccur) {
write_xliff = TRUE;
if(options[WRITE_XLIFF].value != NULL){
xliffOutputFileName = options[WRITE_XLIFF].value;
}
}
if(options[NO_BINARY_COLLATION].doesOccur) {
@ -422,8 +425,8 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch
}
if(write_java== TRUE){
bundle_write_java(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName),packageName,bundleName,status);
}else if(write_xml ==TRUE){
bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, packageName,status);
}else if(write_xliff ==TRUE){
bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, xliffOutputFileName,status);
}else{
/* Write the data to the file */
bundle_write(data, outputDir, packageName, outputFileName, sizeof(outputFileName), status);

View File

@ -776,7 +776,7 @@ array_write_xml( struct SResource *res, const char* id, const char* language, UE
T_FileStream_write(out, srBundle->fKeys+res->fKey, (int32_t) uprv_strlen(srBundle->fKeys+res->fKey));
T_FileStream_write(out, "\"", 1);
if(res->fComment!=NULL && res->fComment->fChars != NULL){
printComments(res->fComment, sid, FALSE, status);
printComments(res->fComment, srBundle->fKeys+res->fKey, FALSE, status);
printNoteElements(res->fComment, status);
}else{
T_FileStream_write(out,">\n", 2);
@ -847,7 +847,7 @@ intvector_write_xml( struct SResource *res, const char* id, const char* language
T_FileStream_write(out, srBundle->fKeys+res->fKey, (int32_t) uprv_strlen(srBundle->fKeys+res->fKey));
T_FileStream_write(out, "\"", 1);
if(res->fComment!=NULL && res->fComment->fChars != NULL){
printComments(res->fComment, sid, FALSE, status);
printComments(res->fComment, srBundle->fKeys+res->fKey, FALSE, status);
printNoteElements(res->fComment, status);
}else{
T_FileStream_write(out,">\n", 2);
@ -928,7 +928,7 @@ int_write_xml(struct SResource *res, const char* id, const char* language, UErro
T_FileStream_write(out,"\"", 1);
if(res->fComment!=NULL && res->fComment->fChars != NULL){
printComments(res->fComment, sid, TRUE, status);
printComments(res->fComment, srBundle->fKeys+res->fKey, TRUE, status);
}else{
T_FileStream_write(out,">\n", 2);
@ -1007,7 +1007,7 @@ bin_write_xml( struct SResource *res, const char* id, const char* language, UErr
T_FileStream_write(out, m_type, (int32_t)uprv_strlen(m_type));
if(!(res->fKey<0 || uprv_strcmp(srBundle->fKeys+res->fKey ,"")==0)){
T_FileStream_write(out, key, (int32_t)uprv_strlen(key));
T_FileStream_write(out, sid, (int32_t) uprv_strlen(srBundle->fKeys+res->fKey));
T_FileStream_write(out, srBundle->fKeys+res->fKey, (int32_t) uprv_strlen(srBundle->fKeys+res->fKey));
}
T_FileStream_write(out,"\"", 1);
tabCount++;
@ -1163,7 +1163,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr
T_FileStream_write(out, "\" ", 2);
if(res->fComment!=NULL && res->fComment->fChars != NULL){
printComments(res->fComment, sid, FALSE, status);
printComments(res->fComment, srBundle->fKeys+res->fKey, FALSE, status);
printNoteElements(res->fComment, status);
}else{
T_FileStream_write(out,">\n", 2);
@ -1205,7 +1205,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr
T_FileStream_write(out, srBundle->fKeys+res->fKey, (int32_t) uprv_strlen(srBundle->fKeys+res->fKey));
if(res->fComment!=NULL && res->fComment->fChars != NULL){
printComments(res->fComment, sid, FALSE, status);
printComments(res->fComment, srBundle->fKeys+res->fKey, FALSE, status);
printNoteElements(res->fComment, status);
}else{
T_FileStream_write(out,">\n", 2);
@ -1262,7 +1262,7 @@ res_write_xml(struct SResource *res, const char* id, const char* language, UErro
void
bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* filename,
char *writtenFilename, int writtenFilenameLen,
const char* language, const char* package, UErrorCode *status) {
const char* language, const char* outFileName, UErrorCode *status) {
char* xmlfileName = NULL;
char* outputFileName = NULL;
@ -1278,7 +1278,7 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
const char* headerEnd = "</header>\n";
const char* bodyStart = "<body>\n";
const char* bodyEnd = "</body>\n";
const char* defaultLang = "en";
char* pid = NULL;
char* temp = NULL;
char* lang = NULL;
@ -1318,9 +1318,29 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
if (language == NULL) {
lang = parseFilename(filename, lang);
if (lang == NULL) {
lang = uprv_malloc(sizeof(char)*uprv_strlen(defaultLang) +1);
uprv_memset(lang, 0, sizeof(char)*uprv_strlen(defaultLang) +1);
uprv_strcpy(lang, defaultLang);
/* now check if locale name is valid or not
* this is to cater for situation where
* pegasusServer.txt contains
*
* en{
* ..
* }
*/
lang = parseFilename(srBundle->fLocale, lang);
/*
* Neither the file name nor the table name inside the
* txt file contain a valid country and language codes
* throw an error.
* pegasusServer.txt contains
*
* testelements{
* ....
* }
*/
if(lang==NULL){
fprintf(stderr, "Error: The file name and table name do not contain a valid language code. Please use -l option to specify it.\n");
exit(U_ILLEGAL_ARGUMENT_ERROR);
}
}
} else {
lang = uprv_malloc(sizeof(char)*uprv_strlen(language) +1);
@ -1328,10 +1348,10 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
uprv_strcpy(lang, language);
}
if(package) {
outputFileName = uprv_malloc(sizeof(char)*uprv_strlen(package) + 1);
uprv_memset(outputFileName, 0, sizeof(char)*uprv_strlen(package) + 1);
uprv_strcpy(outputFileName,package);
if(outFileName) {
outputFileName = uprv_malloc(sizeof(char)*uprv_strlen(outFileName) + 1);
uprv_memset(outputFileName, 0, sizeof(char)*uprv_strlen(outFileName) + 1);
uprv_strcpy(outputFileName,outFileName);
} else {
outputFileName = uprv_malloc(sizeof(char)*uprv_strlen(srBundle->fLocale) + 1);
uprv_memset(outputFileName, 0, sizeof(char)*uprv_strlen(srBundle->fLocale) + 1);
@ -1382,6 +1402,10 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
T_FileStream_write(out,bundleStart,uprv_strlen(bundleStart));
write_tabs(out);
T_FileStream_write(out, fileStart, uprv_strlen(fileStart));
/* check if lang and language are the same */
if(language != NULL && uprv_strcmp(lang, srBundle->fLocale)!=0){
fprintf(stderr,"Warning: The top level tag in the resource and language specified are not the same. Please check the input.\n");
}
T_FileStream_write(out,lang,uprv_strlen(lang));
T_FileStream_write(out,file1, uprv_strlen(file1));
T_FileStream_write(out,file2, uprv_strlen(file2));
@ -1393,10 +1417,6 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%dT%H:%M:%SZ", gmtime(&currTime));
T_FileStream_write(out,timeBuf, uprv_strlen(timeBuf));
if(package) {
T_FileStream_write(out,file5, uprv_strlen(file5));
T_FileStream_write(out,package, uprv_strlen(package));
}
T_FileStream_write(out,"\">\n", 3);
tabCount++;
@ -1407,14 +1427,8 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu
tabCount++;
T_FileStream_write(out,bodyStart, uprv_strlen(bodyStart));
if(package) {
pid = uprv_malloc(sizeof(char) * uprv_strlen(package)+1);
uprv_memset(pid, 0, sizeof(char) * uprv_strlen(package)+1);
uprv_strcpy(pid, package);
res_write_xml(bundle->fRoot, pid, lang, status);
} else {
res_write_xml(bundle->fRoot, "", lang, status);
}
res_write_xml(bundle->fRoot, srBundle->fLocale, lang, status);
tabCount--;
write_tabs(out);