/******************************************************************************
- * Copyright (C) 2008-2010, International Business Machines
+ * Copyright (C) 2008-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
#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"
static char *symPrefix = NULL;
+#define LINE_BUFFER_SIZE 512
/* prototypes --------------------------------------------------------------- */
static void
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) {
}
/* 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;
}
addFile(getLongPathname(line), name, source, sourceTOC, verbose);
}
+ if (linePtr) {
+ uprv_free(linePtr);
+ }
+
if(in!=T_FileStream_stdin()) {
T_FileStream_close(in);
}
/* 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);
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);
}
}
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);
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);
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) {
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)