]> arthur.barton.de Git - netatalk.git/blob - libatalk/unicode/charsets/mac_greek.c
f41846d7c5151b785afd8c41cafcc26a15691646
[netatalk.git] / libatalk / unicode / charsets / mac_greek.c
1 /* 
2    Unix SMB/CIFS implementation.
3    minimal iconv implementation
4    Copyright (C) Andrew Tridgell 2001
5    Copyright (C) Jelmer Vernooij 2002,2003
6    Copyright (C) Panos Christeas 2006
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21    
22    From samba 3.0 beta and GNU libiconv-1.8
23    It's bad but most of the time we can't use libc iconv service:
24    - it doesn't round trip for most encoding
25    - it doesn't know about Apple extension
26
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif /* HAVE_CONFIG_H */
32 #include <stdlib.h>
33 #include <netatalk/endian.h>
34 #include <atalk/unicode.h>
35
36 #include "mac_greek.h"
37 #include "generic_mb.h"
38
39 static size_t   mac_greek_pull(void *,char **, size_t *, char **, size_t *);
40 static size_t   mac_greek_push(void *,char **, size_t *, char **, size_t *);
41
42 struct charset_functions charset_mac_greek =
43 {
44         "MAC_GREEK",
45         6,
46         mac_greek_pull,
47         mac_greek_push,
48         CHARSET_CLIENT | CHARSET_MULTIBYTE,
49         NULL, NULL
50 };
51
52 /* ------------------------ */
53 static int
54 char_ucs2_to_mac_greek ( unsigned char *r, ucs2_t wc)
55 {
56   unsigned char c = 0;
57   if (wc < 0x0080) {
58     *r = wc;
59     return 1;
60   }
61   else if (wc >= 0x00a0 && wc < 0x0100)
62     c = mac_greek_page00[wc-0x00a0];
63   else if (wc == 0x0153)
64     c = 0xcf;
65   else if (wc >= 0x0380 && wc < 0x03d0)
66     c = mac_greek_page03[wc-0x0380];
67   else if (wc >= 0x2010 && wc < 0x2038)
68     c = mac_greek_page20[wc-0x2010];
69   else if (wc == 0x2122)
70     c = 0x93;
71   else if (wc >= 0x2248 && wc < 0x2268)
72     c = mac_greek_page22[wc-0x2248];
73   if (c != 0) {
74     *r = c;
75     return 1;
76   }
77  return 0;
78  }
79
80 static size_t mac_greek_push( void *cd, char **inbuf, size_t *inbytesleft,
81                          char **outbuf, size_t *outbytesleft)
82 {
83         /* No special handling required */
84         return (size_t) mb_generic_push( char_ucs2_to_mac_greek, cd, inbuf, inbytesleft, outbuf, outbytesleft);
85 }
86
87 /* ------------------------ */
88 static int
89 char_mac_greek_to_ucs2 (ucs2_t *pwc, const unsigned char *s)
90 {
91   unsigned char c = *s;
92   if (c < 0x80) {
93     *pwc = (ucs2_t) c;
94     return 1;
95   }
96   else {
97     unsigned short wc = mac_greek_2uni[c-0x80];
98     if (wc != 0xfffd) {
99       *pwc = (ucs2_t) wc;
100       return 1;
101     }
102   }
103   return 0;
104 }
105
106 static size_t mac_greek_pull ( void *cd, char **inbuf, size_t *inbytesleft,
107                          char **outbuf, size_t *outbytesleft)
108 {
109         return (size_t) mb_generic_pull( char_mac_greek_to_ucs2, cd, inbuf, inbytesleft, outbuf, outbytesleft);
110 }