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>
31 #include "../../libatalk/unicode/byteorder.h"
33 static size_t iso8859_adapted_pull(void *,char **, size_t *, char **, size_t *);
34 static size_t iso8859_adapted_push(void *,char **, size_t *, char **, size_t *);
36 struct charset_functions charset_iso8859_adapted =
42 CHARSET_MULTIBYTE | CHARSET_PRECOMPOSED,
48 /* ------------------------
49 * from unicode to iso8859_adapted code page
52 static size_t iso8859_adapted_push( void *cd _U_, char **inbuf, size_t *inbytesleft,
53 char **outbuf, size_t *outbytesleft)
57 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
58 ucs2_t inptr = SVAL((*inbuf),0);
59 if ( inptr == 0x2122) {
60 SSVAL((*outbuf),0,0xAA);
62 else if ( inptr == 0x0192) {
63 SSVAL((*outbuf),0,0xC5);
65 else if ( inptr == 0x2014) {
66 SSVAL((*outbuf),0,0xD1);
68 else if ( inptr == 0x201C) {
69 SSVAL((*outbuf),0,0xD2);
71 else if ( inptr == 0x201D) {
72 SSVAL((*outbuf),0,0xD3);
74 else if ( inptr == 0x2018) {
75 SSVAL((*outbuf),0,0xD4);
77 else if ( inptr == 0x2019) {
78 SSVAL((*outbuf),0,0xD5);
80 else if ( inptr == 0x25CA) {
81 SSVAL((*outbuf),0,0xD7);
83 else if ( inptr > 0x0100) {
88 SSVAL((*outbuf), 0, inptr);
97 if (*inbytesleft > 0) {
105 /* ------------------------ */
106 static size_t iso8859_adapted_pull ( void *cd _U_, char **inbuf, size_t *inbytesleft,
107 char **outbuf, size_t *outbytesleft)
109 unsigned char *inptr;
112 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
113 inptr = (unsigned char *) *inbuf;
115 if ( *inptr == 0xAA) {
116 SSVAL((*outbuf),0,0x2122);
118 else if ( *inptr == 0xC5) {
119 SSVAL((*outbuf),0,0x0192);
121 else if ( *inptr == 0xD1) {
122 SSVAL((*outbuf),0,0x2014);
124 else if ( *inptr == 0xD2) {
125 SSVAL((*outbuf),0,0x201C);
127 else if ( *inptr == 0xD3) {
128 SSVAL((*outbuf),0,0x201D);
130 else if ( *inptr == 0xD4) {
131 SSVAL((*outbuf),0,0x2018);
133 else if ( *inptr == 0xD5) {
134 SSVAL((*outbuf),0,0x2019);
136 else if ( *inptr == 0xD7) {
137 SSVAL((*outbuf),0,0x25CA);
140 SSVAL((*outbuf),0,(*inptr));
149 if (*inbytesleft > 0) {