2 Unix SMB/CIFS implementation.
3 minimal iconv implementation
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2002,2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 From samba 3.0 beta and GNU libiconv-1.8
22 It's bad but most of the time we can't use libc iconv service:
23 - it doesn't round trip for most encoding
24 - it doesn't know about Apple extension
29 #endif /* HAVE_CONFIG_H */
33 #include <arpa/inet.h>
35 #include <atalk/unicode.h>
36 #include <atalk/logger.h>
37 #include <atalk/byteorder.h>
39 #include "mac_hebrew.h"
41 static size_t mac_hebrew_pull(void *,char **, size_t *, char **, size_t *);
42 static size_t mac_hebrew_push(void *,char **, size_t *, char **, size_t *);
44 struct charset_functions charset_mac_hebrew =
50 CHARSET_CLIENT | CHARSET_MULTIBYTE,
56 /* ------------------------
57 * from unicode to mac hebrew code page
60 char_ucs2_to_mac_hebrew ( unsigned char *r, ucs2_t wc)
67 else if (wc >= 0x00a0 && wc < 0x0100)
68 c = mac_hebrew_page00[wc-0x00a0];
69 else if (wc >= 0x05b0 && wc < 0x05f0)
70 c = mac_hebrew_page05[wc-0x05b0];
71 else if (wc >= 0x2010 && wc < 0x2028)
72 c = mac_hebrew_page20[wc-0x2010];
73 else if (wc == 0x20aa)
75 else if (wc >= 0xfb18 && wc < 0xfb50)
76 c = mac_hebrew_pagefb[wc-0xfb18];
84 static size_t mac_hebrew_push( void *cd _U_, char **inbuf, size_t *inbytesleft,
85 char **outbuf, size_t *outbytesleft)
89 unsigned char *tmpptr = (unsigned char *) *outbuf;
91 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
92 ucs2_t inptr = SVAL((*inbuf),0);
93 if (inptr == 0x05b8) {
96 if (*inbytesleft >= 2 && SVAL((*inbuf),0) == 0xf87f ) {
106 else if (inptr == 0x05f2 && *inbytesleft >= 4 && SVAL((*inbuf),2) == 0x05b7) {
111 else if (inptr == 0xf86a && *inbytesleft >= 6 && SVAL((*inbuf),2) == 0x05dc && SVAL((*inbuf),4) == 0x05b9) {
116 else if (char_ucs2_to_mac_hebrew ( tmpptr, inptr)) {
124 (*outbytesleft) -= 1;
129 if (*inbytesleft > 0) {
137 /* ------------------------ */
139 char_mac_hebrew_to_ucs2 (ucs2_t *pwc, const unsigned char *s)
141 unsigned char c = *s;
147 unsigned short wc = mac_hebrew_2uni[c-0x80];
156 static size_t mac_hebrew_pull ( void *cd _U_, char **inbuf, size_t *inbytesleft,
157 char **outbuf, size_t *outbytesleft)
160 unsigned char *inptr;
163 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
164 inptr = (unsigned char *) *inbuf;
165 if (char_mac_hebrew_to_ucs2 ( &temp, inptr)) {
166 if (temp == 1) { /* 0x81 --> 0x05f2+0x05b7 */
167 if (*outbytesleft < 4) {
171 SSVAL((*outbuf),0,0x05f2);
172 SSVAL((*outbuf),2,0x05b7);
177 else if (temp == 2) { /* 0xc0 -> 0xf86a 0x05dc 0x05b9*/
178 if (*outbytesleft < 6) {
182 SSVAL((*outbuf),0,0xf86a);
183 SSVAL((*outbuf),2,0x05dc);
184 SSVAL((*outbuf),4,0x05b9);
189 else if (temp == 3) { /* 0xde --> 0x05b8 0xf87f */
190 if (*outbytesleft < 4) {
194 SSVAL((*outbuf),0,0x05b8);
195 SSVAL((*outbuf),2,0xf87f);
201 SSVAL((*outbuf),0,temp);
216 if (*inbytesleft > 0) {