Made xcharof non-recursive (same algorithm)

This commit is contained in:
Kris Maglione 2006-07-01 06:52:44 -04:00
parent 207aac30fe
commit 4a85fd4aa0
1 changed files with 10 additions and 9 deletions

View File

@ -116,17 +116,18 @@ blitz_ispointinrect(int x, int y, XRectangle * r)
static char *
xcharof(BlitzInput *i, int x, char *start, unsigned int len)
{
unsigned int piv, tw;
unsigned int tw;
if(!(piv = len / 2))
return start; /* found */
while((len /= 2)) {
tw = blitz_textwidth_l(i->font, start, len);
tw = blitz_textwidth_l(i->font, start, piv);
if(x < tw)
return xcharof(i, x, start, piv);
else
return xcharof(i, x - tw, start + piv, strlen(start + piv));
if(x >= tw) {
x -= tw;
start += len;
len = strlen(start);
}
}
return start; /* found */
}
static char *