]> arthur.barton.de Git - netatalk.git/blob - libatalk/unicode/charsets/mac_greek.c
Merge master
[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 <arpa/inet.h>
34
35 #include <atalk/unicode.h>
36
37 #include "mac_greek.h"
38 #include "generic_mb.h"
39
40 static size_t   mac_greek_pull(void *,char **, size_t *, char **, size_t *);
41 static size_t   mac_greek_push(void *,char **, size_t *, char **, size_t *);
42
43 struct charset_functions charset_mac_greek =
44 {
45         "MAC_GREEK",
46         6,
47         mac_greek_pull,
48         mac_greek_push,
49         CHARSET_CLIENT | CHARSET_MULTIBYTE,
50         NULL,
51         NULL, NULL
52 };
53
54 /* ------------------------ */
55 static int
56 char_ucs2_to_mac_greek ( unsigned char *r, ucs2_t wc)
57 {
58   unsigned char c = 0;
59   if (wc < 0x0080) {
60     *r = wc;
61     return 1;
62   }
63   else if (wc >= 0x00a0 && wc < 0x0100)
64     c = mac_greek_page00[wc-0x00a0];
65   else if (wc == 0x0153)
66     c = 0xcf;
67   else if (wc >= 0x0380 && wc < 0x03d0)
68     c = mac_greek_page03[wc-0x0380];
69   else if (wc >= 0x2010 && wc < 0x2038)
70     c = mac_greek_page20[wc-0x2010];
71   else if (wc == 0x2122)
72     c = 0x93;
73   else if (wc >= 0x2248 && wc < 0x2268)
74     c = mac_greek_page22[wc-0x2248];
75   if (c != 0) {
76     *r = c;
77     return 1;
78   }
79  return 0;
80  }
81
82 static size_t mac_greek_push( void *cd, char **inbuf, size_t *inbytesleft,
83                          char **outbuf, size_t *outbytesleft)
84 {
85         /* No special handling required */
86         return (size_t) mb_generic_push( char_ucs2_to_mac_greek, cd, inbuf, inbytesleft, outbuf, outbytesleft);
87 }
88
89 /* ------------------------ */
90 static int
91 char_mac_greek_to_ucs2 (ucs2_t *pwc, const unsigned char *s)
92 {
93   unsigned char c = *s;
94   if (c < 0x80) {
95     *pwc = (ucs2_t) c;
96     return 1;
97   }
98   else {
99     unsigned short wc = mac_greek_2uni[c-0x80];
100     if (wc != 0xfffd) {
101       *pwc = (ucs2_t) wc;
102       return 1;
103     }
104   }
105   return 0;
106 }
107
108 static size_t mac_greek_pull ( void *cd, char **inbuf, size_t *inbytesleft,
109                          char **outbuf, size_t *outbytesleft)
110 {
111         return (size_t) mb_generic_pull( char_mac_greek_to_ucs2, cd, inbuf, inbytesleft, outbuf, outbytesleft);
112 }