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 */
27 #include <netatalk/endian.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
46 /* ------------------------
47 * from unicode to iso8859_adapted code page
50 static size_t iso8859_adapted_push( void *cd, char **inbuf, size_t *inbytesleft,
51 char **outbuf, size_t *outbytesleft)
55 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
56 ucs2_t inptr = SVAL((*inbuf),0);
57 if ( inptr == 0x2122) {
58 SSVAL((*outbuf),0,0xAA);
60 else if ( inptr == 0x0192) {
61 SSVAL((*outbuf),0,0xC5);
63 else if ( inptr == 0x2014) {
64 SSVAL((*outbuf),0,0xD1);
66 else if ( inptr == 0x201C) {
67 SSVAL((*outbuf),0,0xD2);
69 else if ( inptr == 0x201D) {
70 SSVAL((*outbuf),0,0xD3);
72 else if ( inptr == 0x2018) {
73 SSVAL((*outbuf),0,0xD4);
75 else if ( inptr == 0x2019) {
76 SSVAL((*outbuf),0,0xD5);
78 else if ( inptr == 0x25CA) {
79 SSVAL((*outbuf),0,0xD7);
81 else if ( inptr > 0x0100) {
86 SSVAL((*outbuf), 0, inptr);
95 if (*inbytesleft > 0) {
103 /* ------------------------ */
104 static size_t iso8859_adapted_pull ( void *cd, char **inbuf, size_t *inbytesleft,
105 char **outbuf, size_t *outbytesleft)
107 unsigned char *inptr;
110 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
111 inptr = (unsigned char *) *inbuf;
113 if ( *inptr == 0xAA) {
114 SSVAL((*outbuf),0,0x2122);
116 else if ( *inptr == 0xC5) {
117 SSVAL((*outbuf),0,0x0192);
119 else if ( *inptr == 0xD1) {
120 SSVAL((*outbuf),0,0x2014);
122 else if ( *inptr == 0xD2) {
123 SSVAL((*outbuf),0,0x201C);
125 else if ( *inptr == 0xD3) {
126 SSVAL((*outbuf),0,0x201D);
128 else if ( *inptr == 0xD4) {
129 SSVAL((*outbuf),0,0x2018);
131 else if ( *inptr == 0xD5) {
132 SSVAL((*outbuf),0,0x2019);
134 else if ( *inptr == 0xD7) {
135 SSVAL((*outbuf),0,0x25CA);
138 SSVAL((*outbuf),0,(*inptr));
147 if (*inbytesleft > 0) {