Mercurial > audlegacy
annotate src/libguess/guess.c @ 4535:2cfd5d48d787
Added a TODO (mostly my own semi-organized ramblings, feel free to add your own.)
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 10 May 2008 21:30:24 +0300 |
parents | ce2d24746c09 |
children |
rev | line source |
---|---|
2313 | 1 #include "libguess.h" |
3201
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
2 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
3 typedef struct _guess_impl { |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
4 struct _guess_impl *next; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
5 const char *name; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
6 const char *(*impl)(const char *buf, int len); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
7 } guess_impl; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
8 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
9 static guess_impl *guess_impl_list = NULL; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
10 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
11 void guess_impl_register(const char *lang, |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
12 const char *(*impl)(const char *buf, int len)) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
13 { |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
14 guess_impl *iptr = calloc(sizeof(guess_impl), 1); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
15 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
16 iptr->name = lang; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
17 iptr->impl = impl; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
18 iptr->next = guess_impl_list; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
19 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
20 guess_impl_list = iptr; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
21 } |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
22 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
23 void guess_init(void) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
24 { |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
25 /* check if already initialized */ |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
26 if (guess_impl_list != NULL) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
27 return; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
28 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
29 guess_impl_register(GUESS_REGION_JP, guess_jp); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
30 guess_impl_register(GUESS_REGION_TW, guess_tw); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
31 guess_impl_register(GUESS_REGION_CN, guess_cn); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
32 guess_impl_register(GUESS_REGION_KR, guess_kr); |
3202
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
3201
diff
changeset
|
33 guess_impl_register(GUESS_REGION_RU, guess_ru); |
3206
6bcfc6561711
Implement support for Arabic and Turkish.
William Pitcock <nenolod@atheme-project.org>
parents:
3202
diff
changeset
|
34 guess_impl_register(GUESS_REGION_AR, guess_ar); |
6bcfc6561711
Implement support for Arabic and Turkish.
William Pitcock <nenolod@atheme-project.org>
parents:
3202
diff
changeset
|
35 guess_impl_register(GUESS_REGION_TR, guess_tr); |
3215
ce2d24746c09
Add support for greek and hebrew character set detection.
William Pitcock <nenolod@atheme-project.org>
parents:
3213
diff
changeset
|
36 guess_impl_register(GUESS_REGION_GR, guess_gr); |
ce2d24746c09
Add support for greek and hebrew character set detection.
William Pitcock <nenolod@atheme-project.org>
parents:
3213
diff
changeset
|
37 guess_impl_register(GUESS_REGION_HW, guess_hw); |
3201
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
38 } |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
39 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
40 const char *guess_encoding(const char *inbuf, int buflen, const char *lang) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
41 { |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
42 guess_impl *iter; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
43 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
44 guess_init(); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
45 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
46 for (iter = guess_impl_list; iter != NULL; iter = iter->next) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
47 { |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
48 if (!strcasecmp(lang, iter->name)) |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
49 return iter->impl(inbuf, buflen); |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
50 } |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
51 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
52 /* TODO: try other languages as fallback? */ |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
53 |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
54 return NULL; |
e1470a536417
Allow libguess to be extended for other languages using a common API.
William Pitcock <nenolod@atheme-project.org>
parents:
2599
diff
changeset
|
55 } |