Mercurial > audlegacy
annotate src/libguess/cjk_impl.c @ 4838:53dd85fdf42b
"default" -> "newui".
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 05 Apr 2009 15:28:31 -0500 |
parents | 92c12d945d99 |
children |
rev | line source |
---|---|
3213
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * This code is derivative of guess.c of Gauche-0.8.3. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 * The following is the original copyright notice. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 /* |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 * guess.c - guessing character encoding |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 * Copyright (c) 2000-2003 Shiro Kawai, All rights reserved. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 * Redistribution and use in source and binary forms, with or without |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 * modification, are permitted provided that the following conditions |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 * are met: |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 * 1. Redistributions of source code must retain the above copyright |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16 * notice, this list of conditions and the following disclaimer. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18 * 2. Redistributions in binary form must reproduce the above copyright |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 * notice, this list of conditions and the following disclaimer in the |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 * documentation and/or other materials provided with the distribution. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22 * 3. Neither the name of the authors nor the names of its contributors |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 * may be used to endorse or promote products derived from this |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 * software without specific prior written permission. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 * |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 #include "libguess.h" |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 /* take precedence if scores are same. you can customize the order as: */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 /* ORDER_** &highest, &second, ... &lowest */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 #define ORDER_JP &utf8, &sjis, &eucj |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 #define ORDER_TW &utf8, &big5 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 #define ORDER_CN &utf8, &gb2312, &gb18030 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 #define ORDER_KR &utf8, &euck, &johab |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 /* workaround for that glib's g_convert can't convert |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 properly from UCS-2BE/LE trailing after BOM. */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 #define WITH_G_CONVERT 1 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 /* #undef WITH_G_CONVERT */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 #ifdef WITH_G_CONVERT |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55 const char UCS_2BE[] = "UTF-16"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 const char UCS_2LE[] = "UTF-16"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 #else |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 const char UCS_2BE[] = "UCS-2BE"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 const char UCS_2LE[] = "UCS-2LE"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60 #endif |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 /* data types */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 typedef struct guess_arc_rec |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 unsigned int next; /* next state */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 double score; /* score */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67 } guess_arc; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 typedef struct guess_dfa_rec |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 signed char (*states)[256]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 guess_arc *arcs; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 int state; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 double score; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75 } guess_dfa; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77 /* macros */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78 #define DFA_INIT(st, ar) \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 { st, ar, 0, 1.0 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81 #define DFA_NEXT(dfa, ch) \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82 do { \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 int arc__; \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 if (dfa.state >= 0) { \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85 arc__ = dfa.states[dfa.state][ch]; \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 if (arc__ < 0) { \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 dfa.state = -1; \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88 } else { \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89 dfa.state = dfa.arcs[arc__].next; \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 dfa.score *= dfa.arcs[arc__].score; \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91 } \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 } \ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 } while (0) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 #define DFA_ALIVE(dfa) (dfa.state >= 0) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97 /* include DFA table generated by guess.scm */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 #include "guess_tab.c" |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 int dfa_validate_utf8(const char *buf, int buflen) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 int i; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 guess_dfa utf8 = DFA_INIT(guess_utf8_st, guess_utf8_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 for (i = 0; i < buflen; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107 int c = (unsigned char) buf[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
108 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 if (DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
110 DFA_NEXT(utf8, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
111 else |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
112 break; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
113 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
114 |
3916
92c12d945d99
fix for bug #53, first try.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3644
diff
changeset
|
115 DFA_NEXT(utf8, '\0'); //Bug #53 |
92c12d945d99
fix for bug #53, first try.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3644
diff
changeset
|
116 |
3213
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
117 if(DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
118 return 1; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 else |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
120 return 0; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
121 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
122 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123 const char *guess_jp(const char *buf, int buflen) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
124 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 int i; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 guess_dfa eucj = DFA_INIT(guess_eucj_st, guess_eucj_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
127 guess_dfa sjis = DFA_INIT(guess_sjis_st, guess_sjis_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
128 guess_dfa utf8 = DFA_INIT(guess_utf8_st, guess_utf8_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 guess_dfa *top = NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
130 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 guess_dfa *order[] = { ORDER_JP, NULL }; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133 for (i = 0; i < buflen; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134 int c = (unsigned char) buf[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136 /* special treatment of iso-2022 escape sequence */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 if (c == 0x1b) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
138 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139 c = (unsigned char) buf[++i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140 if (c == '$' || c == '(') |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141 return "ISO-2022-JP"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
143 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
144 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
145 /* special treatment of BOM */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
146 if (i == 0 && c == 0xff) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
147 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
148 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
149 if (c == 0xfe) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
150 return UCS_2LE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 if (i == 0 && c == 0xfe) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 if (c == 0xff) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 return UCS_2BE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 if (DFA_ALIVE(eucj)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 if (!DFA_ALIVE(sjis) && !DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 return "EUC-JP"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 DFA_NEXT(eucj, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166 if (DFA_ALIVE(sjis)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 if (!DFA_ALIVE(eucj) && !DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168 return "SJIS"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 DFA_NEXT(sjis, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171 if (DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 if (!DFA_ALIVE(sjis) && !DFA_ALIVE(eucj)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174 DFA_NEXT(utf8, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 if (!DFA_ALIVE(eucj) && !DFA_ALIVE(sjis) && !DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178 /* we ran out the possibilities */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 /* Now, we have ambigous code. Pick the highest score. If more than |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184 one candidate tie, pick the default encoding. */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185 for (i = 0; order[i] != NULL; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 if (order[i]->state >= 0) { //DFA_ALIVE() |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 if (top == NULL || order[i]->score > top->score) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188 top = order[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192 if (top == &eucj) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193 return "EUC-JP"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194 if (top == &utf8) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196 if (top == &sjis) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197 return "SJIS"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201 const char *guess_tw(const char *buf, int buflen) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 int i; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 guess_dfa big5 = DFA_INIT(guess_big5_st, guess_big5_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 guess_dfa utf8 = DFA_INIT(guess_utf8_st, guess_utf8_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206 guess_dfa *top = NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
208 guess_dfa *order[] = { ORDER_TW, NULL }; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210 for (i = 0; i < buflen; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211 int c = (unsigned char) buf[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213 /* special treatment of iso-2022 escape sequence */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214 if (c == 0x1b) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
216 c = (unsigned char) buf[++i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217 if (c == '$' || c == '(') |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218 return "ISO-2022-TW"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
219 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
220 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
221 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
222 /* special treatment of BOM */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
223 if (i == 0 && c == 0xff) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
224 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
225 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
226 if (c == 0xfe) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
227 return UCS_2LE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
228 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
229 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
230 if (i == 0 && c == 0xfe) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
231 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
232 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
233 if (c == 0xff) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
234 return UCS_2BE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
235 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
236 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
237 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
238 if (DFA_ALIVE(big5)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
239 if (!DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
240 return "BIG5"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
241 DFA_NEXT(big5, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
242 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
243 if (DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
244 if (!DFA_ALIVE(big5)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
245 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
246 DFA_NEXT(utf8, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
247 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
248 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
249 if (!DFA_ALIVE(big5) && !DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
250 /* we ran out the possibilities */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
251 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
252 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
253 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
254 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
255 /* Now, we have ambigous code. Pick the highest score. If more than |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
256 one candidate tie, pick the default encoding. */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
257 for (i = 0; order[i] != NULL; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
258 if (order[i]->state >= 0) { //DFA_ALIVE() |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
259 if (top == NULL || order[i]->score > top->score) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
260 top = order[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
261 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
262 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
263 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
264 if (top == &big5) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
265 return "BIG5"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
266 if (top == &utf8) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
267 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
268 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
269 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
270 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
271 const char *guess_cn(const char *buf, int buflen) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
272 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
273 int i; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
274 guess_dfa gb2312 = DFA_INIT(guess_gb2312_st, guess_gb2312_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
275 guess_dfa utf8 = DFA_INIT(guess_utf8_st, guess_utf8_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
276 guess_dfa gb18030 = DFA_INIT(guess_gb18030_st, guess_gb18030_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
277 guess_dfa *top = NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
278 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
279 guess_dfa *order[] = { ORDER_CN, NULL }; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
280 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
281 for (i = 0; i < buflen; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
282 int c = (unsigned char) buf[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
283 int c2; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
284 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
285 /* special treatment of iso-2022 escape sequence */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
286 if (c == 0x1b) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
287 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
288 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
289 c2 = (unsigned char) buf[i + 2]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
290 if (c == '$' && (c2 == ')' || c2 == '+')) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
291 return "ISO-2022-CN"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
292 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
293 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
294 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
295 /* special treatment of BOM */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
296 if (i == 0 && c == 0xff) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
297 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
298 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
299 if (c == 0xfe) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
300 return UCS_2LE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
301 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
302 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
303 if (i == 0 && c == 0xfe) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
304 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
305 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
306 if (c == 0xff) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
307 return UCS_2BE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
308 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
309 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
310 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
311 if (DFA_ALIVE(gb2312)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
312 if (!DFA_ALIVE(utf8) && !DFA_ALIVE(gb18030)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
313 return "GB2312"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
314 DFA_NEXT(gb2312, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
315 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
316 if (DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
317 if (!DFA_ALIVE(gb2312) && !DFA_ALIVE(gb18030)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
318 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
319 DFA_NEXT(utf8, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
320 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
321 if (DFA_ALIVE(gb18030)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
322 if (!DFA_ALIVE(utf8) && !DFA_ALIVE(gb2312)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
323 return "GB18030"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
324 DFA_NEXT(gb18030, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
325 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
326 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
327 if (!DFA_ALIVE(gb2312) && !DFA_ALIVE(utf8) && !DFA_ALIVE(gb18030)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
328 /* we ran out the possibilities */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
329 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
330 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
331 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
332 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
333 /* Now, we have ambigous code. Pick the highest score. If more than |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
334 one candidate tie, pick the default encoding. */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
335 for (i = 0; order[i] != NULL; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
336 if (order[i]->state >= 0) { //DFA_ALIVE() |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
337 if (top == NULL || order[i]->score > top->score) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
338 top = order[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
339 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
340 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
341 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
342 if (top == &gb2312) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
343 return "GB2312"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
344 if (top == &utf8) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
345 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
346 if (top == &gb18030) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
347 return "GB18030"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
348 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
349 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
350 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
351 const char *guess_kr(const char *buf, int buflen) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
352 { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
353 int i; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
354 guess_dfa euck = DFA_INIT(guess_euck_st, guess_euck_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
355 guess_dfa utf8 = DFA_INIT(guess_utf8_st, guess_utf8_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
356 guess_dfa johab = DFA_INIT(guess_johab_st, guess_johab_ar); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
357 guess_dfa *top = NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
358 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
359 guess_dfa *order[] = { ORDER_KR, NULL }; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
360 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
361 for (i = 0; i < buflen; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
362 int c = (unsigned char) buf[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
363 int c2; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
364 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
365 /* special treatment of iso-2022 escape sequence */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
366 if (c == 0x1b) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
367 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
368 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
369 c2 = (unsigned char) buf[i + 2]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
370 if (c == '$' && c2 == ')') |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
371 return "ISO-2022-KR"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
372 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
373 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
374 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
375 /* special treatment of BOM */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
376 if (i == 0 && c == 0xff) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
377 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
378 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
379 if (c == 0xfe) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
380 return UCS_2LE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
381 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
382 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
383 if (i == 0 && c == 0xfe) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
384 if (i < buflen - 1) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
385 c = (unsigned char) buf[i + 1]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
386 if (c == 0xff) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
387 return UCS_2BE; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
388 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
389 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
390 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
391 if (DFA_ALIVE(euck)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
392 if (!DFA_ALIVE(johab) && !DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
393 return "EUC-KR"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
394 DFA_NEXT(euck, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
395 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
396 if (DFA_ALIVE(johab)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
397 if (!DFA_ALIVE(euck) && !DFA_ALIVE(utf8)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
398 return "JOHAB"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
399 DFA_NEXT(johab, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
400 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
401 if (DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
402 if (!DFA_ALIVE(euck) && !DFA_ALIVE(johab)) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
403 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
404 DFA_NEXT(utf8, c); |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
405 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
406 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
407 if (!DFA_ALIVE(euck) && !DFA_ALIVE(johab) && !DFA_ALIVE(utf8)) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
408 /* we ran out the possibilities */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
409 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
410 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
411 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
412 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
413 /* Now, we have ambigous code. Pick the highest score. If more than |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
414 one candidate tie, pick the default encoding. */ |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
415 for (i = 0; order[i] != NULL; i++) { |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
416 if (order[i]->state >= 0) { //DFA_ALIVE() |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
417 if (top == NULL || order[i]->score > top->score) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
418 top = order[i]; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
419 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
420 } |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
421 |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
422 if (top == &euck) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
423 return "EUC-KR"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
424 if (top == &utf8) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
425 return "UTF-8"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
426 if (top == &johab) |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
427 return "JOHAB"; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
428 return NULL; |
1b9251ab3655
Split off CJK implementation from guess.c logic.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
429 } |