Address issue 18: use fprinf instead of iostream for logging in the dynamic code.
https://code.google.com/p/cld2/issues/detail?id=18 git-svn-id: https://cld2.googlecode.com/svn/trunk@164 b252ecd4-b096-bf77-eb8e-91563289f87e
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include "cld2_dynamic_data.h"
|
||||
#include "integral_types.h"
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace CLD2DynamicData {
|
||||
@@ -29,12 +28,12 @@ bool mem_compare(const void* data1, const void* data2, const int length) {
|
||||
const unsigned char* raw2 = static_cast<const unsigned char*>(data2);
|
||||
for (int x=0; x<length; x++) {
|
||||
if (raw1[x] != raw2[x]) {
|
||||
std::cerr << "mem difference at data[" << x << "]: decimal " << (unsigned int) raw1[x] << " != decimal " << (unsigned int) raw2[x] << std::endl;
|
||||
fprintf(stderr, "mem difference at data[%d]: decimal %d != decimal %d\n",
|
||||
x, (unsigned int) raw1[x], (unsigned int) raw2[x]);
|
||||
for (int y=std::max(0,x-5); y<length && y<=x+5; y++) {
|
||||
std::cerr << "[" << y << "]: " << (unsigned int) raw1[y]
|
||||
<< " <-> " << (unsigned int) raw2[y]
|
||||
<< ( x == y ? " [FIRST ERROR DETECTED HERE] " : "")
|
||||
<< std::endl;
|
||||
fprintf(stderr, "[%d]: %d <-> %d%s\n",
|
||||
y, (unsigned int) raw1[y], (unsigned int) raw2[y],
|
||||
( x == y ? " [FIRST ERROR DETECTED HERE] " : ""));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -52,27 +51,27 @@ void dumpHeader(FileHeader* header) {
|
||||
char safeString[DATA_FILE_MARKER_LENGTH + 1];
|
||||
memcpy(safeString, header->sanityString, DATA_FILE_MARKER_LENGTH);
|
||||
safeString[DATA_FILE_MARKER_LENGTH] = 0;
|
||||
std::cout << "sanityString: " << safeString << std::endl;
|
||||
std::cout << "totalFileSizeBytes: " << header->totalFileSizeBytes << std::endl;
|
||||
std::cout << "utf8PropObj_state0: " << header->utf8PropObj_state0 << std::endl;
|
||||
std::cout << "utf8PropObj_state0_size: " << header->utf8PropObj_state0_size << std::endl;
|
||||
std::cout << "utf8PropObj_total_size: " << header->utf8PropObj_total_size << std::endl;
|
||||
std::cout << "utf8PropObj_max_expand: " << header->utf8PropObj_max_expand << std::endl;
|
||||
std::cout << "utf8PropObj_entry_shift: " << header->utf8PropObj_entry_shift << std::endl;
|
||||
std::cout << "utf8PropObj_bytes_per_entry: " << header->utf8PropObj_bytes_per_entry << std::endl;
|
||||
std::cout << "utf8PropObj_losub: " << header->utf8PropObj_losub << std::endl;
|
||||
std::cout << "utf8PropObj_hiadd: " << header->utf8PropObj_hiadd << std::endl;
|
||||
std::cout << "startOf_utf8PropObj_state_table: " << header->startOf_utf8PropObj_state_table << std::endl;
|
||||
std::cout << "lengthOf_utf8PropObj_state_table: " << header->lengthOf_utf8PropObj_state_table << std::endl;
|
||||
std::cout << "startOf_utf8PropObj_remap_base: " << header->startOf_utf8PropObj_remap_base << std::endl;
|
||||
std::cout << "lengthOf_utf8PropObj_remap_base: " << header->lengthOf_utf8PropObj_remap_base << std::endl;
|
||||
std::cout << "startOf_utf8PropObj_remap_string: " << header->startOf_utf8PropObj_remap_string << std::endl;
|
||||
std::cout << "lengthOf_utf8PropObj_remap_string: " << header->lengthOf_utf8PropObj_remap_string << std::endl;
|
||||
std::cout << "startOf_utf8PropObj_fast_state: " << header->startOf_utf8PropObj_fast_state << std::endl;
|
||||
std::cout << "lengthOf_utf8PropObj_fast_state: " << header->lengthOf_utf8PropObj_fast_state << std::endl;
|
||||
std::cout << "startOf_kAvgDeltaOctaScore: " << header->startOf_kAvgDeltaOctaScore << std::endl;
|
||||
std::cout << "lengthOf_kAvgDeltaOctaScore: " << header->lengthOf_kAvgDeltaOctaScore << std::endl;
|
||||
std::cout << "numTablesEncoded: " << header->numTablesEncoded << std::endl;
|
||||
fprintf(stdout, "sanityString: %s\n", safeString);
|
||||
fprintf(stdout, "totalFileSizeBytes: %d\n", header->totalFileSizeBytes);
|
||||
fprintf(stdout, "utf8PropObj_state0: %d\n", header->utf8PropObj_state0);
|
||||
fprintf(stdout, "utf8PropObj_state0_size: %d\n", header->utf8PropObj_state0_size);
|
||||
fprintf(stdout, "utf8PropObj_total_size: %d\n", header->utf8PropObj_total_size);
|
||||
fprintf(stdout, "utf8PropObj_max_expand: %d\n", header->utf8PropObj_max_expand);
|
||||
fprintf(stdout, "utf8PropObj_entry_shift: %d\n", header->utf8PropObj_entry_shift);
|
||||
fprintf(stdout, "utf8PropObj_bytes_per_entry: %d\n", header->utf8PropObj_bytes_per_entry);
|
||||
fprintf(stdout, "utf8PropObj_losub: %d\n", header->utf8PropObj_losub);
|
||||
fprintf(stdout, "utf8PropObj_hiadd: %d\n", header->utf8PropObj_hiadd);
|
||||
fprintf(stdout, "startOf_utf8PropObj_state_table: %d\n", header->startOf_utf8PropObj_state_table);
|
||||
fprintf(stdout, "lengthOf_utf8PropObj_state_table: %d\n", header->lengthOf_utf8PropObj_state_table);
|
||||
fprintf(stdout, "startOf_utf8PropObj_remap_base: %d\n", header->startOf_utf8PropObj_remap_base);
|
||||
fprintf(stdout, "lengthOf_utf8PropObj_remap_base: %d\n", header->lengthOf_utf8PropObj_remap_base);
|
||||
fprintf(stdout, "startOf_utf8PropObj_remap_string: %d\n", header->startOf_utf8PropObj_remap_string);
|
||||
fprintf(stdout, "lengthOf_utf8PropObj_remap_string: %d\n", header->lengthOf_utf8PropObj_remap_string);
|
||||
fprintf(stdout, "startOf_utf8PropObj_fast_state: %d\n", header->startOf_utf8PropObj_fast_state);
|
||||
fprintf(stdout, "lengthOf_utf8PropObj_fast_state: %d\n", header->lengthOf_utf8PropObj_fast_state);
|
||||
fprintf(stdout, "startOf_kAvgDeltaOctaScore: %d\n", header->startOf_kAvgDeltaOctaScore);
|
||||
fprintf(stdout, "lengthOf_kAvgDeltaOctaScore: %d\n", header->lengthOf_kAvgDeltaOctaScore);
|
||||
fprintf(stdout, "numTablesEncoded: %d\n", header->numTablesEncoded);
|
||||
|
||||
const char* tableNames[7];
|
||||
tableNames[0]="unigram_compat_obj";
|
||||
@@ -86,27 +85,27 @@ void dumpHeader(FileHeader* header) {
|
||||
for (int x=0; x<header->numTablesEncoded; x++) {
|
||||
TableHeader& tHeader = header->tableHeaders[x];
|
||||
|
||||
std::cout << "Table " << (x+1) << ": (" << tableNames[x] << ")" << std::endl;
|
||||
std::cout << " kCLDTableSizeOne: " << tHeader.kCLDTableSizeOne << std::endl;
|
||||
std::cout << " kCLDTableSize: " << tHeader.kCLDTableSize << std::endl;
|
||||
std::cout << " kCLDTableKeyMask: " << tHeader.kCLDTableKeyMask << std::endl;
|
||||
std::cout << " kCLDTableBuildDate: " << tHeader.kCLDTableBuildDate << std::endl;
|
||||
std::cout << " startOf_kCLDTable: " << tHeader.startOf_kCLDTable << std::endl;
|
||||
std::cout << " lengthOf_kCLDTable: " << tHeader.lengthOf_kCLDTable << std::endl;
|
||||
std::cout << " startOf_kCLDTableInd: " << tHeader.startOf_kCLDTableInd << std::endl;
|
||||
std::cout << " lengthOf_kCLDTableInd: " << tHeader.lengthOf_kCLDTableInd << std::endl;
|
||||
std::cout << " startOf_kRecognizedLangScripts: " << tHeader.startOf_kRecognizedLangScripts << std::endl;
|
||||
std::cout << " lengthOf_kRecognizedLangScripts: " << tHeader.lengthOf_kRecognizedLangScripts << std::endl;
|
||||
fprintf(stdout, "Table %d: (%s)\n", (x+1), tableNames[x]);;
|
||||
fprintf(stdout, " kCLDTableSizeOne: %d\n", tHeader.kCLDTableSizeOne);
|
||||
fprintf(stdout, " kCLDTableSize: %d\n", tHeader.kCLDTableSize);
|
||||
fprintf(stdout, " kCLDTableKeyMask: %d\n", tHeader.kCLDTableKeyMask);
|
||||
fprintf(stdout, " kCLDTableBuildDate: %d\n", tHeader.kCLDTableBuildDate);
|
||||
fprintf(stdout, " startOf_kCLDTable: %d\n", tHeader.startOf_kCLDTable);
|
||||
fprintf(stdout, " lengthOf_kCLDTable: %d\n", tHeader.lengthOf_kCLDTable);
|
||||
fprintf(stdout, " startOf_kCLDTableInd: %d\n", tHeader.startOf_kCLDTableInd);
|
||||
fprintf(stdout, " lengthOf_kCLDTableInd: %d\n", tHeader.lengthOf_kCLDTableInd);
|
||||
fprintf(stdout, " startOf_kRecognizedLangScripts: %d\n", tHeader.startOf_kRecognizedLangScripts);
|
||||
fprintf(stdout, " lengthOf_kRecognizedLangScripts: %d\n", tHeader.lengthOf_kRecognizedLangScripts);
|
||||
}
|
||||
}
|
||||
|
||||
#define CHECK_EQUALS(name) if (loadedData->name != realData->name) {\
|
||||
std::cerr << #name << ": " << loadedData->name << " != " << realData->name << std::endl;\
|
||||
fprintf(stderr, "%s: %d != %d\n", #name, loadedData->name, realData->name);\
|
||||
return false;\
|
||||
}
|
||||
|
||||
#define CHECK_MEM_EQUALS(name,size) if (!mem_compare(loadedData->name,realData->name,size)) {\
|
||||
std::cerr << #name << ": data mismatch." << std::endl;\
|
||||
fprintf(stderr, "%s: data mismatch.\n", #name);\
|
||||
return false;\
|
||||
}
|
||||
|
||||
@@ -147,26 +146,26 @@ bool verify(const CLD2::ScoringTables* realData,
|
||||
|
||||
if (loadedData->unigram_obj->fast_state == NULL) {
|
||||
if (realData->unigram_obj->fast_state != NULL) {
|
||||
std::cerr << "unigram_obj->fast_state is missing." << std::endl;
|
||||
fprintf(stderr, "unigram_obj->fast_state is missing.\n");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (realData->unigram_obj->fast_state == NULL) {
|
||||
std::cerr << "unigram_obj->fast_state shouldn't be present." << std::endl;
|
||||
fprintf(stderr, "unigram_obj->fast_state shouldn't be present.\n");
|
||||
return false;
|
||||
}
|
||||
CHECK_MEM_EQUALS(unigram_obj->fast_state, strlen(
|
||||
reinterpret_cast<const char*>(realData->unigram_obj->fast_state)) + 1); // null terminator included
|
||||
}
|
||||
if (DEBUG) std::cout << "verified." << std::endl;
|
||||
if (DEBUG) fprintf(stdout, "verified.\n");
|
||||
|
||||
if (DEBUG) std::cout << "Verifying kExpectedScore... ";
|
||||
if (DEBUG) fprintf(stdout, "Verifying kExpectedScore... ");
|
||||
CHECK_MEM_EQUALS(kExpectedScore, realSupplement->lengthOf_kAvgDeltaOctaScore);
|
||||
if (DEBUG) std::cout << "verified." << std::endl;
|
||||
if (DEBUG) fprintf(stdout, "verified.\n");
|
||||
|
||||
// 3. Each table
|
||||
for (int x=0; x<NUM_TABLES; x++) {
|
||||
if (DEBUG) std::cout << "Verifying table " << (x+1) << "... ";
|
||||
if (DEBUG) fprintf(stdout, "Verifying table %d... ", x+1);
|
||||
const CLD2::CLD2TableSummary* realData = realTableSummaries[x];
|
||||
const CLD2::CLD2TableSummary* loadedData = loadedTableSummaries[x];
|
||||
// We need to calculate the table lengths to do the memcmp
|
||||
@@ -185,9 +184,9 @@ bool verify(const CLD2::ScoringTables* realData,
|
||||
CHECK_MEM_EQUALS(kCLDTable, tableSizeBytes);
|
||||
CHECK_MEM_EQUALS(kCLDTableInd, indirectTableSizeBytes);
|
||||
CHECK_MEM_EQUALS(kRecognizedLangScripts, recognizedScriptsSizeBytes);
|
||||
if (DEBUG) std::cout << "verified." << std::endl;
|
||||
if (DEBUG) fprintf(stdout, "verified.\n");
|
||||
}
|
||||
if (DEBUG) std::cout << "All data verified successfully." << std::endl;
|
||||
if (DEBUG) fprintf(stdout, "All data verified successfully.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -205,18 +204,15 @@ bool isLittleEndian() {
|
||||
|
||||
bool coreAssumptionsOk() {
|
||||
if (sizeof(CLD2::uint8) != 1) {
|
||||
std::cerr << "uint8 is " << (sizeof(CLD2::uint8) * 8)
|
||||
<< " bits instead of 8!" << std::endl;
|
||||
fprintf(stderr, "uint8 is %d bits instead of 8!\n", (int) (sizeof(CLD2::uint8) * 8));
|
||||
return false;
|
||||
}
|
||||
if (sizeof(CLD2::uint16) != 2) {
|
||||
std::cerr << "uint16 is " << (sizeof(CLD2::uint16) * 8)
|
||||
<< " bits instead of 16!" << std::endl;
|
||||
fprintf(stderr, "uint16 is %d bits instead of 16!\n", (int) (sizeof(CLD2::uint16) * 8));
|
||||
return false;
|
||||
}
|
||||
if (sizeof(CLD2::uint32) != 4) {
|
||||
std::cerr << "uint32 is " << (sizeof(CLD2::uint32) * 8)
|
||||
<< " bits instead of 32!" << std::endl;
|
||||
fprintf(stderr, "uint32 is %d bits instead of 32!\n", (int) (sizeof(CLD2::uint32) * 8));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "cld2_dynamic_data.h"
|
||||
#include "cld2_dynamic_data_extractor.h"
|
||||
#include "cld2_dynamic_data_loader.h" // for verifying the written data
|
||||
@@ -31,7 +29,7 @@ void setDebug(int debug) {
|
||||
int advance(FILE* f, CLD2::uint32 position) {
|
||||
const char ZERO = 0;
|
||||
int pad = position - ftell(f);
|
||||
if (DEBUG) cout << " Adding " << pad << " bytes of padding" << endl;
|
||||
if (DEBUG) fprintf(stdout, " Adding %d bytes of padding\n", pad);
|
||||
while (pad-- > 0) {
|
||||
fwrite(&ZERO,1,1,f);
|
||||
}
|
||||
@@ -39,9 +37,9 @@ int advance(FILE* f, CLD2::uint32 position) {
|
||||
}
|
||||
|
||||
void writeChunk(FILE *f, const void* data, CLD2::uint32 startAt, CLD2::uint32 length) {
|
||||
if (DEBUG) cout << "Write chunk @" << startAt << ", len=" << length << endl;
|
||||
if (DEBUG) fprintf(stdout, " Write chunk @%d, len=%d\n", startAt, length);
|
||||
advance(f, startAt);
|
||||
if (DEBUG) cout << " Writing " << length << " bytes of data" << endl;
|
||||
if (DEBUG) fprintf(stdout, " Writing %d bytes of data", length);;
|
||||
fwrite(data, 1, length, f);
|
||||
}
|
||||
|
||||
@@ -200,7 +198,7 @@ void initTableHeaders(const CLD2::CLD2TableSummary** summaries,
|
||||
// boundaries for maximum efficiency.
|
||||
void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
CLD2::uint32 totalPadding = 0;
|
||||
if (DEBUG) { std::cout << "Align for " << (alignment*8) << " bits." << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Align for %d bits.\n", (alignment*8)); }
|
||||
CLD2::uint32 headerSize = CLD2DynamicData::calculateHeaderSize(
|
||||
header->numTablesEncoded);
|
||||
CLD2::uint32 offset = headerSize;
|
||||
@@ -209,7 +207,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int stateTablePad = alignment - (offset % alignment);
|
||||
if (stateTablePad == alignment) stateTablePad = 0;
|
||||
totalPadding += stateTablePad;
|
||||
if (DEBUG) { std::cout << "Alignment for stateTable adjusted by " << stateTablePad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for stateTable adjusted by %d\n", stateTablePad); }
|
||||
offset += stateTablePad;
|
||||
header->startOf_utf8PropObj_state_table = offset;
|
||||
offset += header->lengthOf_utf8PropObj_state_table;
|
||||
@@ -219,7 +217,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int remapPad = alignment - (offset % alignment);
|
||||
if (remapPad == alignment) remapPad = 0;
|
||||
totalPadding += remapPad;
|
||||
if (DEBUG) { std::cout << "Alignment for remap adjusted by " << remapPad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for remap adjusted by %d\n", remapPad); }
|
||||
offset += remapPad;
|
||||
header->startOf_utf8PropObj_remap_base = offset;
|
||||
offset += header->lengthOf_utf8PropObj_remap_base;
|
||||
@@ -229,7 +227,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int remapStringPad = alignment - (offset % alignment);
|
||||
if (remapStringPad == alignment) remapStringPad = 0;
|
||||
totalPadding += remapStringPad;
|
||||
if (DEBUG) { std::cout << "Alignment for remapString adjusted by " << remapStringPad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for remapString adjusted by %d\n", remapStringPad); }
|
||||
offset += remapStringPad;
|
||||
header->startOf_utf8PropObj_remap_string = offset;
|
||||
offset += header->lengthOf_utf8PropObj_remap_string; // null terminator already counted in initUtf8Headers
|
||||
@@ -239,7 +237,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int fastStatePad = alignment - (offset % alignment);
|
||||
if (fastStatePad == alignment) fastStatePad = 0;
|
||||
totalPadding += fastStatePad;
|
||||
if (DEBUG) { std::cout << "Alignment for fastState adjusted by " << fastStatePad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for fastState adjusted by %d\n", fastStatePad); }
|
||||
offset += fastStatePad;
|
||||
if (header->lengthOf_utf8PropObj_fast_state > 0) {
|
||||
header->startOf_utf8PropObj_fast_state = offset;
|
||||
@@ -253,7 +251,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int deltaOctaPad = alignment - (offset % alignment);
|
||||
if (deltaOctaPad == alignment) deltaOctaPad = 0;
|
||||
totalPadding += deltaOctaPad;
|
||||
if (DEBUG) { std::cout << "Alignment for deltaOctaScore adjusted by " << deltaOctaPad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for deltaOctaScore adjusted by %d\n", deltaOctaPad); }
|
||||
offset += deltaOctaPad;
|
||||
header->startOf_kAvgDeltaOctaScore = offset;
|
||||
offset += header->lengthOf_kAvgDeltaOctaScore;
|
||||
@@ -264,7 +262,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int tablePad = alignment - (offset % alignment);
|
||||
if (tablePad == alignment) tablePad = 0;
|
||||
totalPadding += tablePad;
|
||||
if (DEBUG) { std::cout << "Alignment for table " << x << " adjusted by " << tablePad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for table %d adjusted by %d\n", x, tablePad); }
|
||||
offset += tablePad;
|
||||
tableHeader.startOf_kCLDTable = offset;
|
||||
offset += tableHeader.lengthOf_kCLDTable;
|
||||
@@ -272,7 +270,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int indirectPad = alignment - (offset % alignment);
|
||||
if (indirectPad == alignment) indirectPad = 0;
|
||||
totalPadding += indirectPad;
|
||||
if (DEBUG) { std::cout << "Alignment for tableInd " << x << " adjusted by " << indirectPad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for tableInd %d adjusted by %d\n", x, indirectPad); }
|
||||
offset += indirectPad;
|
||||
tableHeader.startOf_kCLDTableInd = offset;
|
||||
offset += tableHeader.lengthOf_kCLDTableInd;
|
||||
@@ -280,7 +278,7 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
int scriptsPad = alignment - (offset % alignment);
|
||||
if (scriptsPad == alignment) scriptsPad = 0;
|
||||
totalPadding += scriptsPad;
|
||||
if (DEBUG) { std::cout << "Alignment for scriptsPad " << x << " adjusted by " << scriptsPad << std::endl; }
|
||||
if (DEBUG) { fprintf(stdout, "Alignment for scriptsPad %d adjusted by %d", x, scriptsPad); }
|
||||
offset += scriptsPad;
|
||||
tableHeader.startOf_kRecognizedLangScripts = offset;
|
||||
offset += tableHeader.lengthOf_kRecognizedLangScripts; // null terminator already counted in initTableHeaders
|
||||
@@ -291,53 +289,44 @@ void alignAll(CLD2DynamicData::FileHeader* header, const int alignment) {
|
||||
header->totalFileSizeBytes = offset;
|
||||
|
||||
if (DEBUG) {
|
||||
std::cout << "Data aligned." << std::endl;
|
||||
std::cout << "Header size: " << headerSize << " bytes " << std::endl;
|
||||
std::cout << "Data size: " << (offset - totalPadding) << " bytes" << std::endl;
|
||||
std::cout << "Padding size: " << totalPadding << " bytes" << std::endl;
|
||||
|
||||
std::cout << " cld_generated_CjkUni_obj: " << (
|
||||
fprintf(stdout, "Data aligned.\n");
|
||||
fprintf(stdout, "Header size: %d bytes\n", headerSize);
|
||||
fprintf(stdout, "Data size: %d bytes\n", (offset - totalPadding));
|
||||
fprintf(stdout, "Padding size: %d bytes\n", totalPadding);
|
||||
fprintf(stdout, " cld_generated_CjkUni_obj: %d bytes\n", (
|
||||
header->lengthOf_utf8PropObj_state_table +
|
||||
header->lengthOf_utf8PropObj_remap_string +
|
||||
header->lengthOf_utf8PropObj_fast_state)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kAvgDeltaOctaScore: "
|
||||
<< header->lengthOf_kAvgDeltaOctaScore << " bytes " << std::endl;
|
||||
std::cout << " kCjkCompat_obj: " << (
|
||||
header->lengthOf_utf8PropObj_fast_state));
|
||||
fprintf(stdout, " kAvgDeltaOctaScore: %d bytes\n",
|
||||
header->lengthOf_kAvgDeltaOctaScore);
|
||||
fprintf(stdout, " kCjkCompat_obj: %d bytes\n", (
|
||||
header->tableHeaders[0].lengthOf_kCLDTable +
|
||||
header->tableHeaders[0].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[0].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kCjkDeltaBi_obj: " << (
|
||||
header->tableHeaders[0].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kCjkDeltaBi_obj: %d bytes\n", (
|
||||
header->tableHeaders[1].lengthOf_kCLDTable +
|
||||
header->tableHeaders[1].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[1].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kDistinctBiTable_obj: " << (
|
||||
header->tableHeaders[1].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kDistinctBiTable_obj: %d bytes\n", (
|
||||
header->tableHeaders[2].lengthOf_kCLDTable +
|
||||
header->tableHeaders[2].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[2].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kQuad_obj: " << (
|
||||
header->tableHeaders[2].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kQuad_obj: %d bytes\n", (
|
||||
header->tableHeaders[3].lengthOf_kCLDTable +
|
||||
header->tableHeaders[3].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[3].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kQuad_obj2: " << (
|
||||
header->tableHeaders[3].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kQuad_obj2: %d bytes\n", (
|
||||
header->tableHeaders[4].lengthOf_kCLDTable +
|
||||
header->tableHeaders[4].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[4].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kDeltaOcta_obj: " << (
|
||||
header->tableHeaders[4].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kDeltaOcta_obj: %d bytes\n", (
|
||||
header->tableHeaders[5].lengthOf_kCLDTable +
|
||||
header->tableHeaders[5].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[5].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
std::cout << " kDistinctOcta_obj: " << (
|
||||
header->tableHeaders[5].lengthOf_kRecognizedLangScripts + 1));
|
||||
fprintf(stdout, " kDistinctOcta_obj: %d bytes\n", (
|
||||
header->tableHeaders[6].lengthOf_kCLDTable +
|
||||
header->tableHeaders[6].lengthOf_kCLDTableInd +
|
||||
header->tableHeaders[6].lengthOf_kRecognizedLangScripts + 1)
|
||||
<< " bytes " << std::endl;
|
||||
header->tableHeaders[6].lengthOf_kRecognizedLangScripts + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,6 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
@@ -69,7 +68,7 @@ CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer,
|
||||
header->sanityString,
|
||||
CLD2DynamicData::DATA_FILE_MARKER,
|
||||
CLD2DynamicData::DATA_FILE_MARKER_LENGTH)) {
|
||||
std::cerr << "Malformed header: bad file marker!" << std::endl;
|
||||
fprintf(stderr, "Malformed header: bad file marker!\n");
|
||||
delete header;
|
||||
return NULL;
|
||||
}
|
||||
@@ -114,7 +113,7 @@ CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer,
|
||||
// Confirm header size is correct.
|
||||
int expectedHeaderSize = CLD2DynamicData::calculateHeaderSize(header->numTablesEncoded);
|
||||
if (expectedHeaderSize != bytesRead) {
|
||||
std::cerr << "Header size mismatch! Expected " << expectedHeaderSize << ", but read " << bytesRead << std::endl;
|
||||
fprintf(stderr, "Header size mismatch! Expected %d, but read %d\n", expectedHeaderSize, bytesRead);
|
||||
delete header;
|
||||
delete[] tableHeaders;
|
||||
return NULL;
|
||||
@@ -131,7 +130,7 @@ CLD2DynamicData::FileHeader* loadInternal(FILE* inFile, const void* basePointer,
|
||||
}
|
||||
|
||||
if (actualSize != header->totalFileSizeBytes) {
|
||||
std::cerr << "File size mismatch! Expected " << header->totalFileSizeBytes << ", but found " << actualSize << std::endl;
|
||||
fprintf(stderr, "File size mismatch! Expected %d, but found %d\n", header->totalFileSizeBytes, actualSize);
|
||||
delete header;
|
||||
delete[] tableHeaders;
|
||||
return NULL;
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
@@ -52,11 +51,11 @@ namespace CLD2 {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (!CLD2DynamicData::isLittleEndian()) {
|
||||
std::cerr << "System is big-endian: currently not supported." << std::endl;
|
||||
fprintf(stderr, "System is big-endian: currently not supported.\n");
|
||||
return -1;
|
||||
}
|
||||
if (!CLD2DynamicData::coreAssumptionsOk()) {
|
||||
std::cerr << "Core assumptions violated, unsafe to continue." << std::endl;
|
||||
fprintf(stderr, "Core assumptions violated, unsafe to continue.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
@@ -101,22 +100,22 @@ Usage:\n\
|
||||
if (i < argc - 1) {
|
||||
fileName = argv[++i];
|
||||
} else {
|
||||
std::cerr << "missing file name argument" << std::endl << std::endl;
|
||||
std::cerr << USAGE;
|
||||
fprintf(stderr, "Missing file name argument\n\n");
|
||||
fprintf(stderr, "%s", USAGE);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "--help") == 0) {
|
||||
std::cout << USAGE;
|
||||
fprintf(stdout, "%s", USAGE);
|
||||
return 0;
|
||||
} else {
|
||||
std::cerr << "Unsupported option: " << argv[i] << std::endl << std::endl;
|
||||
std::cerr << USAGE;
|
||||
fprintf(stderr, "Unsupported option: %s\n\n", argv[i]);
|
||||
fprintf(stderr, "%s", USAGE);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == 0) {
|
||||
std::cerr << USAGE;
|
||||
fprintf(stderr, "%s", USAGE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -152,7 +151,7 @@ Usage:\n\
|
||||
} else if (mode == 3) { // head
|
||||
CLD2DynamicData::FileHeader* header = CLD2DynamicDataLoader::loadHeaderFromFile(fileName);
|
||||
if (header == NULL) {
|
||||
std::cerr << "Cannot read header from file: " << fileName << std::endl;
|
||||
fprintf(stderr, "Cannot read header from file: %s\n", fileName);
|
||||
return -1;
|
||||
}
|
||||
CLD2DynamicData::dumpHeader(header);
|
||||
@@ -166,7 +165,7 @@ Usage:\n\
|
||||
CLD2::ScoringTables* loadedData = CLD2DynamicDataLoader::loadDataFile(fileName, &mmapAddress, &mmapLength);
|
||||
|
||||
if (loadedData == NULL) {
|
||||
std::cerr << "Failed to read data file: " << fileName << std::endl;
|
||||
fprintf(stderr, "Failed to read data file: %s\n", fileName);
|
||||
return -1;
|
||||
}
|
||||
bool result = CLD2DynamicData::verify(
|
||||
@@ -175,10 +174,10 @@ Usage:\n\
|
||||
static_cast<const CLD2::ScoringTables*>(loadedData));
|
||||
CLD2DynamicDataLoader::unloadDataFile(&loadedData, &mmapAddress, &mmapLength);
|
||||
if (loadedData != NULL || mmapAddress != NULL || mmapLength != 0) {
|
||||
std::cerr << "Warning: failed to clean up memory for ScoringTables." << std::endl;
|
||||
fprintf(stderr, "Warning: failed to clean up memory for ScoringTables.\n");
|
||||
}
|
||||
if (!result) {
|
||||
std::cerr << "Verification failed!" << std::endl;
|
||||
fprintf(stderr, "Verification failed!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user