/********************************************************************
* COPYRIGHT:
- * Copyright (C) 2001-2008 IBM, Inc. All Rights Reserved.
+ * Copyright (C) 2001-2011 IBM, Inc. All Rights Reserved.
*
********************************************************************/
/********************************************************************************
// Stubs for Windows API functions when building on UNIXes.
//
typedef int DWORD;
-inline int CompareStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;};
+inline int CompareStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;}
#include <sys/time.h>
unsigned long timeGetTime() {
struct timeval t;
unsigned long val = t.tv_sec * 1000; // Let it overflow. Who cares.
val += t.tv_usec / 1000;
return val;
-};
-inline int LCMapStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;};
+}
+inline int LCMapStringW(DWORD, DWORD, UChar *, int, UChar *, int) {return 0;}
const int LCMAP_SORTKEY = 0;
#define MAKELCID(a,b) 0
const int SORT_DEFAULT = 0;
// These global variables are set according to the options specified
// on the command line by the user.
char * opt_fName = 0;
-char * opt_locale = "en_US";
+const char * opt_locale = "en_US";
int opt_langid = 0; // Defaults to value corresponding to opt_locale.
char * opt_rules = 0;
UBool opt_help = FALSE;
void doKeyGen()
{
int line;
- int loops;
+ int loops = 0;
int iLoop;
int t;
int len=-1;
gCount = 0;
int line;
- int loops;
- int iLoop;
- unsigned long elapsedTime;
+ int loops = 0;
+ int iLoop = 0;
+ unsigned long elapsedTime = 0;
// Adjust loop count to compensate for file size. Should be order n (lookups) * log n (compares/lookup)
// Accurate timings do not depend on this being perfect. The correction is just to try to
// get total running times of about the right order, so the that user doesn't need to
// manually adjust the loop count for every different file size.
- double dLoopCount = double(opt_loopCount) * 3000. / (log10(gNumFileLines) * double(gNumFileLines));
+ double dLoopCount = double(opt_loopCount) * 3000. / (log10((double)gNumFileLines) * double(gNumFileLines));
if (opt_usekeys) dLoopCount *= 5;
int adj_loopCount = int(dLoopCount);
if (adj_loopCount < 1) adj_loopCount = 1;
//if (opt_strcmp && opt_win) {pf = (PF)wcscmp;} // Damn the difference between int32_t and int
// which forces the use of a cast here.
- int r;
+ int r = 0;
for (loops=0; loops<adj_loopCount; loops++) {
for (line=0; line < gNumFileLines; line++) {
if (opt_icu)
{
unsigned long startTime = timeGetTime();
- UCollationResult r;
+ UCollationResult r = UCOL_EQUAL;
for (loops=0; loops<adj_loopCount; loops++) {
for (line=0; line < gNumFileLines; line++) {
if (newGuess == guess)
break;
guess = newGuess;
- int ri;
+ int ri = 0;
if (opt_usekeys) {
for (iLoop=0; iLoop < opt_iLoopCount; iLoop++) {
ri = strcmp((gSortedLines[line])->icuSortKey, (gSortedLines[guess])->icuSortKey);
if (opt_win)
{
unsigned long startTime = timeGetTime();
- int r;
+ int r = 0;
for (loops=0; loops<adj_loopCount; loops++) {
for (line=0; line < gNumFileLines; line++) {
if (opt_unix)
{
unsigned long startTime = timeGetTime();
- int r;
+ int r = 0;
for (loops=0; loops<adj_loopCount; loops++) {
for (line=0; line < gNumFileLines; line++) {
Line **sortBuf = new Line *[gNumFileLines];
// Adjust loop count to compensate for file size. QSort should be n log(n)
- double dLoopCount = double(opt_loopCount) * 3000. / (log10(gNumFileLines) * double(gNumFileLines));
+ double dLoopCount = double(opt_loopCount) * 3000. / (log10((double)gNumFileLines) * double(gNumFileLines));
if (opt_usekeys) dLoopCount *= 5;
int adj_loopCount = int(dLoopCount);
if (adj_loopCount < 1) adj_loopCount = 1;
} else {
printf("%d, ", ns);
}
-};
+}
(float)accumulatedLen[i] / (float)(numKeysOfSize[i] * i));
}
}
+ delete []accumulatedLen;
+ delete []numKeysOfSize ;
}
//---------------------------------------------------------------------------------------
count ++;
}
unsigned long elapsedTime = timeGetTime() - startTime;
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
// empty loop recalculation
count = 0;
count ++;
}
elapsedTime -= (timeGetTime() - startTime);
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
ucol_closeElements(iter);
}
elapsedTime = timeGetTime() - startTime;
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
// empty loop recalculation
int tempgCount = 0;
count ++;
}
elapsedTime -= (timeGetTime() - startTime);
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
ucol_closeElements(iter);
}
unsigned long elapsedTime = timeGetTime() - startTime;
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
// empty loop recalculation
count = 0;
}
elapsedTime -= (timeGetTime() - startTime);
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
ucol_closeElements(iter);
int ns = (int)(float(1000000) * (float)elapsedTime / (float)gCount);
}
elapsedTime = timeGetTime() - startTime;
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
// empty loop recalculation
count = 0;
count ++;
}
elapsedTime -= (timeGetTime() - startTime);
- printf("elapsedTime %d\n", elapsedTime);
+ printf("elapsedTime %ld\n", elapsedTime);
ucol_closeElements(iter);
printf("gCount %d\n", gCount);
cvrtr = ucnv_open("utf-8", &status); // we are just doing UTF-8 locales for now.
if (U_FAILURE(status)) {
- fprintf(stderr, "ICU Converter open failed.: %d\n", &status);
+ fprintf(stderr, "ICU Converter open failed.: %s\n", u_errorName(status));
exit(-1);
}
UBool error() {return fError;};
private:
- UCharFile (const UCharFile &other) {}; // No copy constructor.
- UCharFile & operator = (const UCharFile &other) {return *this;}; // No assignment op
+ UCharFile (const UCharFile & /*other*/) {}; // No copy constructor.
+ UCharFile & operator = (const UCharFile &/*other*/) {return *this;}; // No assignment op
FILE *fFile;
const char *fName;
}
break;
};
+ default:
+ c = 0xFFFD; /* Error, unspecified codepage*/
+ fprintf(stderr, "UCharFile: Error: unknown fEncoding\n");
+ exit(1);
}
return c;
}
int bufLen = 10000;
UChar *buf = (UChar *)malloc(bufLen * sizeof(UChar));
+ UChar *tmp;
int i = 0;
for(;;) {
}
i++;
if (i >= bufLen) {
+ tmp = buf;
bufLen += 10000;
buf = (UChar *)realloc(buf, bufLen);
+ if (buf == NULL) {
+ free(tmp);
+ return 0;
+ }
}
}
buf[i] = 0;
// Pre-compute ICU sort keys for the lines of the file.
//
int line;
- int t;
+ int32_t t;
for (line=0; line<gNumFileLines; line++) {
t = ucol_getSortKey(gCol, gFileLines[line].name, -1, (unsigned char *)buf, sizeof(buf));
gFileLines[line].icuSortKey = new char[t];
- if (t > sizeof(buf)) {
+ if (t > (int32_t)sizeof(buf)) {
t = ucol_getSortKey(gCol, gFileLines[line].name, -1, (unsigned char *)gFileLines[line].icuSortKey , t);
}
else
for (line=0; line<gNumFileLines; line++) {
t=LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, -1, buf, sizeof(buf));
gFileLines[line].winSortKey = new char[t];
- if (t > sizeof(buf)) {
+ if (t > (int32_t)sizeof(buf)) {
t = LCMapStringW(gWinLCID, LCMAP_SORTKEY, gFileLines[line].name, -1, (unsigned short *)(gFileLines[line].winSortKey), t);
}
else
for (line=0; line<gNumFileLines; line++) {
t=strxfrm((char *)buf, gFileLines[line].unixName, sizeof(buf));
gFileLines[line].unixSortKey = new char[t];
- if (t > sizeof(buf)) {
+ if (t > (int32_t)sizeof(buf)) {
t = strxfrm(gFileLines[line].unixSortKey, gFileLines[line].unixName, sizeof(buf));
}
else