~ubuntu-branches/ubuntu/gutsy/lv/gutsy

« back to all changes in this revision

Viewing changes to src/unirev.c

  • Committer: Bazaar Package Importer
  • Author(s): GOTO Masanori
  • Date: 2003-11-16 01:21:59 UTC
  • Revision ID: james.westby@ubuntu.com-20031116012159-wpu27qhoxzskmjy0
Tags: upstream-4.50
ImportĀ upstreamĀ versionĀ 4.50

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * unirev.c
 
3
 *
 
4
 * All rights reserved. Copyright (C) 1996 by NARITA Tomio.
 
5
 * $Id: unirev.c,v 1.6 2003/11/13 03:08:19 nrt Exp $
 
6
 */
 
7
/*
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 */
 
22
 
 
23
#include <import.h>
 
24
#include <itable.h>
 
25
#include <uty.h>
 
26
#include <big5.h>
 
27
#include <begin.h>
 
28
#include <unirev.h>
 
29
 
 
30
#define ISO8859_TO_UNI
 
31
#define BIG5_TO_UNI
 
32
#define GB_TO_UNI
 
33
#define JIS_TO_UNI
 
34
#define KSC_TO_UNI
 
35
 
 
36
#ifdef ISO8859_TO_UNI
 
37
#include <iso88592.rev>
 
38
#include <iso88593.rev>
 
39
#include <iso88594.rev>
 
40
#include <iso88595.rev>
 
41
#include <iso88596.rev>
 
42
#include <iso88597.rev>
 
43
#include <iso88598.rev>
 
44
#include <iso88599.rev>
 
45
#include <iso885910.rev>
 
46
#include <iso885911.rev>
 
47
#include <iso885913.rev>
 
48
#include <iso885914.rev>
 
49
#include <iso885915.rev>
 
50
#include <iso885916.rev>
 
51
#endif
 
52
 
 
53
#ifdef BIG5_TO_UNI
 
54
#include <big5.rev>
 
55
#endif
 
56
 
 
57
#ifdef GB_TO_UNI
 
58
#include <gb2312.rev>
 
59
#endif
 
60
 
 
61
#ifdef JIS_TO_UNI
 
62
#include <jis0208.rev>
 
63
#include <jis0212.rev>
 
64
#endif
 
65
 
 
66
#ifdef KSC_TO_UNI
 
67
#include <ksc5601.rev>
 
68
#endif
 
69
 
 
70
private ic_t ISO8859_1toUNI( ic_t ic, byte *cset )
 
71
{
 
72
  *cset = UNICODE;
 
73
  return ic | 0x80;
 
74
}
 
75
 
 
76
private ic_t CNStoUNI( ic_t ic, byte *cset )
 
77
{
 
78
  ic_t res;
 
79
 
 
80
  res = CNStoBIG5( ic, cset );
 
81
  if( BIG5 == *cset )
 
82
    return RevUNI( res, cset );
 
83
  else
 
84
    return res;
 
85
}
 
86
 
 
87
private ic_t ASCIItoUNI( ic_t ic, byte *cset )
 
88
{
 
89
  *cset = ASCII;
 
90
  return ic;
 
91
}
 
92
 
 
93
private ic_t JIS0201ROMANtoUNI( ic_t ic, byte *cset )
 
94
{
 
95
  if( ic == 0x5c ){
 
96
    *cset = UNICODE;
 
97
    return (ic_t)0x00a5;
 
98
  } else if( ic == 0x7e ){
 
99
    *cset = UNICODE;
 
100
    return (ic_t)0x203e;
 
101
  }
 
102
  *cset = ASCII;
 
103
  return ic;
 
104
}
 
105
 
 
106
private ic_t JIS0201KANAtoUNI( ic_t ic, byte *cset )
 
107
{
 
108
  *cset = UNICODE;
 
109
  return ic + 0xff40U;
 
110
}
 
111
 
 
112
typedef ic_t (*uniconv_t)( ic_t ic, byte *cset );
 
113
 
 
114
typedef struct {
 
115
  ic_t          *directmap;
 
116
  codes_t       *map;
 
117
  int           size;
 
118
  uniconv_t     conv;
 
119
} rev_table_t;
 
120
 
 
121
private rev_table_t revTable[ PSEUDO ] = {
 
122
  { NULL, NULL, 0, ASCIItoUNI },                /* ASCII */
 
123
  { NULL, NULL, 0, JIS0201ROMANtoUNI },         /* X0201ROMAN */
 
124
  { NULL, NULL, 0, JIS0201KANAtoUNI },          /* X0201KANA */
 
125
  { NULL, NULL, 0, ISO8859_1toUNI },            /* ISO8859_1 */
 
126
#ifdef ISO8859_TO_UNI
 
127
  { revISO8859_2, NULL, 0, NULL },              /* ISO8859_2 */
 
128
  { revISO8859_3, NULL, 0, NULL },              /* ISO8859_3 */
 
129
  { revISO8859_4, NULL, 0, NULL },              /* ISO8859_4 */
 
130
  { revISO8859_5, NULL, 0, NULL },              /* ISO8859_5 */
 
131
  { revISO8859_6, NULL, 0, NULL },              /* ISO8859_6 */
 
132
  { revISO8859_7, NULL, 0, NULL },              /* ISO8859_7 */
 
133
  { revISO8859_8, NULL, 0, NULL },              /* ISO8859_8 */
 
134
  { revISO8859_9, NULL, 0, NULL },              /* ISO8859_9 */
 
135
  { revISO8859_10, NULL, 0, NULL },             /* ISO8859_10 */
 
136
  { revISO8859_11, NULL, 0, NULL },             /* ISO8859_11 */
 
137
  { revISO8859_13, NULL, 0, NULL },             /* ISO8859_13 */
 
138
  { revISO8859_14, NULL, 0, NULL },             /* ISO8859_14 */
 
139
  { revISO8859_15, NULL, 0, NULL },             /* ISO8859_15 */
 
140
  { revISO8859_16, NULL, 0, NULL },             /* ISO8859_16 */
 
141
#else
 
142
  { NULL, NULL, 0, NULL },
 
143
  { NULL, NULL, 0, NULL },
 
144
  { NULL, NULL, 0, NULL },
 
145
  { NULL, NULL, 0, NULL },
 
146
  { NULL, NULL, 0, NULL },
 
147
  { NULL, NULL, 0, NULL },
 
148
  { NULL, NULL, 0, NULL },
 
149
  { NULL, NULL, 0, NULL },
 
150
  { NULL, NULL, 0, NULL },
 
151
  { NULL, NULL, 0, NULL },
 
152
  { NULL, NULL, 0, NULL },
 
153
  { NULL, NULL, 0, NULL },
 
154
  { NULL, NULL, 0, NULL },
 
155
  { NULL, NULL, 0, NULL },
 
156
#endif
 
157
#ifdef JIS_TO_UNI
 
158
  { NULL, revJIS0208, 6878, NULL },             /* C6226 */
 
159
#else
 
160
  { NULL, NULL, 0, NULL },
 
161
#endif
 
162
#ifdef GB_TO_UNI
 
163
  { NULL, revGB2312, 7444, NULL },              /* GB2312 */
 
164
#else
 
165
  { NULL, NULL, 0, NULL },
 
166
#endif
 
167
#ifdef JIS_TO_UNI
 
168
  { NULL, revJIS0208, 6878, NULL },             /* X0208 */
 
169
#else
 
170
  { NULL, NULL, 0, NULL },
 
171
#endif
 
172
#ifdef KSC_TO_UNI
 
173
  { NULL, revKSC5601, 8223, NULL },             /* KSC5601 */
 
174
#else
 
175
  { NULL, NULL, 0, NULL },
 
176
#endif
 
177
#ifdef JIS_TO_UNI
 
178
  { NULL, revJIS0212, 6066, NULL },             /* X0212 */
 
179
#else
 
180
  { NULL, NULL, 0, NULL },
 
181
#endif
 
182
  { NULL, NULL, 0, NULL },                      /* ISO_IR_165 */
 
183
  { NULL, NULL, 0, CNStoUNI },                  /* CNS_1 */
 
184
  { NULL, NULL, 0, CNStoUNI },                  /* CNS_2 */
 
185
  { NULL, NULL, 0, CNStoUNI },                  /* CNS_3 */
 
186
  { NULL, NULL, 0, CNStoUNI },                  /* CNS_4 */
 
187
  { NULL, NULL, 0, NULL },                      /* CNS_5 */
 
188
  { NULL, NULL, 0, NULL },                      /* CNS_6 */
 
189
  { NULL, NULL, 0, NULL },                      /* CNS_7 */
 
190
  { NULL, NULL, 0, NULL },                      /* JIS X 0213-2000 Plane 1 */
 
191
  { NULL, NULL, 0, NULL },                      /* JIS X 0213-2000 Plane 2 */
 
192
#ifdef BIG5_TO_UNI
 
193
  { NULL, revBIG5, 13702, NULL }                /* BIG5 */
 
194
#else
 
195
  { NULL, NULL, 0, NULL }
 
196
#endif
 
197
};
 
198
 
 
199
public ic_t RevUNI( ic_t ic, byte *cset )
 
200
{
 
201
  ic_t res;
 
202
 
 
203
  if( revTable[ (int)*cset ].map ){
 
204
    if( 0 < (res = BinarySearch( revTable[ (int)*cset ].map,
 
205
                                       revTable[ (int)*cset ].size,
 
206
                                       ic )) ){
 
207
      *cset = UNICODE;
 
208
      return res;
 
209
    }
 
210
  } else if( revTable[ (int)*cset ].conv ){
 
211
    return (*revTable[ (int)*cset ].conv)( ic, cset );
 
212
  } else if( revTable[ (int)*cset ].directmap ){
 
213
    if( 0x20 <= ic && ic < 0x80 ){
 
214
      if( (ic_t)0 != (res = revTable[ (int)*cset ].directmap[ ic - 0x20 ]) ){
 
215
        *cset = UNICODE;
 
216
        return res;
 
217
      }
 
218
    }
 
219
  }
 
220
 
 
221
  *cset = ASCII;
 
222
  return (ic_t)'?';
 
223
}
 
224
 
 
225
public void ConvertToUNI( i_str_t *istr )
 
226
{
 
227
  int i;
 
228
 
 
229
  for( i = 0 ; NOSET != istr[ i ].charset ; i++ ){
 
230
    if( istr[ i ].charset < UNICODE )
 
231
      istr[ i ].c = RevUNI( istr[ i ].c, &istr[ i ].charset );
 
232
  }
 
233
}