diff --git a/ccstruct/polyaprx.cpp b/ccstruct/polyaprx.cpp index b9093af81466f7b338d66ef6de876678e68ec70d..8c92bc0a0ea1fd274ee1bdc4fab91bbc20ad452b 100644 --- a/ccstruct/polyaprx.cpp +++ b/ccstruct/polyaprx.cpp @@ -221,9 +221,9 @@ void fix2( //polygonal approx register EDGEPT *edgefix0, *edgefix1, *edgefix2, *edgefix3; edgept = start; /*start of loop */ - while ((edgept->flags[DIR] - edgept->prev->flags[DIR] + 1 & 7) < 3 + while (((edgept->flags[DIR] - edgept->prev->flags[DIR] + 1) & 7) < 3 && (dir1 = - edgept->prev->flags[DIR] - edgept->next->flags[DIR] & 7) != 2 + (edgept->prev->flags[DIR] - edgept->next->flags[DIR]) & 7) != 2 && dir1 != 6) edgept = edgept->next; /*find suitable start */ loopstart = edgept; /*remember start */ @@ -239,7 +239,7 @@ void fix2( //polygonal approx dir2 = edgept->flags[DIR]; /*2nd direction */ /*length in dir2 */ sum2 = edgept->flags[RUNLENGTH]; - if ((dir1 - dir2 + 1 & 7) < 3) { + if (((dir1 - dir2 + 1) & 7) < 3) { while (edgept->prev->flags[DIR] == edgept->next->flags[DIR]) { edgept = edgept->next; /*look at next */ if (edgept->flags[DIR] == dir1) @@ -260,11 +260,11 @@ void fix2( //polygonal approx linestart->flags[FLAGS] |= FIXED; } - if ((edgept->next->flags[DIR] - edgept->flags[DIR] + 1 & 7) >= 3 - || edgept->flags[DIR] == dir1 && sum1 >= sum2 - || (edgept->prev->flags[RUNLENGTH] < edgept->flags[RUNLENGTH] - || edgept->flags[DIR] == dir2 && sum2 >= sum1) - && linestart->next != edgept) + if (((edgept->next->flags[DIR] - edgept->flags[DIR] + 1) & 7) >= 3 + || (edgept->flags[DIR] == dir1 && sum1 >= sum2) + || ((edgept->prev->flags[RUNLENGTH] < edgept->flags[RUNLENGTH] + || (edgept->flags[DIR] == dir2 && sum2 >= sum1)) + && linestart->next != edgept)) edgept = edgept->next; } /*sharp bend */ @@ -295,7 +295,7 @@ void fix2( //polygonal approx && edgept->next->flags[FLAGS] & FIXED && (edgept->prev->flags[FLAGS] & FIXED) == 0 /*same pair of dirs */ && (edgept->next->next->flags[FLAGS] & FIXED) == 0 && edgept->prev->flags[DIR] == edgept->next->flags[DIR] && edgept->prev->prev->flags[DIR] == edgept->next->next->flags[DIR] - && (edgept->prev->flags[DIR] - edgept->flags[DIR] + 1 & 7) < 3) { + && ((edgept->prev->flags[DIR] - edgept->flags[DIR] + 1) & 7) < 3) { /*unfix it */ edgept->flags[FLAGS] &= ~FIXED; edgept->next->flags[FLAGS] &= ~FIXED; diff --git a/classify/mfoutline.cpp b/classify/mfoutline.cpp index a36af418ed146b12870c34fddc585bec4fcfed58..db10ccb2301978319a64fbc21e9c94f6e87b4cc3 100644 --- a/classify/mfoutline.cpp +++ b/classify/mfoutline.cpp @@ -291,13 +291,14 @@ LIST ConvertOutlines(TESSLINE *Outline, MFOUTLINE MFOutline; while (Outline != NULL) { - if (Outline->child != NULL) + if (Outline->child != NULL) { if (OutlineType == outer) ConvertedOutlines = ConvertOutlines (Outline->child, ConvertedOutlines, hole); else ConvertedOutlines = ConvertOutlines (Outline->child, ConvertedOutlines, outer); + } MFOutline = ConvertOutline (Outline); ConvertedOutlines = push (ConvertedOutlines, MFOutline); diff --git a/cutil/cutil.h b/cutil/cutil.h index c7bb9c2a5051f31d8bc0263bd5c9edd46b07d723..cf92faf6a5e504bf368578b13a17bd06edfb83cc 100644 --- a/cutil/cutil.h +++ b/cutil/cutil.h @@ -134,7 +134,7 @@ extern char_proc allocate; **********************************************************************/ #define strsave(s) \ - ((s) ? \ + ((s) != NULL ? \ ((char*) strcpy ((*allocate) (strlen(s)+1), s)) : \ (NULL)) diff --git a/cutil/tessarray.h b/cutil/tessarray.h index 8b5a38cead086e8a3b34de8e2eea4a98e0b08166..a56dfcdbce58fc640b6338a1a7d8f3e4ec9e4ab1 100644 --- a/cutil/tessarray.h +++ b/cutil/tessarray.h @@ -29,8 +29,8 @@ different popular data structures. A new "das" can be created by declaring a variable of type 'DAS' ******************************************************************************/ -#ifndef ARRAY_H -#define ARRAY_H +#ifndef TESSARRAY_H +#define TESSARRAY_H /* ---------------------------------------------------------------------- @@ -135,11 +135,11 @@ for (x=0; x < array_count (a); x++) /*---------------------------------------------------------------------- F u n c t i o n s ----------------------------------------------------------------------*/ -ARRAY array_insert(ARRAY array, int index, void *value); +ARRAY array_insert(ARRAY array, int index, void *value); -ARRAY array_new(int num); +ARRAY array_new(int num); -ARRAY array_push(ARRAY array, void *value); +ARRAY array_push(ARRAY array, void *value); /* #if defined(__STDC__) || defined(__cplusplus) diff --git a/dict/states.cpp b/dict/states.cpp index bd7fa9f85e6b1be118ab68544602c3cf0b49dbe0..a5f0db0a8cd6892a52cd462b7e5b2eadc4821ab9 100644 --- a/dict/states.cpp +++ b/dict/states.cpp @@ -290,7 +290,7 @@ int compare_states(STATE *true_state, STATE *this_state, int *blob_index) { return 2; if (*blob_index == 0) { if (bits_in_states > 32) { - for (mask = 1 << bits_in_states - 33; mask != 0; mask >>= 1) { + for (mask = 1 << (bits_in_states - 33); mask != 0; mask >>= 1) { if (this_state->part1 & mask) { if (true_state->part1 & mask) return 2; @@ -320,7 +320,7 @@ int compare_states(STATE *true_state, STATE *this_state, int *blob_index) { blob_count = 0; true_index = 0; if (bits_in_states > 32) { - for (mask = 1 << bits_in_states - 33; mask != 0; mask >>= 1) { + for (mask = 1 << (bits_in_states - 33); mask != 0; mask >>= 1) { if (true_state->part1 & mask) true_index++; if (this_state->part1 & mask) { diff --git a/image/imgtiff.cpp b/image/imgtiff.cpp index cc3a90b865bb484327d70480b7f3901bb8682c4c..4976c682f2a42cdae0296695bddbaaab59467895 100644 --- a/image/imgtiff.cpp +++ b/image/imgtiff.cpp @@ -203,7 +203,7 @@ INT8 open_tif_image( //read header *res = -1; resoffset = -1; if (read (fd, (char *) &filetype, sizeof filetype) != sizeof filetype - || filetype != INTEL && filetype != MOTO) { + || (filetype != INTEL && filetype != MOTO)) { BADIMAGEFORMAT.error ("read_tif_image", TESSLOG, "Filetype"); return -1; } @@ -577,7 +577,7 @@ INT8 write_tif_image( //write whole image resolution.top = res; resolution.bottom = 1; if (write (fd, (char *) &type, sizeof type) != sizeof type - || type != INTEL && type != MOTO) { + || (type != INTEL && type != MOTO)) { WRITEFAILED.error ("write_tif_image", TESSLOG, "Filetype"); return -1; } diff --git a/textord/pithsync.cpp b/textord/pithsync.cpp index 4990044da8100cfcfadef323862704083b1d13d6..e6f8147a7b7bce0ac86900b87058c0f85c9adef2 100644 --- a/textord/pithsync.cpp +++ b/textord/pithsync.cpp @@ -428,8 +428,8 @@ double check_pitch_sync2( //find segmentation if (cutpts[x - array_origin].index () + cutpts[x - array_origin].fake_count <= best_count + best_fake) { if (cutpts[x - array_origin].fake_count < best_fake - || cutpts[x - array_origin].fake_count == best_fake - && cutpts[x - array_origin].cost_function () < best_cost) { + || (cutpts[x - array_origin].fake_count == best_fake + && cutpts[x - array_origin].cost_function () < best_cost)) { best_fake = cutpts[x - array_origin].fake_count; best_cost = cutpts[x - array_origin].cost_function (); best_left_x = x; @@ -610,7 +610,7 @@ double check_pitch_sync3( //find segmentation mid_cut = TRUE; } } - if (start == 0 && end == 0 + if ((start == 0 && end == 0) || !textord_fast_pitch_test || (x - projection_left - start) % pitch <= end) cutpts[x - array_origin].assign (cutpts, array_origin, x, @@ -643,8 +643,8 @@ double check_pitch_sync3( //find segmentation if (cutpts[x - array_origin].index () + cutpts[x - array_origin].fake_count <= best_count + best_fake) { if (cutpts[x - array_origin].fake_count < best_fake - || cutpts[x - array_origin].fake_count == best_fake - && cutpts[x - array_origin].cost_function () < best_cost) { + || (cutpts[x - array_origin].fake_count == best_fake + && cutpts[x - array_origin].cost_function () < best_cost)) { best_fake = cutpts[x - array_origin].fake_count; best_cost = cutpts[x - array_origin].cost_function (); best_left_x = x; diff --git a/textord/pitsync1.cpp b/textord/pitsync1.cpp index fe1fc26da54c6b8de291958be473f9efca3e5537..e4ad5125eedc027762e797af4c821211ab3e6651 100644 --- a/textord/pitsync1.cpp +++ b/textord/pitsync1.cpp @@ -253,9 +253,9 @@ double check_pitch_sync( //find segmentation } if (x <= max_box.left () + pitch_error || x >= max_box.right () - pitch_error || x >= right_edge - || max_index < blob_count - 1 && x >= next_box.left () - || x - max_box.left () > pitch * pitsync_joined_edge - && max_box.right () - x > pitch * pitsync_joined_edge) { + || (max_index < blob_count - 1 && x >= next_box.left ()) + || (x - max_box.left () > pitch * pitsync_joined_edge + && max_box.right () - x > pitch * pitsync_joined_edge)) { // || projection->local_min(x)) if (x - max_box.left () > 0 && x - max_box.left () <= pitch_error) diff --git a/wordrec/chop.cpp b/wordrec/chop.cpp index f382ad6822314c2951f54f7d894354897c184d21..4951e29e6b791c0f9727e841f166dc2b15d91a37 100644 --- a/wordrec/chop.cpp +++ b/wordrec/chop.cpp @@ -281,9 +281,8 @@ EDGEPT *pick_close_point(EDGEPT *critical_point, if (this_distance <= *best_dist) { if (!(same_point (critical_point->pos, vertical_point->pos) || - same_point (critical_point->pos, vertical_point->next->pos) - || best_point != NULL - && same_point (best_point->pos, vertical_point->pos) || + same_point (critical_point->pos, vertical_point->next->pos) || + (best_point && same_point (best_point->pos, vertical_point->pos)) || is_exterior_point (critical_point, vertical_point))) { *best_dist = this_distance; best_point = vertical_point; diff --git a/wordrec/chopper.cpp b/wordrec/chopper.cpp index b65d20c2589b0558c1f0687fefd2543fa895ac5c..8991e78523e71aed8ec96fc0b91edcaa059bfb23 100644 --- a/wordrec/chopper.cpp +++ b/wordrec/chopper.cpp @@ -451,8 +451,8 @@ CHOICES_LIST chop_word_main(register TWERD *word, } if (!AcceptableChoice (char_choices, best_choice, raw_choice, &fixpt) - || (tester || trainer) - && strcmp (word->correct, class_string (best_choice))) { + || ((tester || trainer) + && strcmp (word->correct, class_string (best_choice)))) { did_chopping = 1; if (first_pass) words_chopped1++; @@ -477,10 +477,10 @@ CHOICES_LIST chop_word_main(register TWERD *word, if (chop_debug) print_seams ("Final seam list:", seam_list); - if (enable_assoc && - !AcceptableChoice (char_choices, best_choice, raw_choice, NULL) - || (tester || trainer) - && strcmp (word->correct, class_string (best_choice))) { + if ((enable_assoc && + !AcceptableChoice (char_choices, best_choice, raw_choice, NULL)) + || ((tester || trainer) + && strcmp (word->correct, class_string (best_choice)))) { ratings = word_associator (word->blobs, seam_list, &state, fx, best_choice, raw_choice, word->correct, /*0, */ &fixpt, @@ -606,11 +606,12 @@ INT16 select_blob_to_split(CHOICES_LIST char_choices, float rating_ceiling) { float worst = -MAX_FLOAT32; int worst_index = -1; - if (chop_debug) + if (chop_debug) { if (rating_ceiling < MAX_FLOAT32) cprintf ("rating_ceiling = %8.4f\n", rating_ceiling); - else - cprintf ("rating_ceiling = No Limit\n"); + else + cprintf ("rating_ceiling = No Limit\n"); + } for_each_choice(char_choices, x) { this_choice = (CHOICES) array_value (char_choices, x); diff --git a/wordrec/findseam.cpp b/wordrec/findseam.cpp index f50f101cdbd523e15f14afe2547b7ba07372f0d6..6bae5f930f07722f9178150c2d968a2df9995b5c 100644 --- a/wordrec/findseam.cpp +++ b/wordrec/findseam.cpp @@ -284,26 +284,38 @@ void combine_seam(SEAM_QUEUE seam_queue, SEAM_PILE seam_pile, SEAM *seam) { if (-SPLIT_CLOSENESS < dist && dist < SPLIT_CLOSENESS && seam->priority + this_one->priority < ok_split) { + INT16 split1_point1_y = this_one->split1->point1->pos.y; + INT16 split1_point2_y = this_one->split1->point2->pos.y; + INT16 split2_point1_y = 0; + INT16 split2_point2_y = 0; + if (this_one->split2) { + split2_point1_y = this_one->split2->point1->pos.y; + split2_point2_y = this_one->split2->point2->pos.y; + } if ( - /*!tessedit_fix_sideways_chops - || */ - (this_one->split1->point1->pos.y >= top1 - && this_one->split1->point2->pos.y >= top1 - || this_one->split1->point1->pos.y <= bottom1 - && this_one->split1->point2->pos.y <= bottom1) - && (this_one->split1->point1->pos.y >= top2 - && this_one->split1->point2->pos.y >= top2 - || this_one->split1->point1->pos.y <= bottom2 - && this_one->split1->point2->pos.y <= bottom2) - && (this_one->split2 == NULL - || (this_one->split2->point1->pos.y >= top1 - && this_one->split2->point2->pos.y >= top1 - || this_one->split2->point1->pos.y <= bottom1 - && this_one->split2->point2->pos.y <= bottom1) - && (this_one->split2->point1->pos.y >= top2 - && this_one->split2->point2->pos.y >= top2 - || this_one->split2->point1->pos.y <= bottom2 - && this_one->split2->point2->pos.y <= bottom2))) { + /*!tessedit_fix_sideways_chops || */ + ( + /* this_one->split1 always exists */ + ( + ((split1_point1_y >= top1 && split1_point2_y >= top1) || + (split1_point1_y <= bottom1 && split1_point2_y <= bottom1)) + && + ((split1_point1_y >= top2 && split1_point2_y >= top2) || + (split1_point1_y <= bottom2 && split1_point2_y <= bottom2)) + ) + ) + && + ( + this_one->split2 == NULL || + ( + ((split2_point1_y >= top1 && split2_point2_y >= top1) || + (split2_point1_y <= bottom1 && split2_point2_y <= bottom1)) + && + ((split2_point1_y >= top2 && split2_point2_y >= top2) || + (split2_point1_y <= bottom2 && split2_point2_y <= bottom2)) + ) + ) + ) { new_one = join_two_seams (seam, this_one); if (chop_debug > 1) print_seam ("Combo priority ", new_one); diff --git a/wordrec/outlines.cpp b/wordrec/outlines.cpp index 80108dc17add94bf95d816fb4b5254c718e94f1c..43869093e14e9c9711ef843cb64b4c852b047ab3 100644 --- a/wordrec/outlines.cpp +++ b/wordrec/outlines.cpp @@ -88,9 +88,9 @@ int is_crossed(TPOINT a0, TPOINT a1, TPOINT b0, TPOINT b1) { /*a1a0xa1b0=CROSS(a1a0,a1b0); */ a1a0xa1b0 = -CROSS (a1a0, b0a1); - return (b0a1xb0b1 > 0 && b0b1xb0a0 > 0 - || b0a1xb0b1 < 0 && b0b1xb0a0 < 0) - && (a1b1xa1a0 > 0 && a1a0xa1b0 > 0 || a1b1xa1a0 < 0 && a1a0xa1b0 < 0); + return ((b0a1xb0b1 > 0 && b0b1xb0a0 > 0) + || (b0a1xb0b1 < 0 && b0b1xb0a0 < 0)) + && ((a1b1xa1a0 > 0 && a1a0xa1b0 > 0) || (a1b1xa1a0 < 0 && a1a0xa1b0 < 0)); } diff --git a/wordrec/seam.cpp b/wordrec/seam.cpp index 24d5c036bb0b4f14cb43a57033465b7b3c416c89..dc17c9d92ba1f399789750c5408c077515d17e62 100644 --- a/wordrec/seam.cpp +++ b/wordrec/seam.cpp @@ -353,8 +353,8 @@ SEAM *join_two_seams(SEAM *seam1, SEAM *seam2) { assert(seam1 &&seam2); - if ((seam1->split3 == NULL && seam2->split2 == NULL || - seam1->split2 == NULL && seam2->split3 == NULL || + if (((seam1->split3 == NULL && seam2->split2 == NULL) || + (seam1->split2 == NULL && seam2->split3 == NULL) || seam1->split1 == NULL || seam2->split1 == NULL) && (!shared_split_points (seam1, seam2))) { clone_seam(result, seam1);