OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-newlib/] [newlib-1.17.0/] [newlib/] [libc/] [ctype/] [jp2uc.c] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 jlechner
/* Routine to translate from Japanese characters to Unicode */
2
 
3
/* Copyright (c) 2002 Red Hat Incorporated.
4
   All rights reserved.
5
 
6
   Redistribution and use in source and binary forms, with or without
7
   modification, are permitted provided that the following conditions are met:
8
 
9
     Redistributions of source code must retain the above copyright
10
     notice, this list of conditions and the following disclaimer.
11
 
12
     Redistributions in binary form must reproduce the above copyright
13
     notice, this list of conditions and the following disclaimer in the
14
     documentation and/or other materials provided with the distribution.
15
 
16
     The name of Red Hat Incorporated may not be used to endorse
17
     or promote products derived from this software without specific
18
     prior written permission.
19
 
20
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
   ARE DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
24
   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
 
32
#include <newlib.h>
33
 
34
#ifdef _MB_CAPABLE
35
 
36
#include <_ansi.h>
37
#include <wctype.h>
38
#include "local.h"
39
#include "jp2uc.h"
40
 
41
wint_t
42
_DEFUN (__jp2uc, (c, type), wint_t c _AND int type)
43
{
44
  int index, adj;
45
  unsigned char byte1, byte2;
46
  wint_t ret;
47
 
48
  /* we actually use tables of EUCJP to Unicode.  For JIS, we simply
49
     note that EUCJP is essentially JIS with the top bits on in each
50
     byte and translate to EUCJP.  For SJIS, we do a translation to EUCJP before
51
     accessing the tables. */
52
  switch (type)
53
    {
54
    case JP_JIS:
55
      byte1 = (c >> 8) + 0x80;
56
      byte2 = (c & 0xff) + 0x80;
57
      break;
58
    case JP_EUCJP:
59
      byte1 = (c >> 8);
60
      byte2 = (c & 0xff);
61
      break;
62
    case JP_SJIS:
63
      byte1 = c >> 8;
64
      byte2 = c & 0xff;
65
      if (byte2 <= 0x9e)
66
        {
67
          adj = 0xa1 - 0x22;
68
          byte2 = (byte2 - 31) + 0xa1;
69
        }
70
      else
71
        {
72
          adj = 0xa1 - 0x21;
73
          byte2 = (byte2 - 126) + 0xa1;
74
        }
75
      if (byte1 <= 0x9f)
76
        byte1 = ((byte1 - 112) << 1) + adj;
77
      else
78
        byte1 = ((byte1 - 176) << 1) + adj;
79
      break;
80
    default:
81
      return WEOF;
82
    }
83
 
84
  /* find conversion in jp2uc arrays */
85
 
86
  /* handle larger ranges first */
87
  if (byte1 >= 0xb0 && byte1 <= 0xcf && c <= 0xcfd3)
88
    {
89
      index = (byte1 - 0xb0) * 0xfe + (byte2 - 0xa1);
90
      return b02cf[index];
91
    }
92
  else if (byte1 >= 0xd0 && byte1 <= 0xf4 && c <= 0xf4a6)
93
    {
94
      index = (byte1 - 0xd0) * 0xfe + (byte2 - 0xa1);
95
      return d02f4[index];
96
    }
97
 
98
  /* handle smaller ranges here */
99
  switch (byte1)
100
    {
101
    case 0xA1:
102
      return (wint_t)a1[byte2 - 0xa1];
103
    case 0xA2:
104
      ret = a2[byte2 - 0xa1];
105
      if (ret != 0)
106
        return (wint_t)ret;
107
      break;
108
    case 0xA3:
109
      if (a3[byte2 - 0xa1])
110
        return (wint_t)(0xff00 + (byte2 - 0xa0));
111
      break;
112
    case 0xA4:
113
      if (byte2 <= 0xf3)
114
        return (wint_t)(0x3000 + (byte2 - 0x60));
115
      break;
116
    case 0xA5:
117
      if (byte2 <= 0xf6)
118
        return (wint_t)(0x3000 + byte2);
119
      break;
120
    case 0xA6:
121
      ret = 0;
122
      if (byte2 <= 0xd8)
123
        ret = (wint_t)a6[byte2 - 0xa1];
124
      if (ret != 0)
125
        return ret;
126
      break;
127
    case 0xA7:
128
      ret = 0;
129
      if (byte2 <= 0xf1)
130
        ret = (wint_t)a7[byte2 - 0xa1];
131
      if (ret != 0)
132
        return ret;
133
      break;
134
    case 0xA8:
135
      if (byte2 <= 0xc0)
136
        return (wint_t)a8[byte2 - 0xa1];
137
      break;
138
    default:
139
      return WEOF;
140
    }
141
 
142
  return WEOF;
143
}
144
 
145
#endif /* _MB_CAPABLE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.