From d90d9c7a579f1dbc014ba9d4b1e7fe51e7cab9ea Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 7 Oct 2006 15:53:27 +0000 Subject: [PATCH] Use bool. Rename minimal to find_minimal. --- lib/fstrcmp.c | 53 ++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/fstrcmp.c b/lib/fstrcmp.c index f428730db8..e042b5ffcc 100644 --- a/lib/fstrcmp.c +++ b/lib/fstrcmp.c @@ -49,6 +49,7 @@ #include "fstrcmp.h" #include +#include #include #include #include @@ -128,11 +129,11 @@ struct partition /* Midpoints of this partition. */ int xmid, ymid; - /* Nonzero if low half will be analyzed minimally. */ - int lo_minimal; + /* True if low half will be analyzed minimally. */ + bool lo_minimal; /* Likewise for high half. */ - int hi_minimal; + bool hi_minimal; }; @@ -140,7 +141,7 @@ struct partition diag - find diagonal path SYNOPSIS - int diag(int xoff, int xlim, int yoff, int ylim, int minimal, + int diag(int xoff, int xlim, int yoff, int ylim, bool find_minimal, struct partition *part, struct context *ctxt); DESCRIPTION @@ -152,7 +153,7 @@ struct partition edit-sequence. When the two searches meet, we have found the midpoint of the shortest edit sequence. - If MINIMAL is nonzero, find the minimal edit script regardless + If FIND_MINIMAL is true, find the minimal edit script regardless of expense. Otherwise, if the search is too expensive, use heuristics to stop the search and report a suboptimal answer. @@ -181,7 +182,7 @@ struct partition output. */ static OFFSET -diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, +diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, struct partition *part, struct context *ctxt) { OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */ @@ -197,7 +198,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, OFFSET bmin = bmid; OFFSET bmax = bmid; /* Limits of bottom-up search. */ OFFSET c; /* Cost. */ - int odd = (fmid - bmid) & 1; + bool odd = (fmid - bmid) & 1; /* * True if southeast corner is on an odd diagonal with respect @@ -208,9 +209,9 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, for (c = 1;; ++c) { OFFSET d; /* Active diagonal. */ - int big_snake; + bool big_snake; - big_snake = 0; + big_snake = false; /* Extend the top-down search by an edit step in each diagonal. */ if (fmin > dmin) fd[--fmin - 1] = -1; @@ -243,13 +244,13 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, ++y; } if (x - oldx > SNAKE_LIMIT) - big_snake = 1; + big_snake = true; fd[d] = x; if (odd && bmin <= d && d <= bmax && bd[d] <= x) { part->xmid = x; part->ymid = y; - part->lo_minimal = part->hi_minimal = 1; + part->lo_minimal = part->hi_minimal = true; return 2 * c - 1; } } @@ -284,18 +285,18 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, --y; } if (oldx - x > SNAKE_LIMIT) - big_snake = 1; + big_snake = true; bd[d] = x; if (!odd && fmin <= d && d <= fmax && x <= fd[d]) { part->xmid = x; part->ymid = y; - part->lo_minimal = part->hi_minimal = 1; + part->lo_minimal = part->hi_minimal = true; return 2 * c; } } - if (minimal) + if (find_minimal) continue; #ifdef MINUS_H_FLAG @@ -357,8 +358,8 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, } if (best > 0) { - part->lo_minimal = 1; - part->hi_minimal = 0; + part->lo_minimal = true; + part->hi_minimal = false; return 2 * c - 1; } best = 0; @@ -398,8 +399,8 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, } if (best > 0) { - part->lo_minimal = 0; - part->hi_minimal = 1; + part->lo_minimal = false; + part->hi_minimal = true; return 2 * c - 1; } } @@ -465,15 +466,15 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, { part->xmid = fxbest; part->ymid = fxybest - fxbest; - part->lo_minimal = 1; - part->hi_minimal = 0; + part->lo_minimal = true; + part->hi_minimal = false; } else { part->xmid = bxbest; part->ymid = bxybest - bxbest; - part->lo_minimal = 0; - part->hi_minimal = 1; + part->lo_minimal = false; + part->hi_minimal = true; } return 2 * c - 1; } @@ -485,7 +486,7 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, compareseq - find edit sequence SYNOPSIS - void compareseq(int xoff, int xlim, int yoff, int ylim, int minimal, + void compareseq(int xoff, int xlim, int yoff, int ylim, bool find_minimal, struct context *ctxt); DESCRIPTION @@ -498,11 +499,11 @@ diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal, Note that XLIM, YLIM are exclusive bounds. All character numbers are origin-0. - If MINIMAL is nonzero, find a minimal difference no matter how + If FIND_MINIMAL is nonzero, find a minimal difference no matter how expensive it is. */ static void -compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, int minimal, +compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, struct context *ctxt) { const ELEMENT *const xv = ctxt->string[0].data; /* Help the compiler. */ @@ -545,7 +546,7 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, int minimal, struct partition part; /* Find a point of correspondence in the middle of the strings. */ - c = diag (xoff, xlim, yoff, ylim, minimal, &part, ctxt); + c = diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt); if (c == 1) { #if 0 -- 2.39.5