source: trunk/gsdl/packages/wv-0.5.44-gs/src/iconv/tis-620.c@ 1468

Last change on this file since 1468 was 1468, checked in by paynter, 24 years ago

The wv Packages from www.wvware.com is used to convert Word documents into
HTML. This is an adaptation of wv version 0.5.44 for greenstone; it is
called by the gsConvert.pl script.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* Originally contributed to mswordview by */
2#include <stdlib.h>
3#include <stdio.h>
4#include "wv.h"
5#include "iconv_internal.h"
6
7
8
9#define Wchar1 (1UL<<7)-1
10
11union {
12 unsigned char ch[2];
13 unsigned long ulong;
14} un;
15
16struct unichar {
17 unsigned char ch0;
18 unsigned char ch1;
19};
20
21static struct unichar tis2uni[256] = {
22 /* 0x00*/
23 {0x00, 0x00}, {0x01, 0x00}, {0x02, 0x00}, {0x03, 0x00},
24 {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x00},
25 {0x08, 0x00}, {0x09, 0x00}, {0x0a, 0x00}, {0x0b, 0x00},
26 {0x0c, 0x00}, {0x0d, 0x00}, {0x0e, 0x00}, {0x0f, 0x00},
27 /* 0x10*/
28 {0x10, 0x00}, {0x11, 0x00}, {0x12, 0x00}, {0x13, 0x00},
29 {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x17, 0x00},
30 {0x18, 0x00}, {0x19, 0x00}, {0x1a, 0x00}, {0x1b, 0x00},
31 {0x1c, 0x00}, {0x1d, 0x00}, {0x1e, 0x00}, {0x1f, 0x00},
32 /* 0x20*/
33 {0x20, 0x00}, {0x21, 0x00}, {0x22, 0x00}, {0x23, 0x00},
34 {0x24, 0x00}, {0x25, 0x00}, {0x26, 0x00}, {0x27, 0x00},
35 {0x28, 0x00}, {0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00},
36 {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x00}, {0x2f, 0x00},
37 /* 0x30*/
38 {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00},
39 {0x34, 0x00}, {0x35, 0x00}, {0x36, 0x00}, {0x37, 0x00},
40 {0x38, 0x00}, {0x39, 0x00}, {0x3a, 0x00}, {0x3b, 0x00},
41 {0x3c, 0x00}, {0x3d, 0x00}, {0x3e, 0x00}, {0x3f, 0x00},
42 /* 0x40*/
43 {0x40, 0x00}, {0x41, 0x00}, {0x42, 0x00}, {0x43, 0x00},
44 {0x44, 0x00}, {0x45, 0x00}, {0x46, 0x00}, {0x47, 0x00},
45 {0x48, 0x00}, {0x49, 0x00}, {0x4a, 0x00}, {0x4b, 0x00},
46 {0x4c, 0x00}, {0x4d, 0x00}, {0x4e, 0x00}, {0x4f, 0x00},
47 /* 0x50*/
48 {0x50, 0x00}, {0x51, 0x00}, {0x52, 0x00}, {0x53, 0x00},
49 {0x54, 0x00}, {0x55, 0x00}, {0x56, 0x00}, {0x57, 0x00},
50 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x00}, {0x5b, 0x00},
51 {0x5c, 0x00}, {0x5d, 0x00}, {0x5e, 0x00}, {0x5f, 0x00},
52 /* 0x60*/
53 {0x60, 0x00}, {0x61, 0x00}, {0x62, 0x00}, {0x63, 0x00},
54 {0x64, 0x00}, {0x65, 0x00}, {0x66, 0x00}, {0x67, 0x00},
55 {0x68, 0x00}, {0x69, 0x00}, {0x6a, 0x00}, {0x6b, 0x00},
56 {0x6c, 0x00}, {0x6d, 0x00}, {0x6e, 0x00}, {0x6f, 0x00},
57 /* 0x70*/
58 {0x70, 0x00}, {0x71, 0x00}, {0x72, 0x00}, {0x73, 0x00},
59 {0x74, 0x00}, {0x75, 0x00}, {0x76, 0x00}, {0x77, 0x00},
60 {0x78, 0x00}, {0x79, 0x00}, {0x7a, 0x00}, {0x7b, 0x00},
61 {0x7c, 0x00}, {0x7d, 0x00}, {0x7e, 0x00}, {0x7f, 0x00},
62 /* 0x80*/
63 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
64 {0x00, 0x00}, {0x26, 0x20}, {0x00, 0x00}, {0x00, 0x00},
65 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
66 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
67 /* 0x90*/
68 {0x00, 0x00}, {0x18, 0x20}, {0x19, 0x20}, {0x1c, 0x20},
69 {0x1d, 0x20}, {0x22, 0x20}, {0x13, 0x20}, {0x14, 0x20},
70 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
71 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
72 /* 0xa0*/
73 {0xa0, 0x00}, {0x01, 0x0e}, {0x02, 0x0e}, {0x03, 0x0e},
74 {0x04, 0x0e}, {0x05, 0x0e}, {0x06, 0x0e}, {0x07, 0x0e},
75 {0x08, 0x0e}, {0x09, 0x0e}, {0x0a, 0x0e}, {0x0b, 0x0e},
76 {0x0c, 0x0e}, {0x0d, 0x0e}, {0x0e, 0x0e}, {0x0f, 0x0e},
77 /* 0xb0*/
78 {0x10, 0x0e}, {0x11, 0x0e}, {0x12, 0x0e}, {0x13, 0x0e},
79 {0x14, 0x0e}, {0x15, 0x0e}, {0x16, 0x0e}, {0x17, 0x0e},
80 {0x18, 0x0e}, {0x19, 0x0e}, {0x1a, 0x0e}, {0x1b, 0x0e},
81 {0x1c, 0x0e}, {0x1d, 0x0e}, {0x1e, 0x0e}, {0x1f, 0x0e},
82 /* 0xc0*/
83 {0x20, 0x0e}, {0x21, 0x0e}, {0x22, 0x0e}, {0x23, 0x0e},
84 {0x24, 0x0e}, {0x25, 0x0e}, {0x26, 0x0e}, {0x27, 0x0e},
85 {0x28, 0x0e}, {0x29, 0x0e}, {0x2a, 0x0e}, {0x2b, 0x0e},
86 {0x2c, 0x0e}, {0x2d, 0x0e}, {0x2e, 0x0e}, {0x2f, 0x0e},
87 /* 0xd0*/
88 {0x30, 0x0e}, {0x31, 0x0e}, {0x32, 0x0e}, {0x33, 0x0e},
89 {0x34, 0x0e}, {0x35, 0x0e}, {0x36, 0x0e}, {0x37, 0x0e},
90 {0x38, 0x0e}, {0x39, 0x0e}, {0x3a, 0x0e}, {0x00, 0x00},
91 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x3f, 0x0e},
92 /* 0xe0*/
93 {0x40, 0x0e}, {0x41, 0x0e}, {0x42, 0x0e}, {0x43, 0x0e},
94 {0x44, 0x0e}, {0x45, 0x0e}, {0x46, 0x0e}, {0x47, 0x0e},
95 {0x48, 0x0e}, {0x49, 0x0e}, {0x4a, 0x0e}, {0x4b, 0x0e},
96 {0x4c, 0x0e}, {0x4d, 0x0e}, {0x4e, 0x0e}, {0x4f, 0x0e},
97 /* 0xf0*/
98 {0x50, 0x0e}, {0x51, 0x0e}, {0x52, 0x0e}, {0x53, 0x0e},
99 {0x54, 0x0e}, {0x55, 0x0e}, {0x56, 0x0e}, {0x57, 0x0e},
100 {0x58, 0x0e}, {0x59, 0x0e}, {0x5a, 0x0e}, {0x5b, 0x0e},
101 {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00}, {0x00, 0x00},
102};
103
104size_t wvConvertUnicodeToTIS620(const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
105 {
106 size_t ret=0;
107 U16 c1,c2;
108 while( (*inbytesleft) && (*outbytesleft) )
109 {
110 c2 = (U8)**inbuf;
111 (*inbuf)++;
112 c2 = (c2<< 8)&0xFF00;
113 c2 += (U8)**inbuf;
114 (*inbuf)++;
115 (*inbytesleft)-=2;
116
117 c1 = ConvertUnicodeToTIS620(c2);
118 if (c1 == 0xffff)
119 **outbuf = '?';
120 else
121 **outbuf = (char)c1;
122 (*outbuf)++;
123 (*outbytesleft)--;
124 ret++;
125 }
126 return(ret);
127 }
128
129
130U16 ConvertUnicodeToTIS620(U16 wc)
131 {
132 U16 ret;
133 if(wc & (~Wchar1))
134 {
135 un.ulong = wc;
136 ret = un.ch[0];
137 if(un.ch[1] == 0x0e)
138 ret += 0xa0;
139 return(ret);
140 }
141 ret = 0x00 | wc;
142 return(ret);
143 }
Note: See TracBrowser for help on using the repository browser.