1 /* $Id: kanji_.c,v 1.1.1.1 2000/06/27 01:47:56 amura Exp $ */
2 /* mskanji.c: ms-kanji handling routines
3  * -> kanji_.c: euc kanji handling routines
4  *serow / amura
5  */
6 
7 /*
8  * $Log: kanji_.c,v $
9  * Revision 1.1.1.1  2000/06/27 01:47:56  amura
10  * import to CVS
11  *
12  */
13 
14 #include "kanji_.h"
15 
16 #define UCH(c)   ((unsigned char)(c))
17 
18 /* kpart(pLim, pChr);
19  * char * pLim;  Buffer Top or Limit for scanning
20  * char * pChr;  Pointer to the char
21  *		return whith 1 : *pChr is First byte of MS-Kanji
22  *		return whith 2 : *pChr is Second byte of MS-Kanji
23  *		return whith 0 : otherwize
24  */
25 int
kpart(pLim,pChr)26 kpart(pLim, pChr)
27 char *pLim;
28 char *pChr;
29 {
30 	register char * p  = pChr - 1;
31 	register int ct = 0;
32 
33 	while (ISKANJI(*p) && p >= pLim) {
34 		p--;
35 		ct++;
36 	}
37 	return (ct & 1) ? 2 : ISKANJI(*pChr);
38 }
39 
40 /* jstrlen: return the number of charctors in string.
41  */
jstrlen(s)42 int jstrlen(s)
43 char * s;
44 {
45 	int len;
46 
47 	for (len = 0; *s; s++, len++) {
48 		if (ISKANJI(*s) && s[1])
49 			s++;
50 	}
51 	return len;
52 }
53 
54 /* jnthchar: return with the pointer to n'th charactor in string.
55  *           return (char *)0, when jstrlen(s) < n
56  */
jnthchar(s,n)57 char * jnthchar(s, n)
58 char * s;
59 int    n;
60 {
61 	if (n) {
62 		while (--n) {
63 			if (ISKANJI(*s))
64 				s++;
65 			s++;
66 		}
67 	}
68 	return s;
69 }
70 
71 /* jindex: return with the pointer to 'ch' in "string"
72  *         return with (char *)0, when not found
73  */
74 char *
jindex(s,c)75 jindex(s, c)
76 char *s;
77 int   c;
78 {
79 	while (*s) {
80 		if (UCH(*s) == UCH(c))
81 			return s;
82 
83 		if (ISKANJI(*s) && s[1]) {
84 			s++;
85 		}
86 		s++;
87 	}
88 	return (char *)0;
89 }
90 /* jrindex: return with the pointer to Right end 'ch' in "string"
91  *          return with (char *)0, when not found
92  */
93 char *
jrindex(s,c)94 jrindex(s, c)
95 char *s;
96 int   c;
97 {
98 	char * olds = (char *)0;
99 
100 	while (*s) {
101 		if (UCH(*s) == UCH(c))
102 			olds = s;
103 
104 		if (ISKANJI(*s) && s[1]) {
105 			s++;
106 		}
107 		s++;
108 	}
109 	return olds;
110 }
111 
112 char *
jstrlower(s)113 jstrlower(s)
114 char *s;
115 {
116 	char *ws = s;
117 
118 	while (*ws) {
119 		if (ISKANJI(*ws) && ws[1])
120 			ws++;
121 		else
122 			*ws = (('A' <= *ws) && (*ws <= 'Z')) ? *ws - 'A' + 'a': *ws;
123 		ws++;
124 	}
125 	return s;
126 }
127