ReactOS 0.4.16-dev-927-g467dec4
tojisjms.cpp
Go to the documentation of this file.
1/***
2*tojisjms.c: Converts JIS to JMS code, and JMS to JIS code.
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Convert JIS code into Microsoft Kanji code, and vice versa.
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
15#include <locale.h>
16
17/***
18*unsigned int _mbcjistojms(c) - Converts JIS code to Microsoft Kanji Code.
19*
20*Purpose:
21* Convert JIS code to Microsoft Kanji code.
22*
23*Entry:
24* unsigned int c - JIS code to be converted. First byte is the upper
25* 8 bits, and second is the lower 8 bits.
26*
27*Exit:
28* Returns related Microsoft Kanji Code. First byte is the upper 8 bits
29* and second byte is the lower 8 bits.
30*
31*Exceptions:
32* If c is out of range, _mbcjistojms returns zero.
33*
34*******************************************************************************/
35
36extern "C" unsigned int __cdecl _mbcjistojms_l(
37 unsigned int c,
39 )
40{
41 unsigned int h, l;
42 _LocaleUpdate _loc_update(plocinfo);
43
44 if (_loc_update.GetLocaleT()->mbcinfo->mbcodepage != _KANJI_CP)
45 return (c);
46
47 h = (c >> 8) & 0xff;
48 l = c & 0xff;
49 if (h < 0x21 || h > 0x7e || l < 0x21 || l > 0x7e)
50 {
51 errno = EILSEQ;
52 return 0;
53 }
54 if (h & 0x01) { /* first byte is odd */
55 if (l <= 0x5f)
56 l += 0x1f;
57 else
58 l += 0x20;
59 }
60 else
61 l += 0x7e;
62
63 h = ((h - 0x21) >> 1) + 0x81;
64 if (h > 0x9f)
65 h += 0x40;
66 return (h << 8) | l;
67}
68extern "C" unsigned int (__cdecl _mbcjistojms)(
69 unsigned int c
70 )
71{
72 return _mbcjistojms_l(c, nullptr);
73}
74
75
76/***
77*unsigned int _mbcjmstojis(c) - Converts Microsoft Kanji code into JIS code.
78*
79*Purpose:
80* To convert Microsoft Kanji code into JIS code.
81*
82*Entry:
83* unsigned int c - Microsoft Kanji code to be converted. First byte is
84* the upper 8 bits, and the second is the lower 8 bits.
85*
86*Exit:
87* Returns related JIS Code. First byte is the upper 8 bits and the second
88* byte is the lower 8 bits. If c is out of range, return zero.
89*
90*Exceptions:
91*
92*******************************************************************************/
93
94extern "C" unsigned int __cdecl _mbcjmstojis_l(
95 unsigned int c,
97 )
98{
99 unsigned int h, l;
100 _LocaleUpdate _loc_update(plocinfo);
101
102 if ( _loc_update.GetLocaleT()->mbcinfo->mbcodepage != _KANJI_CP )
103 return (c);
104
105 h = (c >> 8) & 0xff;
106 l = c & 0xff;
107
108 /* make sure input is valid shift-JIS */
109 if ( (!(_ismbblead_l(h, _loc_update.GetLocaleT()))) || (!(_ismbbtrail_l(l, _loc_update.GetLocaleT()))) )
110 {
111 errno = EILSEQ;
112 return 0;
113 }
114
115 h -= (h >= 0xa0) ? 0xc1 : 0x81;
116 if(l >= 0x9f) {
117 c = (h << 9) + 0x2200;
118 c |= l - 0x7e;
119 } else {
120 c = (h << 9) + 0x2100;
121 c |= l - ((l <= 0x7e) ? 0x1f : 0x20);
122 }
123
124 /* not all shift-JIS maps to JIS, so make sure output is valid */
125 if ( (c>0x7E7E) || (c<0x2121) || ((c&0xFF)>0x7E) || ((c&0xFF)<0x21) )
126 {
127 errno = EILSEQ;
128 return 0;
129 }
130
131 return c;
132}
133extern "C" unsigned int (__cdecl _mbcjmstojis)(
134 unsigned int c
135 )
136{
137 return _mbcjmstojis_l(c, nullptr);
138}
#define __cdecl
Definition: accygwin.h:79
r l[0]
Definition: byte_order.h:168
#define _ismbblead_l(_c, p)
#define _ismbbtrail_l(_c, p)
#define _KANJI_CP
Definition: mbctype.h:53
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
_Check_return_ _CRTIMP unsigned int __cdecl _mbcjmstojis(_In_ unsigned int _Ch)
_Check_return_ _CRTIMP unsigned int __cdecl _mbcjistojms(_In_ unsigned int _Ch)
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define c
Definition: ke_i.h:80
#define errno
Definition: errno.h:18
#define EILSEQ
Definition: errno.h:109
unsigned int __cdecl _mbcjistojms_l(unsigned int c, _locale_t plocinfo)
Definition: tojisjms.cpp:36
unsigned int __cdecl _mbcjmstojis_l(unsigned int c, _locale_t plocinfo)
Definition: tojisjms.cpp:94