Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / gnu / gcj / convert / natInput_EUCJIS.cc
blob42562b9cb7d31e96032e8be3f4d51ba24f4b08df
1 /* Copyright (C) 1999 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 #include <config.h>
10 #include <gcj/cni.h>
11 #include <gnu/gcj/convert/Input_EUCJIS.h>
13 #define ERROR_CHAR 0xFFFD
15 extern unsigned short JIS0208_to_Unicode[84][94];
16 extern unsigned short JIS0212_to_Unicode[76][94];
18 jint
19 gnu::gcj::convert::Input_EUCJIS::read(jcharArray outbuffer, jint outpos,
20 jint count)
22 jint start_outpos = outpos;
23 for (;;)
25 if (outpos - start_outpos >= count)
26 break;
27 if (inpos >= inlength)
28 break;
29 int b = ((unsigned char*) elements(inbuffer))[inpos++];
30 if (codeset == 0) // ASCII or JIS-Roman
32 if (b < 128)
34 #if 1
35 // Technically, we should translate 0x5c to Yen symbol;
36 // in practice, it is not clear.
37 if (b == 0x5c)
38 b = 0x00A5; // Yen sign.
39 #endif
40 elements(outbuffer)[outpos++] = (char) b;
42 else
44 if (b == 0x8E) // SS2
45 codeset = 2;
46 else if (b == 0x8F) // SS3
47 codeset = 3;
48 else
50 codeset = 1;
51 first_byte = b;
55 else if (codeset == 1) // JIS X 0208:1997
57 first_byte -= 0x80 + 33;
58 b -= 0x80 + 33;
59 if ((unsigned) first_byte >= 84 || (unsigned) b >= 94)
60 b = ERROR_CHAR;
61 else
63 b = JIS0208_to_Unicode[first_byte][b];
64 if (b == 0)
65 b = ERROR_CHAR;
67 elements(outbuffer)[outpos++] = b;
68 codeset = 0;
70 else if (codeset == 2) // Half-width katakana
72 if (b >= 0xA1 && b <= 0xDF)
73 b += 0xFF61 - 0xA1;
74 else
75 b = ERROR_CHAR;
76 elements(outbuffer)[outpos++] = b;
77 codeset = 0;
79 else if (codeset == 3) // second byte of JIS X 0212-1990
81 first_byte = b;
82 codeset = 4;
84 else // codeset == 4 // third byte of JIS X 0212-1990
86 first_byte -= 0x80 + 34;
87 b -= 0x80 + 33;
88 if ((unsigned) first_byte >= 76 || (unsigned) b >= 94)
89 b = ERROR_CHAR;
90 else
92 b = JIS0208_to_Unicode[first_byte][b];
93 if (b == 0)
94 b = ERROR_CHAR;
96 elements(outbuffer)[outpos++] = b;
97 codeset = 0;
100 return outpos - start_outpos;