Skip to content

Commit

Permalink
Fix compiler warnings [-Wunused-but-set-variable]
Browse files Browse the repository at this point in the history
- Use conditional compilation for variables which might be useful for debugging.
- Remove all other unused variables.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed May 20, 2024
1 parent 1644205 commit d0b3d09
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,9 @@ char *TessBaseAPI::GetTSVText(int page_number) {
return nullptr;
}

#if !defined(NDEBUG)
int lcnt = 1, bcnt = 1, pcnt = 1, wcnt = 1;
#endif
int page_id = page_number + 1; // we use 1-based page numbers.

int page_num = page_id;
Expand Down Expand Up @@ -1484,6 +1486,7 @@ char *TessBaseAPI::GetTSVText(int page_number) {
tsv_str += "\t" + std::to_string(res_it->Confidence(RIL_WORD));
tsv_str += "\t";

#if !defined(NDEBUG)
// Increment counts if at end of block/paragraph/textline.
if (res_it->IsAtFinalElement(RIL_TEXTLINE, RIL_WORD)) {
lcnt++;
Expand All @@ -1494,13 +1497,16 @@ char *TessBaseAPI::GetTSVText(int page_number) {
if (res_it->IsAtFinalElement(RIL_BLOCK, RIL_WORD)) {
bcnt++;
}
#endif

do {
tsv_str += std::unique_ptr<const char[]>(res_it->GetUTF8Text(RIL_SYMBOL)).get();
res_it->Next(RIL_SYMBOL);
} while (!res_it->Empty(RIL_BLOCK) && !res_it->IsAtBeginningOf(RIL_WORD));
tsv_str += "\n"; // end of row
#if !defined(NDEBUG)
wcnt++;
#endif
}

char *ret = new char[tsv_str.length() + 1];
Expand Down
4 changes: 4 additions & 0 deletions src/ccmain/osdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ int orientation_and_script_detection(const char *filename, OSResults *osr,
// Returns a non-zero number of blobs if the page was successfully processed, or
// zero if the page had too few characters to be reliable
int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *tess) {
#if !defined(NDEBUG)
int blobs_total = 0;
#endif
TO_BLOCK_IT block_it;
block_it.set_to_list(port_blocks);

Expand All @@ -241,7 +243,9 @@ int os_detect(TO_BLOCK_LIST *port_blocks, OSResults *osr, tesseract::Tesseract *
BLOBNBOX *bbox = bbox_it.data();
C_BLOB *blob = bbox->cblob();
TBOX box = blob->bounding_box();
#if !defined(NDEBUG)
++blobs_total;
#endif

// Catch illegal value of box width and avoid division by zero.
if (box.width() == 0) {
Expand Down
3 changes: 0 additions & 3 deletions src/classify/normmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
tprintf("\nChar norm for class %s\n", unicharset.id_to_unichar(ClassId));
}

int ProtoId = 0;
iterate(Protos) {
auto Proto = reinterpret_cast<PROTOTYPE *>(Protos->first_node());
float Delta = feature.Params[CharNormY] - Proto->Mean[CharNormY];
Expand Down Expand Up @@ -145,8 +144,6 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
if (Match < BestMatch) {
BestMatch = Match;
}

ProtoId++;
}
return 1.0 - NormEvidenceOf(BestMatch);
} /* ComputeNormMatch */
Expand Down
6 changes: 0 additions & 6 deletions src/textord/topitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
int like_votes; // votes over page
int other_votes; // votes of unlike blocks
int block_index; // number of block
int row_index; // number of row
int maxwidth; // max pitch
TO_BLOCK_IT block_it = blocks; // block iterator
TO_BLOCK *block; // current block
Expand All @@ -172,7 +171,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
if (pb != nullptr && !pb->IsText()) {
continue; // Non text doesn't exist!
}
row_index = 1;
TO_ROW_IT row_it(block->get_rows());
for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
row = row_it.data();
Expand Down Expand Up @@ -226,7 +224,6 @@ void fix_row_pitch(TO_ROW *bad_row, // row to fix
other_votes--;
}
}
row_index++;
}
block_index++;
}
Expand Down Expand Up @@ -518,7 +515,6 @@ bool try_rows_fixed( // find line stats
bool testing_on // correct orientation
) {
TO_ROW *row; // current row
int32_t row_index; // row number.
int32_t def_fixed = 0; // counters
int32_t def_prop = 0;
int32_t maybe_fixed = 0;
Expand All @@ -529,7 +525,6 @@ bool try_rows_fixed( // find line stats
float lower, upper; // cluster thresholds
TO_ROW_IT row_it = block->get_rows();

row_index = 1;
for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
row = row_it.data();
ASSERT_HOST(row->xheight > 0);
Expand All @@ -541,7 +536,6 @@ bool try_rows_fixed( // find line stats
row->kern_size = lower;
}
}
row_index++;
}
count_block_votes(block, def_fixed, def_prop, maybe_fixed, maybe_prop, corr_fixed, corr_prop,
dunno);
Expand Down
4 changes: 4 additions & 0 deletions src/training/cntraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,19 @@ int main(int argc, char *argv[]) {
InitFeatureDefs(&FeatureDefs);

ParseArguments(&argc, &argv);
#if !defined(NDEBUG)
int num_fonts = 0;
#endif
for (const char *PageName = *++argv; PageName != nullptr; PageName = *++argv) {
printf("Reading %s ...\n", PageName);
FILE *TrainingPage = fopen(PageName, "rb");
ASSERT_HOST(TrainingPage);
if (TrainingPage) {
ReadTrainingSamples(FeatureDefs, PROGRAM_FEATURE_TYPE, 100, nullptr, TrainingPage, &CharList);
fclose(TrainingPage);
#if !defined(NDEBUG)
++num_fonts;
#endif
}
}
printf("Clustering ...\n");
Expand Down
4 changes: 4 additions & 0 deletions src/training/common/errorcounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void ErrorCounter::DebugNewErrors(ShapeClassifier *new_classifier, ShapeClassifi
ErrorCounter new_counter(new_classifier->GetUnicharset(), fontsize);
std::vector<UnicharRating> results;

#if !defined(NDEBUG)
int total_samples = 0;
#endif
int error_samples = 25;
int total_new_errors = 0;
// Iterate over all the samples, accumulating errors.
Expand Down Expand Up @@ -145,7 +147,9 @@ void ErrorCounter::DebugNewErrors(ShapeClassifier *new_classifier, ShapeClassifi
}
}
}
#if !defined(NDEBUG)
++total_samples;
#endif
}
tprintf("Total new errors = %d\n", total_new_errors);
}
Expand Down
2 changes: 0 additions & 2 deletions src/training/common/sampleiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ int SampleIterator::UniformSamples() {
// to 1. Returns the minimum assigned sample weight.
double SampleIterator::NormalizeSamples() {
double total_weight = 0.0;
int sample_count = 0;
for (Begin(); !AtEnd(); Next()) {
const TrainingSample &sample = GetSample();
total_weight += sample.weight();
++sample_count;
}
// Normalize samples.
double min_assigned_sample_weight = 1.0;
Expand Down

0 comments on commit d0b3d09

Please sign in to comment.