OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2000-2012, International Business Machines | 4 * Copyright (C) 2000-2015, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 * | 8 * |
9 * File wrtjava.c | 9 * File wrtjava.cpp |
10 * | 10 * |
11 * Modification History: | 11 * Modification History: |
12 * | 12 * |
13 * Date Name Description | 13 * Date Name Description |
14 * 01/11/02 Ram Creation. | 14 * 01/11/02 Ram Creation. |
15 * 02/12/08 Spieth Fix errant 'new Object[][]{' insertion | 15 * 02/12/08 Spieth Fix errant 'new Object[][]{' insertion |
16 * 02/19/08 Spieth Removed ICUListResourceBundle dependancy | 16 * 02/19/08 Spieth Removed ICUListResourceBundle dependancy |
17 ******************************************************************************* | 17 ******************************************************************************* |
18 */ | 18 */ |
19 | 19 |
20 #include <assert.h> | 20 #include <assert.h> |
| 21 #include "unicode/unistr.h" |
21 #include "reslist.h" | 22 #include "reslist.h" |
22 #include "unewdata.h" | 23 #include "unewdata.h" |
23 #include "unicode/ures.h" | 24 #include "unicode/ures.h" |
24 #include "errmsg.h" | 25 #include "errmsg.h" |
25 #include "filestrm.h" | 26 #include "filestrm.h" |
26 #include "cstring.h" | 27 #include "cstring.h" |
27 #include "unicode/ucnv.h" | 28 #include "unicode/ucnv.h" |
28 #include "genrb.h" | 29 #include "genrb.h" |
29 #include "rle.h" | 30 #include "rle.h" |
30 #include "uhash.h" | 31 #include "uhash.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 T_FileStream_write(os," ",4); | 94 T_FileStream_write(os," ",4); |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 #define ZERO 0x30 | 98 #define ZERO 0x30 |
98 | 99 |
99 static const char* enc =""; | 100 static const char* enc =""; |
100 static UConverter* conv = NULL; | 101 static UConverter* conv = NULL; |
101 | 102 |
102 static int32_t | 103 static int32_t |
103 uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,
UErrorCode* status){ | 104 uCharsToChars(char *target, int32_t targetLen, const UChar *source, int32_t sour
ceLen, UErrorCode *status) { |
104 int i=0, j=0; | 105 int i=0, j=0; |
105 char str[30]={'\0'}; | 106 char str[30]={'\0'}; |
106 while(i<sourceLen){ | 107 while(i<sourceLen){ |
107 if (source[i] == '\n') { | 108 if (source[i] == '\n') { |
108 if (j + 2 < targetLen) { | 109 if (j + 2 < targetLen) { |
109 uprv_strcat(target, "\\n"); | 110 uprv_strcat(target, "\\n"); |
110 } | 111 } |
111 j += 2; | 112 j += 2; |
112 }else if(source[i]==0x0D){ | 113 }else if(source[i]==0x0D){ |
113 if(j+2<targetLen){ | 114 if(j+2<targetLen){ |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 /* | 219 /* |
219 * calculate the number of lines that | 220 * calculate the number of lines that |
220 * may be required if column count is 80 | 221 * may be required if column count is 80 |
221 */ | 222 */ |
222 if (maxLines < (adjustedLen / columnCount) ){ | 223 if (maxLines < (adjustedLen / columnCount) ){ |
223 columnCount = adjustedLen / maxLines; | 224 columnCount = adjustedLen / maxLines; |
224 } | 225 } |
225 return columnCount; | 226 return columnCount; |
226 } | 227 } |
227 static void | 228 static void |
228 str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *s
tatus){ | 229 str_write_java(const UChar *src, int32_t srcLen, UBool printEndLine, UErrorCode
*status) { |
229 | 230 |
230 uint32_t length = srcLen*8; | 231 uint32_t length = srcLen*8; |
231 uint32_t bufLen = 0; | 232 uint32_t bufLen = 0; |
232 uint32_t columnCount; | 233 uint32_t columnCount; |
233 char* buf = (char*) malloc(sizeof(char)*length); | 234 char* buf = (char*) malloc(sizeof(char)*length); |
234 | 235 |
235 if(buf == NULL) { | 236 if(buf == NULL) { |
236 *status = U_MEMORY_ALLOCATION_ERROR; | 237 *status = U_MEMORY_ALLOCATION_ERROR; |
237 return; | 238 return; |
238 } | 239 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if(printEndLine){ | 298 if(printEndLine){ |
298 T_FileStream_write(out,"\",\n",3); | 299 T_FileStream_write(out,"\",\n",3); |
299 }else{ | 300 }else{ |
300 T_FileStream_write(out,"\"",1); | 301 T_FileStream_write(out,"\"",1); |
301 } | 302 } |
302 uprv_free(buf); | 303 uprv_free(buf); |
303 } | 304 } |
304 | 305 |
305 /* Writing Functions */ | 306 /* Writing Functions */ |
306 static void | 307 static void |
307 string_write_java(struct SResource *res,UErrorCode *status) { | 308 string_write_java(const StringResource *res,UErrorCode *status) { |
308 char resKeyBuffer[8]; | 309 (void)res->getKeyString(srBundle); |
309 const char *resname = res_getKeyString(srBundle, res, resKeyBuffer); | |
310 | 310 |
311 str_write_java(res->u.fString.fChars,res->u.fString.fLength,TRUE,status); | 311 str_write_java(res->getBuffer(), res->length(), TRUE, status); |
312 | |
313 » if(resname != NULL && uprv_strcmp(resname,"Rule")==0) | |
314 » { | |
315 UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength); | |
316 uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength); | |
317 uprv_free(buf); | |
318 } | |
319 | |
320 } | 312 } |
321 | 313 |
322 static void | 314 static void |
323 array_write_java( struct SResource *res, UErrorCode *status) { | 315 array_write_java(const ArrayResource *res, UErrorCode *status) { |
324 | 316 |
325 uint32_t i = 0; | 317 uint32_t i = 0; |
326 const char* arr ="new String[] { \n"; | 318 const char* arr ="new String[] { \n"; |
327 struct SResource *current = NULL; | 319 struct SResource *current = NULL; |
328 UBool allStrings = TRUE; | 320 UBool allStrings = TRUE; |
329 | 321 |
330 if (U_FAILURE(*status)) { | 322 if (U_FAILURE(*status)) { |
331 return; | 323 return; |
332 } | 324 } |
333 | 325 |
334 if (res->u.fArray.fCount > 0) { | 326 if (res->fCount > 0) { |
335 | 327 |
336 current = res->u.fArray.fFirst; | 328 current = res->fFirst; |
337 i = 0; | 329 i = 0; |
338 while(current != NULL){ | 330 while(current != NULL){ |
339 if(current->fType!=URES_STRING){ | 331 if(!current->isString()){ |
340 allStrings = FALSE; | 332 allStrings = FALSE; |
341 break; | 333 break; |
342 } | 334 } |
343 current= current->fNext; | 335 current= current->fNext; |
344 } | 336 } |
345 | 337 |
346 current = res->u.fArray.fFirst; | 338 current = res->fFirst; |
347 if(allStrings==FALSE){ | 339 if(allStrings==FALSE){ |
348 const char* object = "new Object[]{\n"; | 340 const char* object = "new Object[]{\n"; |
349 write_tabs(out); | 341 write_tabs(out); |
350 T_FileStream_write(out, object, (int32_t)uprv_strlen(object)); | 342 T_FileStream_write(out, object, (int32_t)uprv_strlen(object)); |
351 tabCount++; | 343 tabCount++; |
352 }else{ | 344 }else{ |
353 write_tabs(out); | 345 write_tabs(out); |
354 T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr)); | 346 T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr)); |
355 tabCount++; | 347 tabCount++; |
356 } | 348 } |
357 while (current != NULL) { | 349 while (current != NULL) { |
358 /*if(current->fType==URES_STRING){ | 350 /*if(current->isString()){ |
359 write_tabs(out); | 351 write_tabs(out); |
360 }*/ | 352 }*/ |
361 res_write_java(current, status); | 353 res_write_java(current, status); |
362 if(U_FAILURE(*status)){ | 354 if(U_FAILURE(*status)){ |
363 return; | 355 return; |
364 } | 356 } |
365 i++; | 357 i++; |
366 current = current->fNext; | 358 current = current->fNext; |
367 } | 359 } |
368 T_FileStream_write(out,"\n",1); | 360 T_FileStream_write(out,"\n",1); |
369 | 361 |
370 tabCount--; | 362 tabCount--; |
371 write_tabs(out); | 363 write_tabs(out); |
372 T_FileStream_write(out,"},\n",3); | 364 T_FileStream_write(out,"},\n",3); |
373 | 365 |
374 } else { | 366 } else { |
375 write_tabs(out); | 367 write_tabs(out); |
376 T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr)); | 368 T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr)); |
377 write_tabs(out); | 369 write_tabs(out); |
378 T_FileStream_write(out,"},\n",3); | 370 T_FileStream_write(out,"},\n",3); |
379 } | 371 } |
380 } | 372 } |
381 | 373 |
382 static void | 374 static void |
383 intvector_write_java( struct SResource *res, UErrorCode *status) { | 375 intvector_write_java(const IntVectorResource *res, UErrorCode * /*status*/) { |
384 uint32_t i = 0; | 376 uint32_t i = 0; |
385 const char* intArr = "new int[] {\n"; | 377 const char* intArr = "new int[] {\n"; |
386 /* const char* intC = "new Integer("; */ | 378 /* const char* intC = "new Integer("; */ |
387 const char* stringArr = "new String[]{\n"; | 379 const char* stringArr = "new String[]{\n"; |
388 char resKeyBuffer[8]; | 380 const char *resname = res->getKeyString(srBundle); |
389 const char *resname = res_getKeyString(srBundle, res, resKeyBuffer); | |
390 char buf[100]; | 381 char buf[100]; |
391 int len =0; | 382 int len =0; |
392 buf[0]=0; | 383 buf[0]=0; |
393 write_tabs(out); | 384 write_tabs(out); |
394 | 385 |
395 if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){ | 386 if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){ |
396 T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr)); | 387 T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr)); |
397 tabCount++; | 388 tabCount++; |
398 for(i = 0; i<res->u.fIntVector.fCount; i++) { | 389 for(i = 0; i<res->fCount; i++) { |
399 write_tabs(out); | 390 write_tabs(out); |
400 len=itostr(buf,res->u.fIntVector.fArray[i],10,0); | 391 len=itostr(buf,res->fArray[i],10,0); |
401 T_FileStream_write(out,"\"",1); | 392 T_FileStream_write(out,"\"",1); |
402 T_FileStream_write(out,buf,len); | 393 T_FileStream_write(out,buf,len); |
403 T_FileStream_write(out,"\",",2); | 394 T_FileStream_write(out,"\",",2); |
404 T_FileStream_write(out,"\n",1); | 395 T_FileStream_write(out,"\n",1); |
405 } | 396 } |
406 }else{ | 397 }else{ |
407 T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr)); | 398 T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr)); |
408 tabCount++; | 399 tabCount++; |
409 for(i = 0; i<res->u.fIntVector.fCount; i++) { | 400 for(i = 0; i<res->fCount; i++) { |
410 write_tabs(out); | 401 write_tabs(out); |
411 /* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */ | 402 /* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */ |
412 len=itostr(buf,res->u.fIntVector.fArray[i],10,0); | 403 len=itostr(buf,res->fArray[i],10,0); |
413 T_FileStream_write(out,buf,len); | 404 T_FileStream_write(out,buf,len); |
414 /* T_FileStream_write(out,"),",2); */ | 405 /* T_FileStream_write(out,"),",2); */ |
415 /* T_FileStream_write(out,"\n",1); */ | 406 /* T_FileStream_write(out,"\n",1); */ |
416 T_FileStream_write(out,",\n",2); | 407 T_FileStream_write(out,",\n",2); |
417 } | 408 } |
418 } | 409 } |
419 tabCount--; | 410 tabCount--; |
420 write_tabs(out); | 411 write_tabs(out); |
421 T_FileStream_write(out,"},\n",3); | 412 T_FileStream_write(out,"},\n",3); |
422 } | 413 } |
423 | 414 |
424 static void | 415 static void |
425 int_write_java(struct SResource *res,UErrorCode *status) { | 416 int_write_java(const IntResource *res, UErrorCode * /*status*/) { |
426 const char* intC = "new Integer("; | 417 const char* intC = "new Integer("; |
427 char buf[100]; | 418 char buf[100]; |
428 int len =0; | 419 int len =0; |
429 buf[0]=0; | 420 buf[0]=0; |
430 | 421 |
431 /* write the binary data */ | 422 /* write the binary data */ |
432 write_tabs(out); | 423 write_tabs(out); |
433 T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); | 424 T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); |
434 len=itostr(buf, res->u.fIntValue.fValue, 10, 0); | 425 len=itostr(buf, res->fValue, 10, 0); |
435 T_FileStream_write(out,buf,len); | 426 T_FileStream_write(out,buf,len); |
436 T_FileStream_write(out,"),\n",3 ); | 427 T_FileStream_write(out,"),\n",3 ); |
437 | 428 |
438 } | 429 } |
439 | 430 |
440 static void | 431 static void |
441 bytes_write_java( struct SResource *res, UErrorCode *status) { | 432 bytes_write_java(const BinaryResource *res, UErrorCode * /*status*/) { |
442 const char* type = "new byte[] {"; | 433 const char* type = "new byte[] {"; |
443 const char* byteDecl = "%i, "; | 434 const char* byteDecl = "%i, "; |
444 char byteBuffer[100] = { 0 }; | 435 char byteBuffer[100] = { 0 }; |
445 uint8_t* byteArray = NULL; | 436 uint8_t* byteArray = NULL; |
446 int byteIterator = 0; | 437 int byteIterator = 0; |
447 | 438 |
448 int32_t srcLen=res->u.fBinaryValue.fLength; | 439 int32_t srcLen=res->fLength; |
449 | 440 |
450 if(srcLen>0 ) | 441 if(srcLen>0 ) |
451 { | 442 { |
452 byteArray = res->u.fBinaryValue.fData; | 443 byteArray = res->fData; |
453 | 444 |
454 write_tabs(out); | 445 write_tabs(out); |
455 T_FileStream_write(out, type, (int32_t)uprv_strlen(type)); | 446 T_FileStream_write(out, type, (int32_t)uprv_strlen(type)); |
456 T_FileStream_write(out, "\n", 1); | 447 T_FileStream_write(out, "\n", 1); |
457 tabCount++; | 448 tabCount++; |
458 | 449 |
459 for (;byteIterator<srcLen;byteIterator++) | 450 for (;byteIterator<srcLen;byteIterator++) |
460 { | 451 { |
461 if (byteIterator%16 == 0) | 452 if (byteIterator%16 == 0) |
462 { | 453 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 write_tabs(out); | 488 write_tabs(out); |
498 T_FileStream_write(out,type,(int32_t)uprv_strlen(type)); | 489 T_FileStream_write(out,type,(int32_t)uprv_strlen(type)); |
499 T_FileStream_write(out,"},\n",3); | 490 T_FileStream_write(out,"},\n",3); |
500 } | 491 } |
501 | 492 |
502 } | 493 } |
503 | 494 |
504 static UBool start = TRUE; | 495 static UBool start = TRUE; |
505 | 496 |
506 static void | 497 static void |
507 table_write_java(struct SResource *res, UErrorCode *status) { | 498 table_write_java(const TableResource *res, UErrorCode *status) { |
508 uint32_t i = 0; | 499 uint32_t i = 0; |
509 struct SResource *current = NULL; | 500 struct SResource *current = NULL; |
510 const char* obj = "new Object[][]{\n"; | 501 const char* obj = "new Object[][]{\n"; |
511 | 502 |
512 if (U_FAILURE(*status)) { | 503 if (U_FAILURE(*status)) { |
513 return ; | 504 return ; |
514 } | 505 } |
515 | 506 |
516 if (res->u.fTable.fCount > 0) { | 507 if (res->fCount > 0) { |
517 if(start==FALSE){ | 508 if(start==FALSE){ |
518 write_tabs(out); | 509 write_tabs(out); |
519 T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj)); | 510 T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj)); |
520 tabCount++; | 511 tabCount++; |
521 } | 512 } |
522 start = FALSE; | 513 start = FALSE; |
523 current = res->u.fTable.fFirst; | 514 current = res->fFirst; |
524 i = 0; | 515 i = 0; |
525 | 516 |
526 | 517 |
527 while (current != NULL) { | 518 while (current != NULL) { |
528 char currentKeyBuffer[8]; | 519 const char *currentKeyString = current->getKeyString(srBundle); |
529 const char *currentKeyString = res_getKeyString(srBundle, current, c
urrentKeyBuffer); | |
530 | 520 |
531 assert(i < res->u.fTable.fCount); | 521 assert(i < res->fCount); |
532 write_tabs(out); | 522 write_tabs(out); |
533 | 523 |
534 T_FileStream_write(out, openBrace, 2); | 524 T_FileStream_write(out, openBrace, 2); |
535 | 525 |
536 | 526 |
537 tabCount++; | 527 tabCount++; |
538 | 528 |
539 write_tabs(out); | 529 write_tabs(out); |
540 if(currentKeyString != NULL) { | 530 if(currentKeyString != NULL) { |
541 T_FileStream_write(out, "\"", 1); | 531 T_FileStream_write(out, "\"", 1); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 void | 565 void |
576 res_write_java(struct SResource *res,UErrorCode *status) { | 566 res_write_java(struct SResource *res,UErrorCode *status) { |
577 | 567 |
578 if (U_FAILURE(*status)) { | 568 if (U_FAILURE(*status)) { |
579 return ; | 569 return ; |
580 } | 570 } |
581 | 571 |
582 if (res != NULL) { | 572 if (res != NULL) { |
583 switch (res->fType) { | 573 switch (res->fType) { |
584 case URES_STRING: | 574 case URES_STRING: |
585 string_write_java (res, status); | 575 string_write_java (static_cast<const StringResource *>(res), sta
tus); |
586 return; | 576 return; |
587 case URES_ALIAS: | 577 case URES_ALIAS: |
588 printf("Encountered unsupported resource type %d of alias\n", res->
fType); | 578 printf("Encountered unsupported resource type %d of alias\n", res->
fType); |
589 *status = U_UNSUPPORTED_ERROR; | 579 *status = U_UNSUPPORTED_ERROR; |
590 return; | 580 return; |
591 case URES_INT_VECTOR: | 581 case URES_INT_VECTOR: |
592 intvector_write_java (res, status); | 582 intvector_write_java (static_cast<const IntVectorResource *>(res),
status); |
593 return; | 583 return; |
594 case URES_BINARY: | 584 case URES_BINARY: |
595 bytes_write_java (res, status); | 585 bytes_write_java (static_cast<const BinaryResource *>(res), sta
tus); |
596 return; | 586 return; |
597 case URES_INT: | 587 case URES_INT: |
598 int_write_java (res, status); | 588 int_write_java (static_cast<const IntResource *>(res), status
); |
599 return; | 589 return; |
600 case URES_ARRAY: | 590 case URES_ARRAY: |
601 array_write_java (res, status); | 591 array_write_java (static_cast<const ArrayResource *>(res), stat
us); |
602 return; | 592 return; |
603 case URES_TABLE: | 593 case URES_TABLE: |
604 table_write_java (res, status); | 594 table_write_java (static_cast<const TableResource *>(res), stat
us); |
605 return; | 595 return; |
606 default: | 596 default: |
607 break; | 597 break; |
608 } | 598 } |
609 } | 599 } |
610 | 600 |
611 *status = U_INTERNAL_PROGRAM_ERROR; | 601 *status = U_INTERNAL_PROGRAM_ERROR; |
612 } | 602 } |
613 | 603 |
614 void | 604 void |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 } | 678 } |
689 } | 679 } |
690 res_write_java(bundle->fRoot, status); | 680 res_write_java(bundle->fRoot, status); |
691 | 681 |
692 T_FileStream_write(out, closeClass, (int32_t)uprv_strlen(closeClass)); | 682 T_FileStream_write(out, closeClass, (int32_t)uprv_strlen(closeClass)); |
693 | 683 |
694 T_FileStream_close(out); | 684 T_FileStream_close(out); |
695 | 685 |
696 ucnv_close(conv); | 686 ucnv_close(conv); |
697 } | 687 } |
OLD | NEW |