1 : /*
2 : * "streamable kanji code filter and converter"
3 : * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
4 : *
5 : * LICENSE NOTICES
6 : *
7 : * This file is part of "streamable kanji code filter and converter",
8 : * which is distributed under the terms of GNU Lesser General Public
9 : * License (version 2) as published by the Free Software Foundation.
10 : *
11 : * This software is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU Lesser General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public
17 : * License along with "streamable kanji code filter and converter";
18 : * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 : * Suite 330, Boston, MA 02111-1307 USA
20 : *
21 : * The author of this file:
22 : *
23 : */
24 : /*
25 : * The source code included in this files was separated from mbfilter.c
26 : * by Moriyoshi Koizumi <moriyoshi@php.net> on 20 Dec 2002. The file
27 : * mbfilter.c is included in this package .
28 : *
29 : */
30 :
31 : #ifdef HAVE_CONFIG_H
32 : #include "config.h"
33 : #endif
34 :
35 : #ifdef HAVE_STDDEF_H
36 : #include <stddef.h>
37 : #endif
38 :
39 : #ifdef HAVE_STDDEF_H
40 : #include <stddef.h>
41 : #endif
42 :
43 : #ifdef HAVE_STRING_H
44 : #include <string.h>
45 : #endif
46 :
47 : #ifdef HAVE_STRINGS_H
48 : #include <strings.h>
49 : #endif
50 :
51 : #include "mbfl_encoding.h"
52 : #include "mbfl_language.h"
53 :
54 : #include "nls/nls_ja.h"
55 : #include "nls/nls_kr.h"
56 : #include "nls/nls_zh.h"
57 : #include "nls/nls_uni.h"
58 : #include "nls/nls_de.h"
59 : #include "nls/nls_ru.h"
60 : #include "nls/nls_en.h"
61 : #include "nls/nls_hy.h"
62 : #include "nls/nls_tr.h"
63 : #include "nls/nls_neutral.h"
64 :
65 : #ifndef HAVE_STRCASECMP
66 : #ifdef HAVE_STRICMP
67 : #define strcasecmp stricmp
68 : #endif
69 : #endif
70 :
71 : static const mbfl_language *mbfl_language_ptr_table[] = {
72 : &mbfl_language_uni,
73 : &mbfl_language_japanese,
74 : &mbfl_language_korean,
75 : &mbfl_language_simplified_chinese,
76 : &mbfl_language_traditional_chinese,
77 : &mbfl_language_english,
78 : &mbfl_language_german,
79 : &mbfl_language_russian,
80 : &mbfl_language_armenian,
81 : &mbfl_language_turkish,
82 : &mbfl_language_neutral,
83 : NULL
84 : };
85 :
86 : /* language resolver */
87 : const mbfl_language *
88 : mbfl_name2language(const char *name)
89 13593 : {
90 : const mbfl_language *language;
91 : int i, j;
92 :
93 13593 : if (name == NULL) {
94 0 : return NULL;
95 : }
96 :
97 13593 : i = 0;
98 162912 : while ((language = mbfl_language_ptr_table[i++]) != NULL){
99 149319 : if (strcasecmp(language->name, name) == 0) {
100 13593 : return language;
101 : }
102 : }
103 :
104 0 : i = 0;
105 0 : while ((language = mbfl_language_ptr_table[i++]) != NULL){
106 0 : if (strcasecmp(language->short_name, name) == 0) {
107 0 : return language;
108 : }
109 : }
110 :
111 : /* serch aliases */
112 0 : i = 0;
113 0 : while ((language = mbfl_language_ptr_table[i++]) != NULL) {
114 0 : if (language->aliases != NULL) {
115 0 : j = 0;
116 0 : while ((*language->aliases)[j] != NULL) {
117 0 : if (strcasecmp((*language->aliases)[j], name) == 0) {
118 0 : return language;
119 : }
120 0 : j++;
121 : }
122 : }
123 : }
124 :
125 0 : return NULL;
126 : }
127 :
128 : const mbfl_language *
129 : mbfl_no2language(enum mbfl_no_language no_language)
130 28 : {
131 : const mbfl_language *language;
132 : int i;
133 :
134 28 : i = 0;
135 258 : while ((language = mbfl_language_ptr_table[i++]) != NULL){
136 230 : if (language->no_language == no_language) {
137 28 : return language;
138 : }
139 : }
140 :
141 0 : return NULL;
142 : }
143 :
144 : enum mbfl_no_language
145 : mbfl_name2no_language(const char *name)
146 13593 : {
147 : const mbfl_language *language;
148 :
149 13593 : language = mbfl_name2language(name);
150 13593 : if (language == NULL) {
151 0 : return mbfl_no_language_invalid;
152 : } else {
153 13593 : return language->no_language;
154 : }
155 : }
156 :
157 : const char *
158 : mbfl_no_language2name(enum mbfl_no_language no_language)
159 14 : {
160 : const mbfl_language *language;
161 :
162 14 : language = mbfl_no2language(no_language);
163 14 : if (language == NULL) {
164 0 : return "";
165 : } else {
166 14 : return language->name;
167 : }
168 : }
169 :
|