9 /**********************************************************************
13 **********************************************************************/
14 /*---------------------------------------------------------------------
16 guess - distinguish code system
17 ---------------------------------------------------------------------*/
18 unsigned Kcc_guess(str, len, extend, zenkaku, gsmode, insi, inso, innj, ingj)
22 unsigned long *insi, *inso, *innj, *ingj;
26 register int euc, sjis, dec;
28 register unsigned code;
36 for (s = str; s < str + len; s += i) {
38 switch (*(u_char *) s) {
43 if (Kcc_compare("$B", s + 1) || Kcc_compare("$@", s + 1)) {
44 *gsmode = M_KANJI; /* kanji */
45 *insi |= bitflag(((u_char *) s)[2]);
47 } else if (Kcc_compare("&@\033$B", s + 1)) {
48 *gsmode = M_KANJI; /* kanji 1990 */
49 *innj |= bitflag('B');
51 } else if (Kcc_compare("(B", s + 1) ||
52 Kcc_compare("(J", s + 1) || Kcc_compare("(H", s + 1)) {
53 *gsmode = M_ASCII; /* kanji end */
54 *inso |= bitflag(((u_char *) s)[2]);
56 } else if (Kcc_compare("(I", s + 1)) {
57 *gsmode = M_KANJI; /* "ESC(I" */
58 *inso |= bitflag('I');
60 } else if (Kcc_compare("$(D", s + 1)) {
61 *gsmode = M_KANJI; /* gaiji */
62 *ingj |= bitflag('D');
71 if (*gsmode == M_ASCII) {
78 if (*gsmode == M_SO) {
84 if (*gsmode != M_ASCII)
88 if (*(u_char *) s & 0x80)
95 if (*(u_char *) s & 0x80) {
96 if ((0xa0 < *(u_char *) s && *(u_char *) s < 0xff) ||
97 (!zenkaku && *(u_char *) s == SS2)) {
102 if (*(u_char *) s == SS3) {
105 } else if (*(u_char *) s < 0xa0)
108 euc = 0; /* not EUC */
113 * EUC second byte or third byte of CS3.
115 if (((u_char *) s)[-1] == SS2) {
116 if (0xa0 < *(u_char *) s &&
117 *(u_char *) s < (extend ? 0xff : 0xe0)) {
118 euc = 1; /* hankaku kana */
122 if (0xa0 < *(u_char *) s && *(u_char *) s < 0xff) {
123 if (((u_char *) s)[-1] != SS3)
124 euc = 1;/* zenkaku */
127 euc = 0; /* not EUC */
136 if (*(u_char *) s & 0x80) {
137 if (0xa0 < *(u_char *) s && *(u_char *) s < 0xff) {
140 } else if (*(u_char *) s < 0xa0)
142 dec = 0; /* not DEC */
149 if (0x20 < (*(u_char *) s & 0x7f) &&
150 (*(u_char *) s & 0x7f) < 0x7f) {
153 dec = 0; /* not DEC */
159 * shift-JIS first byte.
161 if (*(u_char *) s & 0x80) {
162 if (0xa0 < *(u_char *) s && *(u_char *) s < 0xe0) {
165 } else if (*(u_char *) s != 0x80 &&
166 *(u_char *) s != 0xa0 &&
167 *(u_char *) s <= (extend ? 0xfc : 0xef)) {
168 sjis = 2; /* zenkaku */
172 sjis = 0; /* not SJIS */
177 * shift-JIS second byte.
179 if (0x40 <= *(u_char *) s && *(u_char *) s != 0x7f &&
180 *(u_char *) s <= 0xfc)
183 sjis = 0; /* not SJIS */
192 code |= zenkaku || !jis8 ? SJIS : SJIS | JIS8;