Mercurial > libguess
annotate guess.c @ 6:c61a7765c8f5 default tip
added COPYING to make the licence and copyrights clear.
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Thu, 08 Mar 2012 11:08:07 +0900 |
| parents | 8a64459dab94 |
| children |
| rev | line source |
|---|---|
| 0 | 1 #include "libguess.h" |
| 2 | |
| 3 typedef struct _guess_impl { | |
| 4 struct _guess_impl *next; | |
| 5 const char *name; | |
| 6 const char *(*impl)(const char *buf, int len); | |
| 7 } guess_impl; | |
| 8 | |
| 9 static guess_impl *guess_impl_list = NULL; | |
| 10 | |
|
5
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
11 static void |
|
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
12 guess_impl_register(const char *lang, |
|
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
13 const char *(*impl)(const char *buf, int len)) |
| 0 | 14 { |
| 15 guess_impl *iptr = calloc(sizeof(guess_impl), 1); | |
| 16 | |
| 17 iptr->name = lang; | |
| 18 iptr->impl = impl; | |
| 19 iptr->next = guess_impl_list; | |
| 20 | |
| 21 guess_impl_list = iptr; | |
| 22 } | |
| 23 | |
|
5
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
24 static void |
|
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
25 guess_init(void) |
| 0 | 26 { |
| 27 /* check if already initialized */ | |
| 28 if (guess_impl_list != NULL) | |
| 29 return; | |
| 30 | |
| 31 guess_impl_register(GUESS_REGION_JP, guess_jp); | |
| 32 guess_impl_register(GUESS_REGION_TW, guess_tw); | |
| 33 guess_impl_register(GUESS_REGION_CN, guess_cn); | |
| 34 guess_impl_register(GUESS_REGION_KR, guess_kr); | |
| 35 guess_impl_register(GUESS_REGION_RU, guess_ru); | |
| 36 guess_impl_register(GUESS_REGION_AR, guess_ar); | |
| 37 guess_impl_register(GUESS_REGION_TR, guess_tr); | |
| 38 guess_impl_register(GUESS_REGION_GR, guess_gr); | |
| 39 guess_impl_register(GUESS_REGION_HW, guess_hw); | |
| 40 } | |
| 41 | |
|
5
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
42 const char * |
|
8a64459dab94
make guess_init() and guess_impl_register() static functions.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
43 guess_encoding(const char *inbuf, int buflen, const char *lang) |
| 0 | 44 { |
| 45 guess_impl *iter; | |
| 46 | |
| 47 guess_init(); | |
| 48 | |
| 49 for (iter = guess_impl_list; iter != NULL; iter = iter->next) | |
| 50 { | |
| 51 if (!strcasecmp(lang, iter->name)) | |
| 52 return iter->impl(inbuf, buflen); | |
| 53 } | |
| 54 | |
| 55 /* TODO: try other languages as fallback? */ | |
| 56 | |
| 57 return NULL; | |
| 58 } |
