Mercurial > libguess
diff cjk_impl.c @ 2:754a4550c64e
- added arabic, greek, hebrew and turkish DFAs
- new UCS-2LE/BE DFAs
- now arabic_impl.c uses arabic DFAs
- dfa common macros have been moved to dfa.h
- minor cleanups
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Wed, 11 Jun 2008 00:11:30 +0900 |
parents | d9b6ff839eab |
children | 70e2c306231e |
line wrap: on
line diff
--- a/cjk_impl.c Sat Dec 01 03:27:31 2007 +0900 +++ b/cjk_impl.c Wed Jun 11 00:11:30 2008 +0900 @@ -4,14 +4,14 @@ */ /* - * guess.c - guessing character encoding + * guess.c - guessing character encoding * * Copyright (c) 2000-2003 Shiro Kawai, All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * @@ -38,13 +38,7 @@ */ #include "libguess.h" - -/* take precedence if scores are same. you can customize the order as: */ -/* ORDER_** &highest, &second, ... &lowest */ -#define ORDER_JP &utf8, &sjis, &eucj -#define ORDER_TW &utf8, &big5 -#define ORDER_CN &utf8, &gb2312, &gb18030 -#define ORDER_KR &utf8, &euck, &johab +#include "dfa.h" /* workaround for that glib's g_convert can't convert properly from UCS-2BE/LE trailing after BOM. */ @@ -59,40 +53,12 @@ const char UCS_2LE[] = "UCS-2LE"; #endif -/* data types */ -typedef struct guess_arc_rec -{ - unsigned int next; /* next state */ - double score; /* score */ -} guess_arc; - -typedef struct guess_dfa_rec -{ - signed char (*states)[256]; - guess_arc *arcs; - int state; - double score; -} guess_dfa; - -/* macros */ -#define DFA_INIT(st, ar) \ - { st, ar, 0, 1.0 } - -#define DFA_NEXT(dfa, ch) \ - do { \ - int arc__; \ - if (dfa.state >= 0) { \ - arc__ = dfa.states[dfa.state][ch]; \ - if (arc__ < 0) { \ - dfa.state = -1; \ - } else { \ - dfa.state = dfa.arcs[arc__].next; \ - dfa.score *= dfa.arcs[arc__].score; \ - } \ - } \ - } while (0) - -#define DFA_ALIVE(dfa) (dfa.state >= 0) +/* take precedence if scores are same. you can customize the order as: */ +/* ORDER_** &highest, &second, ... &lowest */ +#define ORDER_JP &utf8, &sjis, &eucj +#define ORDER_TW &utf8, &big5 +#define ORDER_CN &utf8, &gb2312, &gb18030 +#define ORDER_KR &utf8, &euck, &johab /* include DFA table generated by guess.scm */ #include "guess_tab.c" @@ -116,7 +82,7 @@ if(DFA_ALIVE(utf8)) return 1; - else + else return 0; }