[sword-cvs] icu-sword/source/tools/genpname genpname.cpp,1.1,1.2 genpname.vcproj,1.1,1.2
sword@www.crosswire.org
sword@www.crosswire.org
Tue, 6 Apr 2004 03:10:40 -0700
- Previous message: [sword-cvs] icu-sword/source/tools/gennames gennames.c,1.5,1.6 gennames.vcproj,1.1,1.2
- Next message: [sword-cvs] icu-sword/source/tools/gennorm gennorm.c,1.4,1.5 gennorm.vcproj,1.1,1.2 store.c,1.3,1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvs/core/icu-sword/source/tools/genpname
In directory www:/tmp/cvs-serv8911/source/tools/genpname
Modified Files:
genpname.cpp genpname.vcproj
Log Message:
ICU 2.8 sync
Index: genpname.cpp
===================================================================
RCS file: /cvs/core/icu-sword/source/tools/genpname/genpname.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- genpname.cpp 10 Sep 2003 02:42:56 -0000 1.1
+++ genpname.cpp 6 Apr 2004 10:10:07 -0000 1.2
@@ -1,6 +1,6 @@
/*
**********************************************************************
-* Copyright (C) 2002, International Business Machines
+* Copyright (C) 2002-2003, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Date Name Description
@@ -9,12 +9,13 @@
*/
#include <stdio.h>
-#include <stdlib.h>
#include "unicode/utypes.h"
#include "unicode/putil.h"
+#include "unicode/uclean.h"
#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
+#include "uarrsort.h"
#include "unewdata.h"
#include "uoptions.h"
#include "uprops.h"
@@ -214,9 +215,12 @@
NameToEnumEntry(int32_t a, int32_t b) { nameIndex=a; enumValue=b; }
};
-// Sort function for NameToEnumEntry (sort by name index)
-U_CAPI int compareNameToEnumEntry(const void* e1, const void* e2) {
- return ((NameToEnumEntry*)e1)->nameIndex - ((NameToEnumEntry*)e2)->nameIndex;
+// Sort function for NameToEnumEntry (sort by name)
+U_CAPI int32_t
+compareNameToEnumEntry(const void * /*context*/, const void* e1, const void* e2) {
+ return
+ STRING_TABLE[((NameToEnumEntry*)e1)->nameIndex].
+ compare(STRING_TABLE[((NameToEnumEntry*)e2)->nameIndex]);
}
//----------------------------------------------------------------------
@@ -245,7 +249,8 @@
};
// Sort function for EnumToNameGroupEntry (sort by name index)
-U_CAPI int compareEnumToNameGroupEntry(const void* e1, const void* e2) {
+U_CAPI int32_t
+compareEnumToNameGroupEntry(const void * /*context*/, const void* e1, const void* e2) {
return ((EnumToNameGroupEntry*)e1)->enumValue - ((EnumToNameGroupEntry*)e2)->enumValue;
}
@@ -276,7 +281,8 @@
};
// Sort function for EnumToValueEntry (sort by enum)
-U_CAPI int compareEnumToValueEntry(const void* e1, const void* e2) {
+U_CAPI int32_t
+compareEnumToValueEntry(const void * /*context*/, const void* e1, const void* e2) {
return ((EnumToValueEntry*)e1)->enumValue - ((EnumToValueEntry*)e2)->enumValue;
}
@@ -639,7 +645,7 @@
// first string must be "" -- we skip it
U_ASSERT(*propertyNames[0].str == 0);
for (i=1 /*sic*/; i<propertyNameCount; ++i) {
- stringPool_size += uprv_strlen(propertyNames[i].str) + 1;
+ stringPool_size += (int32_t)(uprv_strlen(propertyNames[i].str) + 1);
}
stringPool = MALLOC(char, stringPool_size);
stringPool_offsetArray = MALLOC(Offset, stringPool_count);
@@ -648,7 +654,7 @@
stringPool_offsetArray[0] = -1; // we don't use this entry
for (i=1 /*sic*/; i<propertyNameCount; ++i) {
const char* str = propertyNames[i].str;
- int32_t len = uprv_strlen(str);
+ int32_t len = (int32_t)uprv_strlen(str);
uprv_strcpy(p, str);
p += len;
*p++ = 0;
@@ -761,7 +767,7 @@
void Builder::fixupNCEnumToNameGroup(NonContiguousEnumToOffset* e2ng) {
int32_t i;
- EnumValue* e = e2ng->getEnumArray();
+ /*EnumValue* e = e2ng->getEnumArray();*/
Offset* p = e2ng->getOffsetArray();
for (i=0; i<e2ng->count; ++i) {
p[i] = nameGroupPool_offset + sizeof(Offset) * p[i];
@@ -813,7 +819,7 @@
// 3:
Offset* p = enumToValue->getOffsetArray();
- EnumValue* e = enumToValue->getEnumArray();
+ /*EnumValue* e = enumToValue->getEnumArray();*/
U_ASSERT(valueMap_count == enumToValue->count);
for (i=0; i<valueMap_count; ++i) {
p[i] = (Offset)(valueMap_offset + sizeof(ValueMap) * i);
@@ -875,7 +881,10 @@
APPEND(nameGroupPool);
APPEND(stringPool);
- U_ASSERT(p == limit);
+ if (p != limit) {
+ fprintf(stderr, "p != limit; p = %p, limit = %p", p, limit);
+ exit(1);
+ }
return result;
}
@@ -897,11 +906,6 @@
{VERSION_0, VERSION_1, VERSION_2, VERSION_3} /* Unicode version */
};
-// Glue for C<->C++
-U_CAPI int compareAliasNames(const void* elem1, const void* elem2) {
- return ((const AliasName*)elem1)->compare(*(const AliasName*)elem2);
-}
-
class genpname {
// command-line options
@@ -922,9 +926,22 @@
};
int main(int argc, char *argv[]) {
+ UErrorCode status = U_ZERO_ERROR;
+ u_init(&status);
+ if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) {
+ // Note: u_init() will try to open ICU property data.
+ // failures here are expected when building ICU from scratch.
+ // ignore them.
+ fprintf(stderr, "genpname: can not initialize ICU. Status = %s\n",
+ u_errorName(status));
+ exit(1);
+ }
+
genpname app;
U_MAIN_INIT_ARGS(argc, argv);
- return app.MMain(argc, argv);
+ int retVal = app.MMain(argc, argv);
+ u_cleanup();
+ return retVal;
}
static UOption options[]={
@@ -963,8 +980,14 @@
NameToEnumEntry(names[j], p.enumValue);
}
}
- qsort((void*) nameIndex, nameIndexCount, sizeof(nameIndex[0]),
- compareNameToEnumEntry);
+
+ /*
+ * use a stable sort to ensure consistent results between
+ * genpname.cpp and the propname.cpp swapping code
+ */
+ UErrorCode errorCode = U_ZERO_ERROR;
+ uprv_sortArray(nameIndex, nameIndexCount, sizeof(nameIndex[0]),
+ compareNameToEnumEntry, NULL, TRUE, &errorCode);
if (debug>1) {
printf("Alias names: %d\n", nameIndexCount);
for (i=0; i<nameIndexCount; ++i) {
@@ -1015,8 +1038,10 @@
const Alias& p = list[i];
enumIndex[i] = EnumToNameGroupEntry(p.enumValue, p.nameGroupIndex);
}
- qsort((void*) enumIndex, count, sizeof(enumIndex[0]),
- compareEnumToNameGroupEntry);
+
+ UErrorCode errorCode = U_ZERO_ERROR;
+ uprv_sortArray(enumIndex, count, sizeof(enumIndex[0]),
+ compareEnumToNameGroupEntry, NULL, FALSE, &errorCode);
if (debug>1) {
printf("Property enums: %d\n", count);
for (i=0; i<count; ++i) {
@@ -1040,9 +1065,17 @@
return enumIndex;
}
-int genpname::MMain(int argc, char* argv[]) {
-
+int genpname::MMain(int argc, char* argv[])
+{
int32_t i, j;
+ UErrorCode status = U_ZERO_ERROR;
+
+ u_init(&status);
+ if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) {
+ fprintf(stderr, "Error: u_init returned %s\n", u_errorName(status));
+ status = U_ZERO_ERROR;
+ }
+
/* preset then read command line options */
options[3].value=u_getDataDirectory();
@@ -1077,36 +1110,23 @@
verbose = options[4].doesOccur;
// ------------------------------------------------------------
- // Sort the string table. This produces the proper sorting
- // using the actual comparison function we will use.
- qsort((void*) STRING_TABLE, STRING_COUNT, sizeof(STRING_TABLE[0]),
- compareAliasNames);
+ // Do not sort the string table, instead keep it in data.h order.
+ // This simplifies data swapping and testing thereof because the string
+ // table itself need not be sorted during swapping.
+ // The NameToEnum sorter sorts each such map's string offsets instead.
+
if (debug>1) {
printf("String pool: %d\n", STRING_COUNT);
- }
- for (i=0; i<STRING_COUNT; ++i) {
- REMAP[STRING_TABLE[i].index] = i;
- if (debug>1) {
- if (i != 0) printf(", ");
+ for (i=0; i<STRING_COUNT; ++i) {
+ if (i != 0) {
+ printf(", ");
+ }
printf("%s (%d)", STRING_TABLE[i].str, STRING_TABLE[i].index);
}
- }
- if (debug>1) {
printf("\n\n");
}
// ------------------------------------------------------------
- // Fixup the NAME_GROUP indices so they match the sorted order
- for (i=0; i<NAME_GROUP_COUNT; ++i) {
- // keep negative entries (end markers) negative
- if (NAME_GROUP[i] < 0) {
- NAME_GROUP[i] = -REMAP[-NAME_GROUP[i]];
- } else {
- NAME_GROUP[i] = REMAP[NAME_GROUP[i]];
- }
- }
-
- // ------------------------------------------------------------
// Create top-level property indices
PropertyArrayList props(PROPERTY, PROPERTY_COUNT);
@@ -1132,8 +1152,9 @@
++j;
}
enumToValue_count = j;
- qsort((void*) enumToValue, enumToValue_count, sizeof(enumToValue[0]),
- compareEnumToValueEntry);
+
+ uprv_sortArray(enumToValue, enumToValue_count, sizeof(enumToValue[0]),
+ compareEnumToValueEntry, NULL, FALSE, &status);
// ------------------------------------------------------------
// Build PropertyAliases layout in memory
Index: genpname.vcproj
===================================================================
RCS file: /cvs/core/icu-sword/source/tools/genpname/genpname.vcproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- genpname.vcproj 10 Sep 2003 02:42:57 -0000 1.1
+++ genpname.vcproj 6 Apr 2004 10:10:07 -0000 1.2
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
+<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="7.00"
+ Version="7.10"
Name="genpname"
SccProjectName=""
SccLocalPath="">
@@ -37,9 +37,9 @@
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"
- CommandLine="copy $(TargetPath) ..\..\..\bin
+ CommandLine="copy "$(TargetPath)" ..\..\..\bin
"
- Outputs="..\..\..\bin\$(InputName).exe"/>
+ Outputs="..\..\..\bin\$(TargetFileName)"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
@@ -66,7 +66,13 @@
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
@@ -97,9 +103,9 @@
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"
- CommandLine="copy $(TargetPath) ..\..\..\bin
+ CommandLine="copy "$(TargetPath)" ..\..\..\bin
"
- Outputs="..\..\..\bin\$(InputName).exe"/>
+ Outputs="..\..\..\bin\$(TargetFileName)"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
@@ -127,9 +133,17 @@
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
+ <References>
+ </References>
<Files>
<Filter
Name="Source Files"
- Previous message: [sword-cvs] icu-sword/source/tools/gennames gennames.c,1.5,1.6 gennames.vcproj,1.1,1.2
- Next message: [sword-cvs] icu-sword/source/tools/gennorm gennorm.c,1.4,1.5 gennorm.vcproj,1.1,1.2 store.c,1.3,1.4
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]