ReactOS 0.4.16-dev-297-gc569aee
nls_base.c File Reference
#include <linux/module.h>
#include <linux/string.h>
#include <linux/config.h>
#include <linux/nls.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/spinlock.h>
Include dependency graph for nls_base.c:

Go to the source code of this file.

Classes

struct  utf8_table
 

Functions

int utf8_mbtowc (wchar_t *p, const __u8 *s, int n)
 
int utf8_mbstowcs (wchar_t *pwcs, const __u8 *s, int n)
 
int utf8_wctomb (__u8 *s, wchar_t wc, int maxlen)
 
int utf8_wcstombs (__u8 *s, const wchar_t *pwcs, int maxlen)
 
int register_nls (struct nls_table *nls)
 
int unregister_nls (struct nls_table *nls)
 
static struct nls_tablefind_nls (char *charset)
 
struct nls_tableload_nls (char *charset)
 
void unload_nls (struct nls_table *nls)
 
static int uni2char (wchar_t uni, unsigned char *out, int boundlen)
 
static int char2uni (const unsigned char *rawstring, int boundlen, wchar_t *uni)
 
 EXPORT_SYMBOL (register_nls)
 
 EXPORT_SYMBOL (unregister_nls)
 
 EXPORT_SYMBOL (unload_nls)
 
 EXPORT_SYMBOL (load_nls)
 
 EXPORT_SYMBOL (load_nls_default)
 
 EXPORT_SYMBOL (utf8_mbtowc)
 
 EXPORT_SYMBOL (utf8_mbstowcs)
 
 EXPORT_SYMBOL (utf8_wctomb)
 
 EXPORT_SYMBOL (utf8_wcstombs)
 
 MODULE_LICENSE ("Dual BSD/GPL")
 

Variables

struct nls_tabletables
 
spinlock_t nls_lock
 
static struct utf8_table utf8_table []
 
wchar_t charset2uni [256]
 
static unsigned char page00 [256]
 
static unsigned charpage_uni2charset [256]
 
static unsigned char charset2lower [256]
 
static unsigned char charset2upper [256]
 

Function Documentation

◆ char2uni()

static int char2uni ( const unsigned char rawstring,
int  boundlen,
wchar_t uni 
)
static

Definition at line 458 of file nls_base.c.

459{
460 *uni = charset2uni[*rawstring];
461 if (*uni == 0x0000)
462 return -EINVAL;
463 return 1;
464}
#define EINVAL
Definition: acclib.h:90
wchar_t charset2uni[256]
Definition: nls_base.c:245

◆ EXPORT_SYMBOL() [1/9]

EXPORT_SYMBOL ( load_nls  )

◆ EXPORT_SYMBOL() [2/9]

EXPORT_SYMBOL ( load_nls_default  )

◆ EXPORT_SYMBOL() [3/9]

EXPORT_SYMBOL ( register_nls  )

◆ EXPORT_SYMBOL() [4/9]

EXPORT_SYMBOL ( unload_nls  )

◆ EXPORT_SYMBOL() [5/9]

EXPORT_SYMBOL ( unregister_nls  )

◆ EXPORT_SYMBOL() [6/9]

EXPORT_SYMBOL ( utf8_mbstowcs  )

◆ EXPORT_SYMBOL() [7/9]

EXPORT_SYMBOL ( utf8_mbtowc  )

◆ EXPORT_SYMBOL() [8/9]

EXPORT_SYMBOL ( utf8_wcstombs  )

◆ EXPORT_SYMBOL() [9/9]

EXPORT_SYMBOL ( utf8_wctomb  )

◆ find_nls()

static struct nls_table * find_nls ( char charset)
static

Definition at line 202 of file nls_base.c.

203{
204 struct nls_table *nls;
206 for (nls = tables; nls; nls = nls->next) {
207 if (!strcmp(nls->charset, charset))
208 break;
209 if (nls->alias && !strcmp(nls->alias, charset))
210 break;
211 }
212 if (nls && !try_module_get(nls->owner))
213 nls = NULL;
215 return nls;
216}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
CFF_Charset charset
Definition: cffcmap.c:138
#define NULL
Definition: types.h:112
#define nls
Definition: kernel32.h:13
#define spin_unlock(sl)
Definition: module.h:307
#define spin_lock(sl)
Definition: module.h:306
#define try_module_get(x)
Definition: module.h:275
struct nls_table * tables
Definition: nls_base.c:22
spinlock_t nls_lock
Definition: nls_base.c:23
struct define * next
Definition: compiler.c:65

Referenced by load_nls().

◆ load_nls()

struct nls_table * load_nls ( char charset)

Definition at line 218 of file nls_base.c.

219{
220 struct nls_table *nls;
221#ifdef CONFIG_KMOD
222 int ret;
223#endif
224
226 if (nls)
227 return nls;
228
229#ifdef CONFIG_KMOD
230 ret = request_module("nls_%s", charset);
231 if (ret != 0) {
232 printk("Unable to load NLS charset %s\n", charset);
233 return NULL;
234 }
236#endif
237 return nls;
238}
#define printk
Definition: module.h:231
static struct nls_table * find_nls(char *charset)
Definition: nls_base.c:202
int ret

Referenced by DriverEntry(), Ext2ProcessGlobalProperty(), Ext2ProcessVolumeProperty(), init_nls_euc_jp(), and init_nls_koi8_ru().

◆ MODULE_LICENSE()

MODULE_LICENSE ( "Dual BSD/GPL"  )

◆ register_nls()

◆ uni2char()

static int uni2char ( wchar_t  uni,
unsigned char out,
int  boundlen 
)
static

Definition at line 441 of file nls_base.c.

442{
443 unsigned char *uni2charset;
444 unsigned char cl = uni & 0x00ff;
445 unsigned char ch = (uni & 0xff00) >> 8;
446
447 if (boundlen <= 0)
448 return -ENAMETOOLONG;
449
450 uni2charset = page_uni2charset[ch];
451 if (uni2charset && uni2charset[cl])
452 out[0] = uni2charset[cl];
453 else
454 return -EINVAL;
455 return 1;
456}
static unsigned char * page_uni2charset[256]
Definition: nls_base.c:364
static FILE * out
Definition: regtests2xml.c:44
#define ENAMETOOLONG
Definition: errno.h:55

◆ unload_nls()

void unload_nls ( struct nls_table nls)

Definition at line 240 of file nls_base.c.

241{
242 module_put(nls->owner);
243}
#define module_put(x)
Definition: module.h:276

Referenced by exit_nls_euc_jp(), and exit_nls_koi8_ru().

◆ unregister_nls()

◆ utf8_mbstowcs()

int utf8_mbstowcs ( wchar_t pwcs,
const __u8 s,
int  n 
)

Definition at line 79 of file nls_base.c.

80{
81 __u16 *op;
82 const __u8 *ip;
83 int size;
84
85 op = pwcs;
86 ip = s;
87 while (*ip && n > 0) {
88 if (*ip & 0x80) {
89 size = utf8_mbtowc(op, ip, n);
90 if (size == -1) {
91 /* Ignore character and move on */
92 ip++;
93 n--;
94 } else {
95 op++;
96 ip += size;
97 n -= size;
98 }
99 } else {
100 *op++ = *ip++;
101 n--;
102 }
103 }
104 return (int)(op - pwcs);
105}
u16 __u16
Definition: btrfs.h:18
u8 __u8
Definition: btrfs.h:17
UINT op
Definition: effect.c:236
GLdouble s
Definition: gl.h:2039
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
int utf8_mbtowc(wchar_t *p, const __u8 *s, int n)
Definition: nls_base.c:49
Definition: dhcpd.h:62

◆ utf8_mbtowc()

int utf8_mbtowc ( wchar_t p,
const __u8 s,
int  n 
)

Definition at line 49 of file nls_base.c.

50{
51 long l;
52 int c0, c, nc;
53 struct utf8_table *t;
54
55 nc = 0;
56 c0 = *s;
57 l = c0;
58 for (t = utf8_table; t->cmask; t++) {
59 nc++;
60 if ((c0 & t->cmask) == t->cval) {
61 l &= t->lmask;
62 if (l < t->lval)
63 return -1;
64 *p = (wchar_t)l;
65 return nc;
66 }
67 if (n <= nc)
68 return -1;
69 s++;
70 c = (*s ^ 0x80) & 0xFF;
71 if (c & 0xC0)
72 return -1;
73 l = (l << 6) | c;
74 }
75 return -1;
76}
r l[0]
Definition: byte_order.h:168
GLdouble GLdouble t
Definition: gl.h:2047
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
#define c
Definition: ke_i.h:80
int cmask
Definition: nls_base.c:30
long lval
Definition: nls_base.c:34
#define wchar_t
Definition: wchar.h:102

Referenced by char2uni(), and utf8_mbstowcs().

◆ utf8_wcstombs()

int utf8_wcstombs ( __u8 s,
const wchar_t pwcs,
int  maxlen 
)

Definition at line 136 of file nls_base.c.

137{
138 const __u16 *ip;
139 __u8 *op;
140 int size;
141
142 op = s;
143 ip = pwcs;
144 while (*ip && maxlen > 0) {
145 if (*ip > 0x7f) {
146 size = utf8_wctomb(op, *ip, maxlen);
147 if (size == -1) {
148 /* Ignore character and move on */
149 maxlen--;
150 } else {
151 op += size;
152 maxlen -= size;
153 }
154 } else {
155 *op++ = (__u8) *ip;
156 }
157 ip++;
158 }
159 return (int)(op - s);
160}
int utf8_wctomb(__u8 *s, wchar_t wc, int maxlen)
Definition: nls_base.c:108
#define __u8
Definition: types.h:12

◆ utf8_wctomb()

int utf8_wctomb ( __u8 s,
wchar_t  wc,
int  maxlen 
)

Definition at line 108 of file nls_base.c.

109{
110 long l;
111 int c, nc;
112 struct utf8_table *t;
113
114 if (s == 0)
115 return 0;
116
117 l = wc;
118 nc = 0;
119 for (t = utf8_table; t->cmask && maxlen; t++, maxlen--) {
120 nc++;
121 if (l <= t->lmask) {
122 c = t->shift;
123 *s = (__u8)(t->cval | (l >> c));
124 while (c > 0) {
125 c -= 6;
126 s++;
127 *s = 0x80 | (__u8)((l >> c) & 0x3F);
128 }
129 return nc;
130 }
131 }
132 return -1;
133}
long lmask
Definition: nls_base.c:33

Referenced by uni2char(), and utf8_wcstombs().

Variable Documentation

◆ charset2lower

unsigned char charset2lower[256]
static

Definition at line 368 of file nls_base.c.

◆ charset2uni

wchar_t charset2uni[256]

Definition at line 245 of file nls_base.c.

Referenced by char2uni().

◆ charset2upper

unsigned char charset2upper[256]
static

Definition at line 404 of file nls_base.c.

◆ nls_lock

spinlock_t nls_lock

Definition at line 23 of file nls_base.c.

Referenced by Ext2LoadAllNls(), find_nls(), register_nls(), and unregister_nls().

◆ page00

unsigned char page00[256]
static

Definition at line 328 of file nls_base.c.

◆ page_uni2charset

unsigned char* page_uni2charset[256]
static
Initial value:
= {
}
static unsigned char page00[256]
Definition: nls_base.c:328

Definition at line 364 of file nls_base.c.

Referenced by uni2char().

◆ tables

◆ utf8_table

Initial value:
=
{
{0x80, 0x00, 0*6, 0x7F, 0, },
{0xE0, 0xC0, 1*6, 0x7FF, 0x80, },
{0xF0, 0xE0, 2*6, 0xFFFF, 0x800, },
{0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, },
{0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, },
{0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, },
{0, }
}

Definition at line 37 of file nls_base.c.