2 iso-8859-1.adapted conversion routines
3 Copyright (C) Bjoern Fernhomberg 2002,2003
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #endif /* HAVE_CONFIG_H */
26 #include <arpa/inet.h>
28 #include <atalk/unicode.h>
29 #include <atalk/logger.h>
30 #include <atalk/byteorder.h>
32 static size_t iso8859_adapted_pull(void *,char **, size_t *, char **, size_t *);
33 static size_t iso8859_adapted_push(void *,char **, size_t *, char **, size_t *);
35 struct charset_functions charset_iso8859_adapted =
41 CHARSET_MULTIBYTE | CHARSET_PRECOMPOSED,
47 /* ------------------------
48 * from unicode to iso8859_adapted code page
51 static size_t iso8859_adapted_push( void *cd _U_, char **inbuf, size_t *inbytesleft,
52 char **outbuf, size_t *outbytesleft)
56 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
57 ucs2_t inptr = SVAL((*inbuf),0);
58 if ( inptr == 0x2122) {
59 SSVAL((*outbuf),0,0xAA);
61 else if ( inptr == 0x0192) {
62 SSVAL((*outbuf),0,0xC5);
64 else if ( inptr == 0x2014) {
65 SSVAL((*outbuf),0,0xD1);
67 else if ( inptr == 0x201C) {
68 SSVAL((*outbuf),0,0xD2);
70 else if ( inptr == 0x201D) {
71 SSVAL((*outbuf),0,0xD3);
73 else if ( inptr == 0x2018) {
74 SSVAL((*outbuf),0,0xD4);
76 else if ( inptr == 0x2019) {
77 SSVAL((*outbuf),0,0xD5);
79 else if ( inptr == 0x25CA) {
80 SSVAL((*outbuf),0,0xD7);
82 else if ( inptr > 0x0100) {
87 SSVAL((*outbuf), 0, inptr);
96 if (*inbytesleft > 0) {
104 /* ------------------------ */
105 static size_t iso8859_adapted_pull ( void *cd _U_, char **inbuf, size_t *inbytesleft,
106 char **outbuf, size_t *outbytesleft)
108 unsigned char *inptr;
111 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
112 inptr = (unsigned char *) *inbuf;
114 if ( *inptr == 0xAA) {
115 SSVAL((*outbuf),0,0x2122);
117 else if ( *inptr == 0xC5) {
118 SSVAL((*outbuf),0,0x0192);
120 else if ( *inptr == 0xD1) {
121 SSVAL((*outbuf),0,0x2014);
123 else if ( *inptr == 0xD2) {
124 SSVAL((*outbuf),0,0x201C);
126 else if ( *inptr == 0xD3) {
127 SSVAL((*outbuf),0,0x201D);
129 else if ( *inptr == 0xD4) {
130 SSVAL((*outbuf),0,0x2018);
132 else if ( *inptr == 0xD5) {
133 SSVAL((*outbuf),0,0x2019);
135 else if ( *inptr == 0xD7) {
136 SSVAL((*outbuf),0,0x25CA);
139 SSVAL((*outbuf),0,(*inptr));
148 if (*inbytesleft > 0) {