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_ua.h"
61 #include "nls/nls_en.h"
62 #include "nls/nls_hy.h"
63 #include "nls/nls_tr.h"
64 #include "nls/nls_neutral.h"
65 
66 #ifndef HAVE_STRCASECMP
67 #ifdef HAVE_STRICMP
68 #define strcasecmp stricmp
69 #endif
70 #endif
71 
72 static const mbfl_language *mbfl_language_ptr_table[] = {
73 	&mbfl_language_uni,
74 	&mbfl_language_japanese,
75 	&mbfl_language_korean,
76 	&mbfl_language_simplified_chinese,
77 	&mbfl_language_traditional_chinese,
78 	&mbfl_language_english,
79 	&mbfl_language_german,
80 	&mbfl_language_russian,
81 	&mbfl_language_ukrainian,
82 	&mbfl_language_armenian,
83 	&mbfl_language_turkish,
84 	&mbfl_language_neutral,
85 	NULL
86 };
87 
88 /* language resolver */
89 const mbfl_language *
mbfl_name2language(const char * name)90 mbfl_name2language(const char *name)
91 {
92 	const mbfl_language *language;
93 	int i, j;
94 
95 	if (name == NULL) {
96 		return NULL;
97 	}
98 
99 	i = 0;
100 	while ((language = mbfl_language_ptr_table[i++]) != NULL){
101 		if (strcasecmp(language->name, name) == 0) {
102 			return language;
103 		}
104 	}
105 
106 	i = 0;
107 	while ((language = mbfl_language_ptr_table[i++]) != NULL){
108 		if (strcasecmp(language->short_name, name) == 0) {
109 			return language;
110 		}
111 	}
112 
113 	/* serch aliases */
114 	i = 0;
115 	while ((language = mbfl_language_ptr_table[i++]) != NULL) {
116 		if (language->aliases != NULL) {
117 			j = 0;
118 			while ((*language->aliases)[j] != NULL) {
119 				if (strcasecmp((*language->aliases)[j], name) == 0) {
120 					return language;
121 				}
122 				j++;
123 			}
124 		}
125 	}
126 
127 	return NULL;
128 }
129 
130 const mbfl_language *
mbfl_no2language(enum mbfl_no_language no_language)131 mbfl_no2language(enum mbfl_no_language no_language)
132 {
133 	const mbfl_language *language;
134 	int i;
135 
136 	i = 0;
137 	while ((language = mbfl_language_ptr_table[i++]) != NULL){
138 		if (language->no_language == no_language) {
139 			return language;
140 		}
141 	}
142 
143 	return NULL;
144 }
145 
146 enum mbfl_no_language
mbfl_name2no_language(const char * name)147 mbfl_name2no_language(const char *name)
148 {
149 	const mbfl_language *language;
150 
151 	language = mbfl_name2language(name);
152 	if (language == NULL) {
153 		return mbfl_no_language_invalid;
154 	} else {
155 		return language->no_language;
156 	}
157 }
158 
159 const char *
mbfl_no_language2name(enum mbfl_no_language no_language)160 mbfl_no_language2name(enum mbfl_no_language no_language)
161 {
162 	const mbfl_language *language;
163 
164 	language = mbfl_no2language(no_language);
165 	if (language == NULL) {
166 		return "";
167 	} else {
168 		return language->name;
169 	}
170 }
171