1 /*
2  * Copyright (c) 1991-1994  Sony Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Except as contained in this notice, the name of Sony Corporation
24  * shall not be used in advertising or otherwise to promote the sale, use
25  * or other dealings in this Software without prior written authorization
26  * from Sony Corporation.
27  *
28  */
29 
30 /*
31  * $SonyRCSfile: srchidx.c,v $
32  * $SonyRevision: 1.1 $
33  * $SonyDate: 1994/06/03 08:02:29 $
34  */
35 
36 
37 
38 #include "sj_kcnv.h"
39 
40 #include "sj_kanakan.h"
41 
42 TypeDicSeg
srchidx(TypeDicSeg low,Int len)43 srchidx(TypeDicSeg low, Int len)
44 {
45 	TypeDicSeg	high;
46 	TypeDicSeg	mid;
47 	Int		cmp;
48 	Uchar		*target;
49 
50 	if ((high = curdict->segunit - 1) < 1) return 0;
51 
52 	if (low == (TypeDicSeg)-1) low = 0;
53 
54 	while (low <= high) {
55 
56 		mid = (low + high) >> 1;
57 
58 		target = get_idxptr(mid);
59 
60 		cmp = istrcmp(cnvstart, target, len, sstrlen(target));
61 
62 		if (cmp == OVER) {
63 			high = mid - 1;
64 		}
65 
66 		else if(cmp != MATCH){
67 			low = mid + 1;
68 		}
69 
70 		else {
71 			return mid;
72 		}
73 	}
74 
75 	return (cmp == OVER && mid != DicSegBase) ? mid - 1 : mid;
76 }
77 
78