]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/toolutil/pkg_gencmn.c
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / pkg_gencmn.c
index 64f505d6d682209325c8f5cef9905ddf539b7c80..ced82138d2e0cf553e5363ff76bc1cba071b8b8e 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
- *   Copyright (C) 2008-2010, International Business Machines
+ *   Copyright (C) 2008-2012, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
@@ -18,7 +18,7 @@
 #include "putilimp.h"
 #include "pkg_gencmn.h"
 
-#define STRING_STORE_SIZE 100000
+#define STRING_STORE_SIZE 200000
 
 #define COMMON_DATA_NAME U_ICUDATA_NAME
 #define DATA_TYPE "dat"
@@ -92,6 +92,7 @@ static uint32_t fileMax = 0;
 
 static char *symPrefix = NULL;
 
+#define LINE_BUFFER_SIZE 512
 /* prototypes --------------------------------------------------------------- */
 
 static void
@@ -115,12 +116,21 @@ U_CAPI void U_EXPORT2
 createCommonDataFile(const char *destDir, const char *name, const char *entrypointName, const char *type, const char *source, const char *copyRight,
                      const char *dataFile, uint32_t max_size, UBool sourceTOC, UBool verbose, char *gencmnFileName) {
     static char buffer[4096];
-    char line[512];
-    char *s;
+    char *line;
+    char *linePtr;
+    char *s = NULL;
     UErrorCode errorCode=U_ZERO_ERROR;
     uint32_t i, fileOffset, basenameOffset, length, nread;
     FileStream *in, *file;
 
+    line = (char *)uprv_malloc(sizeof(char) * LINE_BUFFER_SIZE);
+    if (line == NULL) {
+        fprintf(stderr, "gencmn: unable to allocate memory for line buffer of size %d\n", LINE_BUFFER_SIZE);
+        exit(U_MEMORY_ALLOCATION_ERROR);
+    }
+
+    linePtr = line;
+
     maxSize = max_size;
 
     if (destDir == NULL) {
@@ -155,11 +165,20 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi
     }
 
     /* read the list of files and get their lengths */
-    while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) {
-        /* remove trailing newline characters */
-        s=line;
+    while((s != NULL && *s != 0) || (s=T_FileStream_readLine(in, (line=linePtr),
+                                                             LINE_BUFFER_SIZE))!=NULL) {
+        /* remove trailing newline characters and parse space separated items */
+        if (s != NULL && *s != 0) {
+            line=s;
+        } else {
+            s=line;
+        }
         while(*s!=0) {
-            if(*s=='\r' || *s=='\n') {
+            if(*s==' ') {
+                *s=0;
+                ++s;
+                break;
+            } else if(*s=='\r' || *s=='\n') {
                 *s=0;
                 break;
             }
@@ -184,6 +203,10 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi
         addFile(getLongPathname(line), name, source, sourceTOC, verbose);
     }
 
+    if (linePtr) {
+      uprv_free(linePtr);
+    }
+
     if(in!=T_FileStream_stdin()) {
         T_FileStream_close(in);
     }
@@ -315,14 +338,14 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi
         /* write the source file */
         sprintf(buffer,
             "/*\n"
-            " * ICU common data table of contents for %s.%s ,\n"
+            " * ICU common data table of contents for %s.%s\n"
             " * Automatically generated by icu/source/tools/gencmn/gencmn .\n"
             " */\n\n"
             "#include \"unicode/utypes.h\"\n"
             "#include \"unicode/udata.h\"\n"
             "\n"
-            "/* external symbol declarations for data */\n",
-            name, type);
+            "/* external symbol declarations for data (%d files) */\n",
+                name, type, fileCount);
         T_FileStream_writeLine(out, buffer);
 
         sprintf(buffer, "extern const char\n    %s%s[]", symPrefix?symPrefix:"", files[0].pathname);
@@ -389,7 +412,7 @@ addFile(const char *filename, const char *name, const char *source, UBool source
       fileMax += CHUNK_FILE_COUNT;
       files = uprv_realloc(files, fileMax*sizeof(files[0])); /* note: never freed. */
       if(files==NULL) {
-        fprintf(stderr, "pkgdata/gencmn: Could not allocate %ld bytes for %d files\n", (fileMax*sizeof(files[0])), fileCount);
+        fprintf(stderr, "pkgdata/gencmn: Could not allocate %u bytes for %d files\n", (unsigned int)(fileMax*sizeof(files[0])), fileCount);
         exit(U_MEMORY_ALLOCATION_ERROR);
       }
     }
@@ -402,7 +425,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source
             exit(U_ILLEGAL_ARGUMENT_ERROR);
         }
         fullPath = pathToFullPath(filename, source);
-
         /* store the pathname */
         length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1);
         s=allocString(length);
@@ -445,7 +467,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source
         files[fileCount].fileSize=length;
     } else {
         char *t;
-
         /* get and store the basename */
         /* need to include the package name */
         length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1);
@@ -455,8 +476,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source
         uprv_strcat(s, filename);
         fixDirToTreePath(s);
         files[fileCount].basename=s;
-
-
         /* turn the basename into an entry point name and store in the pathname field */
         t=files[fileCount].pathname=allocString(length);
         while(--length>0) {
@@ -504,6 +523,8 @@ pathToFullPath(const char *path, const char *source) {
         fullPath[0] = 0;
     }
     n = (int32_t)uprv_strlen(fullPath);
+    fullPath[n] = 0;       /* Suppress compiler warning for unused variable n    */
+                           /*  when conditional code below is not compiled.      */
     uprv_strcat(fullPath, path);
 
 #if (U_FILE_ALT_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR)