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: cnvhinsi.c,v $
32  * $SonyRevision: 1.2 $
33  * $SonyDate: 1996/05/27 06:59:47 $
34  */
35 
36 
37 #include <stdio.h>
38 #include <sys/types.h>
39 
40 
41 
42 static struct gram_code {
43 	char	*name;
44 	int	code;
45 } gramtbl[] = {
46 
47 
48 #include "GramTable"
49 
50 };
51 
52 #define	GramMax	(sizeof(gramtbl)/sizeof(struct gram_code) - 1)
53 
54 int
u_strcmp(u_char * a,u_char * b)55 u_strcmp(u_char *a, u_char *b)
56 {
57 	if (!a || !b) return 0;
58 
59 	while (*a && *b) {
60 		if (*a < *b) return -1;
61 		if (*a > *b) return 1;
62 		a++;
63 		b++;
64 	}
65 	if (!*a && !*b) return 0;
66 	if (!*a) return -1;
67 	return 1;
68 }
69 
70 
71 int
cnvhinsi(u_char * buf)72 cnvhinsi(u_char *buf)
73 {
74 	int	min;
75 	int	max;
76 	int	mid;
77 	int	i;
78 
79 	min = 0;
80 	max = GramMax;
81 	while (min <= max) {
82 
83 		mid = (min + max) / 2;
84 
85 
86 		i = u_strcmp(buf, gramtbl[mid].name);
87 
88 
89 		if (i < 0) {
90 			max = mid - 1;
91 		}
92 
93 		else if (i > 0) {
94 			min = mid + 1;
95 		}
96 
97 		else {
98 			return(gramtbl[mid].code);
99 		}
100 	}
101 
102 
103 	return 0;
104 }
105 
106 
107 
108 char *
hinsi_str(int code)109 hinsi_str(int code)
110 {
111 	int	i;
112 
113 	for (i = 0 ; i <= GramMax ; i++) {
114 		if (gramtbl[i].code == code) return gramtbl[i].name;
115 	}
116 
117 	return "Err";
118 }
119