ReactOS 0.4.15-dev-7674-gc0b4db1
nls_koi8-ru.c
Go to the documentation of this file.
1/*
2 * linux/fs/nls_koi8-ru.c
3 *
4 * Charset koi8-ru translation based on charset koi8-u.
5 * The Unicode to charset table has only exact mappings.
6 */
7
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/string.h>
11#include <linux/nls.h>
12#include <linux/errno.h>
13
14static struct nls_table *p_nls;
15
16static int uni2char(const wchar_t uni,
17 unsigned char *out, int boundlen)
18{
19 if (boundlen <= 0)
20 return -ENAMETOOLONG;
21
22 if ((uni & 0xffaf) == 0x040e || (uni & 0xffce) == 0x254c) {
23 /* koi8-ru and koi8-u differ only on two characters */
24 if (uni == 0x040e)
25 out[0] = 0xbe;
26 else if (uni == 0x045e)
27 out[0] = 0xae;
28 else if (uni == 0x255d || uni == 0x256c)
29 return 0;
30 else
31 return p_nls->uni2char(uni, out, boundlen);
32 return 1;
33 }
34 else
35 /* fast path */
36 return p_nls->uni2char(uni, out, boundlen);
37}
38
39static int char2uni(const unsigned char *rawstring, int boundlen,
40 wchar_t *uni)
41{
42 int n;
43
44 if ((*rawstring & 0xef) != 0xae) {
45 /* koi8-ru and koi8-u differ only on two characters */
46 *uni = (*rawstring & 0x10) ? 0x040e : 0x045e;
47 return 1;
48 }
49
50 n = p_nls->char2uni(rawstring, boundlen, uni);
51 return n;
52}
53
54static struct nls_table table = {
55 /* .charset */ "koi8-ru",
56 /* .alias */ 0,
57 /* .uni2char */ uni2char,
58 /* .char2uni */ char2uni,
59 0, 0,
60 /* .owner */ THIS_MODULE,
61};
62
63static int __init init_nls_koi8_ru(void)
64{
65 p_nls = load_nls("koi8-u");
66
67 if (p_nls) {
68 table.charset2upper = p_nls->charset2upper;
69 table.charset2lower = p_nls->charset2lower;
70 return register_nls(&table);
71 }
72
73 return -EINVAL;
74}
75
76static void __exit exit_nls_koi8_ru(void)
77{
80}
81
84
85MODULE_LICENSE("Dual BSD/GPL");
#define EINVAL
Definition: acclib.h:90
#define __init
Definition: aclinux.h:211
GLdouble n
Definition: glext.h:7729
#define THIS_MODULE
Definition: module.h:269
int register_nls(struct nls_table *)
Definition: nls_base.c:162
void unload_nls(struct nls_table *)
Definition: nls_base.c:240
#define module_init(X)
Definition: module.h:278
int unregister_nls(struct nls_table *)
Definition: nls_base.c:185
#define MODULE_LICENSE(x)
Definition: module.h:270
#define __exit
Definition: module.h:267
struct nls_table * load_nls(char *)
Definition: nls_base.c:218
#define module_exit(X)
Definition: module.h:279
static struct nls_table * p_nls
Definition: nls_koi8-ru.c:14
static void __exit exit_nls_koi8_ru(void)
Definition: nls_koi8-ru.c:76
static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
Definition: nls_koi8-ru.c:39
static int __init init_nls_koi8_ru(void)
Definition: nls_koi8-ru.c:63
static int uni2char(const wchar_t uni, unsigned char *out, int boundlen)
Definition: nls_koi8-ru.c:16
static FILE * out
Definition: regtests2xml.c:44
#define ENAMETOOLONG
Definition: errno.h:55