Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: source/tools/toolutil/package.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/tools/toolutil/flagparser.c ('k') | source/tools/toolutil/pkg_genc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ******************************************************************************* 2 *******************************************************************************
3 * 3 *
4 * Copyright (C) 1999-2014, International Business Machines 4 * Copyright (C) 1999-2015, International Business Machines
5 * Corporation and others. All Rights Reserved. 5 * Corporation and others. All Rights Reserved.
6 * 6 *
7 ******************************************************************************* 7 *******************************************************************************
8 * file name: package.cpp 8 * file name: package.cpp
9 * encoding: US-ASCII 9 * encoding: US-ASCII
10 * tab size: 8 (not used) 10 * tab size: 8 (not used)
11 * indentation:4 11 * indentation:4
12 * 12 *
13 * created on: 2005aug25 13 * created on: 2005aug25
14 * created by: Markus W. Scherer 14 * created by: Markus W. Scherer
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 297 }
298 } 298 }
299 *sep++=U_FILE_SEP_CHAR; // restore file separator character 299 *sep++=U_FILE_SEP_CHAR; // restore file separator character
300 } 300 }
301 } 301 }
302 302
303 static uint8_t * 303 static uint8_t *
304 readFile(const char *path, const char *name, int32_t &length, char &type) { 304 readFile(const char *path, const char *name, int32_t &length, char &type) {
305 char filename[1024]; 305 char filename[1024];
306 FILE *file; 306 FILE *file;
307 uint8_t *data;
308 UErrorCode errorCode; 307 UErrorCode errorCode;
309 int32_t fileLength, typeEnum; 308 int32_t fileLength, typeEnum;
310 309
311 makeFullFilename(path, name, filename, (int32_t)sizeof(filename)); 310 makeFullFilename(path, name, filename, (int32_t)sizeof(filename));
312 311
313 /* open the input file, get its length, allocate memory for it, read the fil e */ 312 /* open the input file, get its length, allocate memory for it, read the fil e */
314 file=fopen(filename, "rb"); 313 file=fopen(filename, "rb");
315 if(file==NULL) { 314 if(file==NULL) {
316 fprintf(stderr, "icupkg: unable to open input file \"%s\"\n", filename); 315 fprintf(stderr, "icupkg: unable to open input file \"%s\"\n", filename);
317 exit(U_FILE_ACCESS_ERROR); 316 exit(U_FILE_ACCESS_ERROR);
318 } 317 }
319 318
320 /* get the file length */ 319 /* get the file length */
321 fileLength=getFileLength(file); 320 fileLength=getFileLength(file);
322 if(ferror(file) || fileLength<=0) { 321 if(ferror(file) || fileLength<=0) {
323 fprintf(stderr, "icupkg: empty input file \"%s\"\n", filename); 322 fprintf(stderr, "icupkg: empty input file \"%s\"\n", filename);
324 fclose(file); 323 fclose(file);
325 exit(U_FILE_ACCESS_ERROR); 324 exit(U_FILE_ACCESS_ERROR);
326 } 325 }
327 326
328 /* allocate the buffer, pad to multiple of 16 */ 327 /* allocate the buffer, pad to multiple of 16 */
329 length=(fileLength+0xf)&~0xf; 328 length=(fileLength+0xf)&~0xf;
330 data=(uint8_t *)uprv_malloc(length); 329 icu::LocalMemory<uint8_t> data((uint8_t *)uprv_malloc(length));
331 if(data==NULL) { 330 if(data.isNull()) {
332 fclose(file); 331 fclose(file);
333 fprintf(stderr, "icupkg: malloc error allocating %d bytes.\n", (int)leng th); 332 fprintf(stderr, "icupkg: malloc error allocating %d bytes.\n", (int)leng th);
334 exit(U_MEMORY_ALLOCATION_ERROR); 333 exit(U_MEMORY_ALLOCATION_ERROR);
335 } 334 }
336 335
337 /* read the file */ 336 /* read the file */
338 if(fileLength!=(int32_t)fread(data, 1, fileLength, file)) { 337 if(fileLength!=(int32_t)fread(data.getAlias(), 1, fileLength, file)) {
339 fprintf(stderr, "icupkg: error reading \"%s\"\n", filename); 338 fprintf(stderr, "icupkg: error reading \"%s\"\n", filename);
340 fclose(file); 339 fclose(file);
341 free(data);
342 exit(U_FILE_ACCESS_ERROR); 340 exit(U_FILE_ACCESS_ERROR);
343 } 341 }
344 342
345 /* pad the file to a multiple of 16 using the usual padding byte */ 343 /* pad the file to a multiple of 16 using the usual padding byte */
346 if(fileLength<length) { 344 if(fileLength<length) {
347 memset(data+fileLength, 0xaa, length-fileLength); 345 memset(data.getAlias()+fileLength, 0xaa, length-fileLength);
348 } 346 }
349 347
350 fclose(file); 348 fclose(file);
351 349
352 // minimum check for ICU-format data 350 // minimum check for ICU-format data
353 errorCode=U_ZERO_ERROR; 351 errorCode=U_ZERO_ERROR;
354 typeEnum=getTypeEnumForInputData(data, length, &errorCode); 352 typeEnum=getTypeEnumForInputData(data.getAlias(), length, &errorCode);
355 if(typeEnum<0 || U_FAILURE(errorCode)) { 353 if(typeEnum<0 || U_FAILURE(errorCode)) {
356 fprintf(stderr, "icupkg: not an ICU data file: \"%s\"\n", filename); 354 fprintf(stderr, "icupkg: not an ICU data file: \"%s\"\n", filename);
357 free(data);
358 #if !UCONFIG_NO_LEGACY_CONVERSION 355 #if !UCONFIG_NO_LEGACY_CONVERSION
359 exit(U_INVALID_FORMAT_ERROR); 356 exit(U_INVALID_FORMAT_ERROR);
360 #else 357 #else
361 fprintf(stderr, "U_INVALID_FORMAT_ERROR occurred but UCONFIG_NO_LEGACY_C ONVERSION is on so this is expected.\n"); 358 fprintf(stderr, "U_INVALID_FORMAT_ERROR occurred but UCONFIG_NO_LEGACY_C ONVERSION is on so this is expected.\n");
362 exit(0); 359 exit(0);
363 #endif 360 #endif
364 } 361 }
365 type=makeTypeLetter(typeEnum); 362 type=makeTypeLetter(typeEnum);
366 363
367 return data; 364 return data.orphan();
368 } 365 }
369 366
370 // .dat package file representation ---------------------------------------- *** 367 // .dat package file representation ---------------------------------------- ***
371 368
372 U_CDECL_BEGIN 369 U_CDECL_BEGIN
373 370
374 static int32_t U_CALLCONV 371 static int32_t U_CALLCONV
375 compareItems(const void * /*context*/, const void *left, const void *right) { 372 compareItems(const void * /*context*/, const void *left, const void *right) {
376 U_NAMESPACE_USE 373 U_NAMESPACE_USE
377 374
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 int32_t length=(headerLength+0xf)&~0xf; 411 int32_t length=(headerLength+0xf)&~0xf;
415 memset(header+headerLength, 0, length-headerLength); 412 memset(header+headerLength, 0, length-headerLength);
416 headerLength=length; 413 headerLength=length;
417 } 414 }
418 pHeader->dataHeader.headerSize=(uint16_t)headerLength; 415 pHeader->dataHeader.headerSize=(uint16_t)headerLength;
419 } 416 }
420 417
421 Package::~Package() { 418 Package::~Package() {
422 int32_t idx; 419 int32_t idx;
423 420
424 free(inData); 421 uprv_free(inData);
425 422
426 for(idx=0; idx<itemCount; ++idx) { 423 for(idx=0; idx<itemCount; ++idx) {
427 if(items[idx].isDataOwned) { 424 if(items[idx].isDataOwned) {
428 free(items[idx].data); 425 uprv_free(items[idx].data);
429 } 426 }
430 } 427 }
431 428
432 uprv_free((void*)items); 429 uprv_free((void*)items);
433 } 430 }
434 431
435 void 432 void
436 Package::setPrefix(const char *p) { 433 Package::setPrefix(const char *p) {
437 if(strlen(p)>=sizeof(pkgPrefix)) { 434 if(strlen(p)>=sizeof(pkgPrefix)) {
438 fprintf(stderr, "icupkg: --toc_prefix %s too long\n", p); 435 fprintf(stderr, "icupkg: --toc_prefix %s too long\n", p);
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 // reset this Item entry 1040 // reset this Item entry
1044 memset(items+idx, 0, sizeof(Item)); 1041 memset(items+idx, 0, sizeof(Item));
1045 1042
1046 // copy the item's name 1043 // copy the item's name
1047 items[idx].name=allocString(TRUE, strlen(name)); 1044 items[idx].name=allocString(TRUE, strlen(name));
1048 strcpy(items[idx].name, name); 1045 strcpy(items[idx].name, name);
1049 pathToTree(items[idx].name); 1046 pathToTree(items[idx].name);
1050 } else { 1047 } else {
1051 // same-name item found, replace it 1048 // same-name item found, replace it
1052 if(items[idx].isDataOwned) { 1049 if(items[idx].isDataOwned) {
1053 free(items[idx].data); 1050 uprv_free(items[idx].data);
1054 } 1051 }
1055 1052
1056 // keep the item's name since it is the same 1053 // keep the item's name since it is the same
1057 } 1054 }
1058 1055
1059 // set the item's data 1056 // set the item's data
1060 items[idx].data=data; 1057 items[idx].data=data;
1061 items[idx].length=length; 1058 items[idx].length=length;
1062 items[idx].isDataOwned=isDataOwned; 1059 items[idx].isDataOwned=isDataOwned;
1063 items[idx].type=type; 1060 items[idx].type=type;
(...skipping 18 matching lines...) Expand all
1082 for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) { 1079 for(pItem=listPkg.items, i=0; i<listPkg.itemCount; ++pItem, ++i) {
1083 addItem(pItem->name, pItem->data, pItem->length, FALSE, pItem->type); 1080 addItem(pItem->name, pItem->data, pItem->length, FALSE, pItem->type);
1084 } 1081 }
1085 } 1082 }
1086 1083
1087 void 1084 void
1088 Package::removeItem(int32_t idx) { 1085 Package::removeItem(int32_t idx) {
1089 if(idx>=0) { 1086 if(idx>=0) {
1090 // remove the item 1087 // remove the item
1091 if(items[idx].isDataOwned) { 1088 if(items[idx].isDataOwned) {
1092 free(items[idx].data); 1089 uprv_free(items[idx].data);
1093 } 1090 }
1094 1091
1095 // move the following items up 1092 // move the following items up
1096 if((idx+1)<itemCount) { 1093 if((idx+1)<itemCount) {
1097 memmove(items+idx, items+idx+1, (itemCount-(idx+1))*sizeof(Item)); 1094 memmove(items+idx, items+idx+1, (itemCount-(idx+1))*sizeof(Item));
1098 } 1095 }
1099 --itemCount; 1096 --itemCount;
1100 1097
1101 if(idx<=findNextIndex) { 1098 if(idx<=findNextIndex) {
1102 --findNextIndex; 1099 --findNextIndex;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 } 1300 }
1304 1301
1305 void Package::ensureItemCapacity() 1302 void Package::ensureItemCapacity()
1306 { 1303 {
1307 if((itemCount+1)>itemMax) { 1304 if((itemCount+1)>itemMax) {
1308 setItemCapacity(itemCount+kItemsChunk); 1305 setItemCapacity(itemCount+kItemsChunk);
1309 } 1306 }
1310 } 1307 }
1311 1308
1312 U_NAMESPACE_END 1309 U_NAMESPACE_END
OLDNEW
« no previous file with comments | « source/tools/toolutil/flagparser.c ('k') | source/tools/toolutil/pkg_genc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698