static char sccsid
[] = "@(#)alpha.seek.c 2.2 9/23/83";
# define nexttry ((high+low)/2)
/* alpha_seek(stream, word, s_size, fold)
seeks the first line in stream that is at least word.
assumes that stream is a sorted file of lines. (last char must be \n)
if fold, assumes that word is lowercase and folds stream to lowercase.
returns 1 if word = line, 0 o.w.
int alpha_seek(stream
, word
, s_size
, fold
)
{ long int high
, low
, mid
; /* point to beginning of a line in stream */
int ans
; /* line(low) < word <= line(high) */
/* initialize low (return if first line >= word) */
pos(low
); getline(stream
, line
);
if (fold
) foldline(line
);
{ pos(low
); return(ans
==0); }
/* initialize high to "line" after last line */
mid
= nextline(stream
, nexttry
);
if (fold
) foldline(line
);
if (strcmp(line
,word
) < 0) low
= mid
;
mid
= nextline(stream
, nexttry
);
/* linear search from low to high */
low
= nextline(stream
,low
);
if (fold
) foldline(line
);
if (low
==high
) return(0);
/* foldline(p): change all uppercase to lowercase in string p
{ if (isupper(*p
)) *p
= tolower(*p
);