• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/netatalk-2.2.5/libatalk/unicode/charsets/
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
39static size_t   mac_greek_pull(void *,char **, size_t *, char **, size_t *);
40static size_t   mac_greek_push(void *,char **, size_t *, char **, size_t *);
41
42struct 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,
50	NULL, NULL
51};
52
53/* ------------------------ */
54static int
55char_ucs2_to_mac_greek ( unsigned char *r, ucs2_t wc)
56{
57  unsigned char c = 0;
58  if (wc < 0x0080) {
59    *r = wc;
60    return 1;
61  }
62  else if (wc >= 0x00a0 && wc < 0x0100)
63    c = mac_greek_page00[wc-0x00a0];
64  else if (wc == 0x0153)
65    c = 0xcf;
66  else if (wc >= 0x0380 && wc < 0x03d0)
67    c = mac_greek_page03[wc-0x0380];
68  else if (wc >= 0x2010 && wc < 0x2038)
69    c = mac_greek_page20[wc-0x2010];
70  else if (wc == 0x2122)
71    c = 0x93;
72  else if (wc >= 0x2248 && wc < 0x2268)
73    c = mac_greek_page22[wc-0x2248];
74  if (c != 0) {
75    *r = c;
76    return 1;
77  }
78 return 0;
79 }
80
81static size_t mac_greek_push( void *cd, char **inbuf, size_t *inbytesleft,
82                         char **outbuf, size_t *outbytesleft)
83{
84	/* No special handling required */
85	return (size_t) mb_generic_push( char_ucs2_to_mac_greek, cd, inbuf, inbytesleft, outbuf, outbytesleft);
86}
87
88/* ------------------------ */
89static int
90char_mac_greek_to_ucs2 (ucs2_t *pwc, const unsigned char *s)
91{
92  unsigned char c = *s;
93  if (c < 0x80) {
94    *pwc = (ucs2_t) c;
95    return 1;
96  }
97  else {
98    unsigned short wc = mac_greek_2uni[c-0x80];
99    if (wc != 0xfffd) {
100      *pwc = (ucs2_t) wc;
101      return 1;
102    }
103  }
104  return 0;
105}
106
107static size_t mac_greek_pull ( void *cd, char **inbuf, size_t *inbytesleft,
108                         char **outbuf, size_t *outbytesleft)
109{
110	return (size_t) mb_generic_pull( char_mac_greek_to_ucs2, cd, inbuf, inbytesleft, outbuf, outbytesleft);
111}
112