]> git.sur5r.net Git - openldap/blob - libraries/libldap/charset.c
Remove LDAP_PORT dependencies so that ldap.conf defaults take over.
[openldap] / libraries / libldap / charset.c
1 /*
2  *  Copyright (c) 1995 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  charset.c
6  */
7
8 #include "portable.h"
9
10 #ifdef STR_TRANSLATION
11
12 #ifndef lint 
13 static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n";
14 #endif
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include <ac/socket.h>
20 #include <ac/string.h>
21 #include <ac/time.h>
22
23 #ifdef HAVE_SYS_PARAM_H
24 #include <sys/param.h>
25 #endif
26
27 #include "ldap-int.h"
28
29
30 void
31 ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc,
32         BERTranslateProc decode_proc )
33 {
34         ld->ld_lber_encode_translate_proc = encode_proc;
35         ld->ld_lber_decode_translate_proc = decode_proc;
36 }
37
38
39 void
40 ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
41 {
42         char    *optionsp;
43
44         optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions :
45             &entry->lm_ber->ber_options;
46                 
47         if ( enable ) {
48                 *optionsp |= LBER_TRANSLATE_STRINGS;
49         } else {
50                 *optionsp &= ~LBER_TRANSLATE_STRINGS;
51         }
52 }
53
54
55 int
56 ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
57     int free_input )
58 {
59         if ( ld->ld_lber_decode_translate_proc == NULL ) {
60                 return( LDAP_SUCCESS );
61         }
62             
63         return( (*ld->ld_lber_decode_translate_proc)( bufp, lenp, free_input ));
64 }
65
66
67 int
68 ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
69     int free_input )
70 {
71         if ( ld->ld_lber_encode_translate_proc == NULL ) {
72                 return( LDAP_SUCCESS );
73         }
74             
75         return( (*ld->ld_lber_encode_translate_proc)( bufp, lenp, free_input ));
76 }
77
78
79 /*
80  ** Character translation routine notes:
81  *
82  * On entry:  bufp points to a "string" to be converted (not necessarily
83  *  zero-terminated) and buflenp points to the length of the buffer.
84  *
85  * On exit:  bufp should point to a malloc'd result.  If free_input is
86  *  non-zero then the original bufp will be freed.  *buflenp should be
87  *  set to the new length.  Zero bytes in the input buffer must be left
88  *  as zero bytes.
89  *
90  * Return values: any ldap error code (LDAP_SUCCESS if all goes well).
91  */
92
93
94 #ifdef LDAP_CHARSET_8859
95
96 #if LDAP_CHARSET_8859 == 88591
97 #define ISO_8859 1
98 #elif LDAP_CHARSET_8859 == 88592
99 #define ISO_8859 2
100 #elif LDAP_CHARSET_8859 == 88593
101 #define ISO_8859 3
102 #elif LDAP_CHARSET_8859 == 88594
103 #define ISO_8859 4
104 #elif LDAP_CHARSET_8859 == 88595
105 #define ISO_8859 5
106 #elif LDAP_CHARSET_8859 == 88596
107 #define ISO_8859 6
108 #elif LDAP_CHARSET_8859 == 88597
109 #define ISO_8859 7
110 #elif LDAP_CHARSET_8859 == 88598
111 #define ISO_8859 8
112 #elif LDAP_CHARSET_8859 == 88599
113 #define ISO_8859 9
114 #elif LDAP_CHARSET_8859 == 885910
115 #define ISO_8859 10
116 #else
117 #define ISO_8859 0
118 #endif
119
120 /*
121  * the following ISO_8859 to/afrom T.61 character set translation code is
122  * based on the code found in Enrique Silvestre Mora's iso-t61.c, found
123  * as part of this package:
124  *   ftp://pereiii.uji.es/pub/uji-ftp/unix/ldap/iso-t61.translation.tar.Z
125  * Enrique is now (10/95) at this address: enrique.silvestre@uv.es
126  *
127  * changes made by mcs@umich.edu 12 October 1995:
128  *   Change calling conventions of iso8859_t61() and t61_iso8859() to
129  *      match libldap conventions; rename to ldap_8859_to_t61() and
130  *      ldap_t61_to_8859().
131  *   Change conversion routines to deal with non-zero terminated strings.
132  *   ANSI-ize functions and include prototypes.
133  */
134
135 /* iso-t61.c - ISO-T61 translation routines (version: 0.2.1, July-1994) */
136 /*
137  * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain.
138  * All rights reserved.
139  *
140  * Redistribution and use in source and binary forms are permitted
141  * provided that this notice is preserved and that due credit is given
142  * to the Universitat Jaume I. The name of the University
143  * may not be used to endorse or promote products derived from this
144  * software without specific prior written permission. This software
145  * is provided ``as is'' without express or implied warranty.
146 */
147
148
149 #include <stdio.h>
150 #include <stdlib.h>
151 #include <ac/string.h>
152
153 /* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */
154 /* #define  ISO_8859      1 */
155
156 #ifndef ISO_8859
157 #  define ISO_8859     0
158 #endif
159
160 typedef unsigned char  Byte;
161 typedef struct { Byte  a, b; } Couple;
162
163 static Byte *c_to_hh LDAP_P(( Byte *o, Byte c ));
164 static Byte *c_to_cc LDAP_P(( Byte *o, Couple *cc, Byte c ));
165 static int hh_to_c LDAP_P(( Byte *h ));
166 static Byte *cc_to_t61 LDAP_P(( Byte *o, Byte *s ));
167
168 /*
169    Character choosed as base in diacritics alone: NO-BREAK SPACE.
170    (The standard say it must be a blank space, 0x20.)
171 */
172 #define  ALONE  0xA0
173
174 static Couple diacritic[16] = {
175 #if (ISO_8859 == 1) || (ISO_8859 == 9)
176         {0,0},       {'`',0},     {0xb4,0},    {'^',0},
177         {'~',0},     {0xaf,0},    {'(',ALONE}, {'.',ALONE},
178         {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
179         {0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE},
180 #elif (ISO_8859 == 2)
181         {0,0},       {'`',0},     {0xb4,0},    {'^',0},
182         {'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
183         {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
184         {0,0},       {0xbd,0},    {0xb2,0},    {0xb7,0}
185 #elif (ISO_8859 == 3)
186         {0,0},       {'`',0},     {0xb4,0},    {'^',0},
187         {'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
188         {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
189         {0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE}
190 #elif (ISO_8859 == 4)
191         {0,0},       {'`',0},     {0xb4,0},    {'^',0},
192         {'~',0},     {0xaf,0},    {'(',ALONE}, {0xff,0},
193         {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
194         {0,0},       {'"',ALONE}, {0xb2,0},    {0xb7,0}
195 #else
196         {0,0},       {'`',0},     {'\'',ALONE}, {'^',0},
197         {'~',0},     {'-',ALONE}, {'(',ALONE},  {'.',ALONE},
198         {':',ALONE}, {0,0},       {'0',ALONE},  {',',ALONE},
199         {0,0},       {'"',ALONE}, {';',ALONE},  {'<',ALONE}
200 #endif
201 };
202
203 /*
204    --- T.61 (T.51) letters with diacritics: conversion to ISO 8859-n -----
205        A,   C,   D,   E,   G,   H,   I,   J,   K,
206        L,   N,   O,   R,   S,   T,   U,   W,   Y,   Z.
207    -----------------------------------------------------------------------
208 */
209 static int letter_w_diacritic[16][38] = {
210 #if (ISO_8859 == 1)
211         0,   0,   0,   0,   0,   0,   0,   0,   0,
212         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
213         0,   0,   0,   0,   0,   0,   0,   0,   0,
214         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
215         0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
216         0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
217         0xe0,0,   0,   0xe8,0,   0,   0xec,0,   0,
218         0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
219         0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
220         -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   0xdd,-1,
221         0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
222         -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   0xfd,-1,
223         0xc2,-1,  0,   0xca,-1,  -1,  0xce,-1,  0,
224         0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
225         0xe2,-1,  0,   0xea,-1,  -1,  0xee,-1,  0,
226         0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
227         0xc3,0,   0,   0,   0,   0,   -1,  0,   0,
228         0,   0xd1,0xd5,0,   0,   0,   -1,  0,   0,   0,
229         0xe3,0,   0,   0,   0,   0,   -1,  0,   0,
230         0,   0xf1,0xf5,0,   0,   0,   -1,  0,   0,   0,
231         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
232         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
233         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
234         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
235         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
236         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
237         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
238         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
239         0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
240         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
241         0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
242         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
243         0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
244         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
245         0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
246         0,   0,   0xf6,0,   0,   0,   0xfc,0,   0xff,0,
247         0,   0,   0,   0,   0,   0,   0,   0,   0,
248         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
249         0,   0,   0,   0,   0,   0,   0,   0,   0,
250         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
251         0xc5,0,   0,   0,   0,   0,   0,   0,   0,
252         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
253         0xe5,0,   0,   0,   0,   0,   0,   0,   0,
254         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
255         0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
256         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
257         0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
258         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
259         0,   0,   0,   0,   0,   0,   0,   0,   0,
260         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
261         0,   0,   0,   0,   0,   0,   0,   0,   0,
262         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
263         0,   0,   0,   0,   0,   0,   0,   0,   0,
264         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
265         0,   0,   0,   0,   0,   0,   0,   0,   0,
266         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
267         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
268         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
269         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
270         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
271         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
272         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
273         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
274         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
275 #elif (ISO_8859 == 2)
276         0,   0,   0,   0,   0,   0,   0,   0,   0,
277         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
278         0,   0,   0,   0,   0,   0,   0,   0,   0,
279         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
280         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
281         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
282         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
283         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
284         0xc1,0xc6,0,   0xc9,0,   0,   0xcd,0,   0,
285         0xc5,0xd1,0xd3,0xc0,0xa6,0,   0xda,0,   0xdd,0xac,
286         0xe1,0xe6,0,   0xe9,0,   0,   0xed,0,   0,
287         0xe5,0xf1,0xf3,0xe0,0xb6,0,   0xfa,0,   0xfd,0xbc,
288         0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
289         0,   0,   0xd4,0,   -1,  0,   -1,  -1,  -1,  0,
290         0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
291         0,   0,   0xf4,0,   -1,  0,   -1,  -1,  -1,  0,
292         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
293         0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
294         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
295         0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
296         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
297         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
298         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
299         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
300         0xc3,0,   0,   0,   -1,  0,   0,   0,   0,
301         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
302         0xe3,0,   0,   0,   -1,  0,   0,   0,   0,
303         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
304         0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
305         0,   0,   0,   0,   0,   0,   0,   0,   0,   0xaf,
306         0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
307         0,   0,   0,   0,   0,   0,   0,   0,   0,   0xbf,
308         0xc4,0,   0,   0xcb,0,   0,   -1,  0,   0,
309         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
310         0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
311         0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
312         0,   0,   0,   0,   0,   0,   0,   0,   0,
313         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
314         0,   0,   0,   0,   0,   0,   0,   0,   0,
315         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
316         -1,  0,   0,   0,   0,   0,   0,   0,   0,
317         0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
318         -1,  0,   0,   0,   0,   0,   0,   0,   0,
319         0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
320         0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
321         -1,  -1,  0,   -1,  0xaa,0xde,0,   0,   0,   0,
322         0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
323         -1,  -1,  0,   -1,  0xba,0xfe,0,   0,   0,   0,
324         0,   0,   0,   0,   0,   0,   0,   0,   0,
325         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
326         0,   0,   0,   0,   0,   0,   0,   0,   0,
327         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
328         0,   0,   0,   0,   0,   0,   0,   0,   0,
329         0,   0,   0xd5,0,   0,   0,   0xdb,0,   0,   0,
330         0,   0,   0,   0,   0,   0,   0,   0,   0,
331         0,   0,   0xf5,0,   0,   0,   0xfb,0,   0,   0,
332         0xa1,0,   0,   0xca,0,   0,   -1,  0,   0,
333         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
334         0xb1,0,   0,   0xea,0,   0,   -1,  0,   0,
335         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
336         0,   0xc8,0xcf,0xcc,0,   0,   0,   0,   0,
337         0xa5,0xd2,0,   0xd8,0xa9,0xab,0,   0,   0,   0xae,
338         0,   0xe8,0xef,0xec,0,   0,   0,   0,   0,
339         0xb5,0xf2,0,   0xf8,0xb9,0xbb,0,   0,   0,   0xbe
340 #elif (ISO_8859 == 3)
341         0,   0,   0,   0,   0,   0,   0,   0,   0,
342         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
343         0,   0,   0,   0,   0,   0,   0,   0,   0,
344         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
345         0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
346         0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
347         0xe0,0,   0,   0xe8,0,   0,   0xec,0,   0,
348         0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
349         0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
350         -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   -1,  -1,
351         0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
352         -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   -1,  -1,
353         0xc2,0xc6,0,   0xca,0xd8,0xa6,0xce,0xac,0,
354         0,   0,   0xd4,0,   0xde,0,   0xdb,-1,  -1,  0,
355         0xe2,0xe6,0,   0xea,0xf8,0xb6,0xee,0xbc,0,
356         0,   0,   0xf4,0,   0xfe,0,   0xfb,-1,  -1,  0,
357         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
358         0,   0xd1,-1,  0,   0,   0,   -1,  0,   0,   0,
359         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
360         0,   0xf1,-1,  0,   0,   0,   -1,  0,   0,   0,
361         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
362         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
363         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
364         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
365         -1,  0,   0,   0,   0xab,0,   0,   0,   0,
366         0,   0,   0,   0,   0,   0,   0xdd,0,   0,   0,
367         -1,  0,   0,   0,   0xbb,0,   0,   0,   0,
368         0,   0,   0,   0,   0,   0,   0xfd,0,   0,   0,
369         0,   0xc5,0,   -1,  0xd5,0,   0xa9,0,   0,
370         0,   0,   0,   0,   0,   0,   0,   0,   0,   0xaf,
371         0,   0xe5,0,   -1,  0xf5,0,   0,   0,   0,
372         0,   0,   0,   0,   0,   0,   0,   0,   0,   0xbf,
373         0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
374         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
375         0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
376         0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
377         0,   0,   0,   0,   0,   0,   0,   0,   0,
378         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
379         0,   0,   0,   0,   0,   0,   0,   0,   0,
380         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
381         -1,  0,   0,   0,   0,   0,   0,   0,   0,
382         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
383         -1,  0,   0,   0,   0,   0,   0,   0,   0,
384         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
385         0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
386         -1,  -1,  0,   -1,  0xaa,-1,  0,   0,   0,   0,
387         0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
388         -1,  -1,  0,   -1,  0xba,-1,  0,   0,   0,   0,
389         0,   0,   0,   0,   0,   0,   0,   0,   0,
390         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
391         0,   0,   0,   0,   0,   0,   0,   0,   0,
392         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
393         0,   0,   0,   0,   0,   0,   0,   0,   0,
394         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
395         0,   0,   0,   0,   0,   0,   0,   0,   0,
396         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
397         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
398         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
399         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
400         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
401         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
402         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
403         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
404         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
405 #elif (ISO_8859 == 4)
406         0,   0,   0,   0,   0,   0,   0,   0,   0,
407         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
408         0,   0,   0,   0,   0,   0,   0,   0,   0,
409         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
410         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
411         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
412         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
413         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
414         0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
415         -1,  -1,  -1,  -1,  -1,  0,   0xda,0,   -1,  -1,
416         0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
417         -1,  -1,  -1,  -1,  -1,  0,   0xfa,0,   -1,  -1,
418         0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
419         0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
420         0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
421         0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
422         0xc3,0,   0,   0,   0,   0,   0xa5,0,   0,
423         0,   -1,  0xd5,0,   0,   0,   0xdd,0,   0,   0,
424         0xe3,0,   0,   0,   0,   0,   0xb5,0,   0,
425         0,   -1,  0xf5,0,   0,   0,   0xfd,0,   0,   0,
426         0xc0,0,   0,   0xaa,0,   0,   0xcf,0,   0,
427         0,   0,   0xd2,0,   0,   0,   0xde,0,   0,   0,
428         0xe0,0,   0,   0xba,0,   0,   0xef,0,   0,
429         0,   0,   0xf2,0,   0,   0,   0xfe,0,   0,   0,
430         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
431         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
432         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
433         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
434         0,   -1,  0,   0xcc,-1,  0,   -1,  0,   0,
435         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
436         0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
437         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
438         0xc4,0,   0,   0xcb,0,   0,   -1,  0,   0,
439         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
440         0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
441         0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
442         0,   0,   0,   0,   0,   0,   0,   0,   0,
443         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
444         0,   0,   0,   0,   0,   0,   0,   0,   0,
445         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
446         0xc5,0,   0,   0,   0,   0,   0,   0,   0,
447         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
448         0xe5,0,   0,   0,   0,   0,   0,   0,   0,
449         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
450         0,   -1,  0,   0,   0xab,0,   0,   0,   0xd3,
451         0xa6,0xd1,0,   0xa3,-1,  -1,  0,   0,   0,   0,
452         0,   -1,  0,   0,   0xbb,0,   0,   0,   0xf3,
453         0xb6,0xf1,0,   0xb3,-1,  -1,  0,   0,   0,   0,
454         0,   0,   0,   0,   0,   0,   0,   0,   0,
455         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
456         0,   0,   0,   0,   0,   0,   0,   0,   0,
457         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
458         0,   0,   0,   0,   0,   0,   0,   0,   0,
459         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
460         0,   0,   0,   0,   0,   0,   0,   0,   0,
461         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
462         0xa1,0,   0,   0xca,0,   0,   0xc7,0,   0,
463         0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
464         0xb1,0,   0,   0xea,0,   0,   0xe7,0,   0,
465         0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
466         0,   0xc8,-1,  -1,  0,   0,   0,   0,   0,
467         -1,  -1,  0,   -1,  0xa9,-1,  0,   0,   0,   0xae,
468         0,   0xe8,-1,  -1,  0,   0,   0,   0,   0,
469         -1,  -1,  0,   -1,  0xb9,-1,  0,   0,   0,   0xbe
470 #elif (ISO_8859 == 9)
471         0,   0,   0,   0,   0,   0,   0,   0,   0,
472         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
473         0,   0,   0,   0,   0,   0,   0,   0,   0,
474         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
475         0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
476         0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
477         0xe0,0,   0,   0xe8,0,   0,   -1,  0,   0,
478         0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
479         0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
480         -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   -1,  -1,
481         0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
482         -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   -1,  -1,
483         0xc2,-1,  0,   0xca,-1,  -1,  0xce,-1,  0,
484         0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
485         0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
486         0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
487         0xc3,0,   0,   0,   0,   0,   -1,  0,   0,
488         0,   0xd1,0xd5,0,   0,   0,   -1,  0,   0,   0,
489         0xe3,0,   0,   0,   0,   0,   -1,  0,   0,
490         0,   0xf1,0xf5,0,   0,   0,   -1,  0,   0,   0,
491         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
492         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
493         -1,  0,   0,   -1,  0,   0,   0xef,0,   0,
494         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
495         -1,  0,   0,   0,   0xd0,0,   0,   0,   0,
496         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
497         -1,  0,   0,   0,   0xf0,0,   0,   0,   0,
498         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
499         0,   -1,  0,   -1,  -1,  0,   0xdd,0,   0,
500         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
501         0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
502         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
503         0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
504         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
505         0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
506         0,   0,   0xf6,0,   0,   0,   0xfc,0,   0xff,0,
507         0,   0,   0,   0,   0,   0,   0,   0,   0,
508         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
509         0,   0,   0,   0,   0,   0,   0,   0,   0,
510         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
511         0xc5,0,   0,   0,   0,   0,   0,   0,   0,
512         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
513         0xe5,0,   0,   0,   0,   0,   0,   0,   0,
514         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
515         0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
516         -1,  -1,  0,   -1,  0xde,-1,  0,   0,   0,   0,
517         0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
518         -1,  -1,  0,   -1,  0xfe,-1,  0,   0,   0,   0,
519         0,   0,   0,   0,   0,   0,   0,   0,   0,
520         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
521         0,   0,   0,   0,   0,   0,   0,   0,   0,
522         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
523         0,   0,   0,   0,   0,   0,   0,   0,   0,
524         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
525         0,   0,   0,   0,   0,   0,   0,   0,   0,
526         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
527         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
528         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
529         -1,  0,   0,   0xea,0,   0,   -1,  0,   0,
530         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
531         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
532         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
533         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
534         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
535 #elif (ISO_8859 == 10)
536         0,   0,   0,   0,   0,   0,   0,   0,   0,
537         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
538         0,   0,   0,   0,   0,   0,   0,   0,   0,
539         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
540         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
541         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
542         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
543         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
544         0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
545         -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   0xdd,-1,
546         0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
547         -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   0xfd,-1,
548         0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
549         0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
550         0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
551         0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
552         0xc3,0,   0,   0,   0,   0,   0xa5,0,   0,
553         0,   -1,  0xd5,0,   0,   0,   0xd7,0,   0,   0,
554         0xe3,0,   0,   0,   0,   0,   0xb5,0,   0,
555         0,   -1,  0xf5,0,   0,   0,   0xf7,0,   0,   0,
556         0xc0,0,   0,   0xa2,0,   0,   0xa4,0,   0,
557         0,   0,   0xd2,0,   0,   0,   0xae,0,   0,   0,
558         0xe0,0,   0,   0xb2,0,   0,   0xb4,0,   0,
559         0,   0,   0xf2,0,   0,   0,   0xbe,0,   0,   0,
560         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
561         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
562         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
563         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
564         0,   -1,  0,   0xcc,-1,  0,   -1,  0,   0,
565         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
566         0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
567         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
568         0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
569         0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
570         0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
571         0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
572         0,   0,   0,   0,   0,   0,   0,   0,   0,
573         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
574         0,   0,   0,   0,   0,   0,   0,   0,   0,
575         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
576         0xc5,0,   0,   0,   0,   0,   0,   0,   0,
577         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
578         0xe5,0,   0,   0,   0,   0,   0,   0,   0,
579         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
580         0,   -1,  0,   0,   0xa3,0,   0,   0,   0xa6,
581         0xa8,0xd1,0,   -1,  -1,  -1,  0,   0,   0,   0,
582         0,   -1,  0,   0,   0xb3,0,   0,   0,   0xb6,
583         0xb8,0xf1,0,   -1,  -1,  -1,  0,   0,   0,   0,
584         0,   0,   0,   0,   0,   0,   0,   0,   0,
585         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
586         0,   0,   0,   0,   0,   0,   0,   0,   0,
587         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
588         0,   0,   0,   0,   0,   0,   0,   0,   0,
589         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
590         0,   0,   0,   0,   0,   0,   0,   0,   0,
591         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
592         0xa1,0,   0,   0xca,0,   0,   0xc7,0,   0,
593         0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
594         0xb1,0,   0,   0xea,0,   0,   0xe7,0,   0,
595         0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
596         0,   0xc8,-1,  -1,  0,   0,   0,   0,   0,
597         -1,  -1,  0,   -1,  0xaa,-1,  0,   0,   0,   0xac,
598         0,   0xe8,-1,  -1,  0,   0,   0,   0,   0,
599         -1,  -1,  0,   -1,  0xba,-1,  0,   0,   0,   0xbc
600 #else
601         0,   0,   0,   0,   0,   0,   0,   0,   0,
602         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
603         0,   0,   0,   0,   0,   0,   0,   0,   0,
604         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
605         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
606         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
607         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
608         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
609         -1,  -1,  0,   -1,  0,   0,   -1,  0,   0,
610         -1,  -1,  -1,  -1,  -1,  0,   -1,  0,   -1,  -1,
611         -1,  -1,  0,   -1,  0,   0,   -1,  0,   0,
612         -1,  -1,  -1,  -1,  -1,  0,   -1,  0,   -1,  -1,
613         -1,  -1,  0,   -1,  -1,  -1,  -1,  -1,  0,
614         0,   0,   -1,  0,   -1,  0,   -1,  -1,  -1,  0,
615         -1,  -1,  0,   -1,  -1,  -1,  -1,  -1,  0,
616         0,   0,   -1,  0,   -1,  0,   -1,  -1,  -1,  0,
617         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
618         0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
619         -1,  0,   0,   0,   0,   0,   -1,  0,   0,
620         0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
621         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
622         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
623         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
624         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
625         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
626         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
627         -1,  0,   0,   0,   -1,  0,   0,   0,   0,
628         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
629         0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
630         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
631         0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
632         0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
633         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
634         0,   0,   -1,  0,   0,   0,   -1,  0,   -1,  0,
635         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
636         0,   0,   -1,  0,   0,   0,   -1,  0,   -1,  0,
637         0,   0,   0,   0,   0,   0,   0,   0,   0,
638         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
639         0,   0,   0,   0,   0,   0,   0,   0,   0,
640         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
641         -1,  0,   0,   0,   0,   0,   0,   0,   0,
642         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
643         -1,  0,   0,   0,   0,   0,   0,   0,   0,
644         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
645         0,   -1,  0,   0,   -1,  0,   0,   0,   -1,
646         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
647         0,   -1,  0,   0,   -1,  0,   0,   0,   -1,
648         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
649         0,   0,   0,   0,   0,   0,   0,   0,   0,
650         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
651         0,   0,   0,   0,   0,   0,   0,   0,   0,
652         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
653         0,   0,   0,   0,   0,   0,   0,   0,   0,
654         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
655         0,   0,   0,   0,   0,   0,   0,   0,   0,
656         0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
657         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
658         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
659         -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
660         0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
661         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
662         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
663         0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
664         -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
665 #endif
666 };
667
668 /*
669 --- T.61 characters [0xA0 .. 0xBF] -----------------
670 */
671 static Couple trans_t61a_iso8859[32] = {
672 #if (ISO_8859 == 1) || (ISO_8859 == 9)
673         {'N','S'}, {0xa1,0},  {0xa2,0},  {0xa3,0},
674         {'D','O'}, {0xa5,0},  {'C','u'}, {0xa7,0},
675         {0xa4,0},  {'\'','6'},{'"','6'}, {0xab,0},
676         {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
677         {0xb0,0},  {0xb1,0},  {0xb2,0},  {0xb3,0},
678         {0xd7,0},  {0xb5,0},  {0xb6,0},  {0xb7,0},
679         {0xf7,0},  {'\'','9'},{'"','9'}, {0xbb,0},
680         {0xbc,0},  {0xbd,0},  {0xbe,0},  {0xbf,0}
681 #elif (ISO_8859 == 2) || (ISO_8859 == 4)
682         {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
683         {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
684         {0xa4,0},  {'\'','6'},{'"','6'}, {'<','<'},
685         {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
686         {0xb0,0},  {'+','-'}, {'2','S'}, {'3','S'},
687         {0xd7,0},  {'M','y'}, {'P','I'}, {'.','M'},
688         {0xf7,0},  {'\'','9'},{'"','9'}, {'>','>'},
689         {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'},
690 #elif (ISO_8859 == 3)
691         {'N','S'}, {'!','I'}, {'C','t'}, {0xa3,0},
692         {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
693         {0xa4,0},  {'\'','6'},{'"','6'}, {'<','<'},
694         {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
695         {0xb0,0},  {'+','-'}, {0xb2,0},  {0xb3,0},
696         {0xd7,0},  {0xb5,0},  {'P','I'}, {0xb7,0},
697         {0xf7,0},  {'\'','9'},{'"','9'}, {'>','>'},
698         {'1','4'}, {0xbd,0},  {'3','4'}, {'?','I'}
699 #elif (ISO_8859 == 10)
700         {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
701         {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
702         {'C','u'}, {'\'','6'},{'"','6'}, {'<','<'},
703         {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
704         {0xb0,0},  {'+','-'}, {'2','S'}, {'3','S'},
705         {'*','X'}, {'M','y'}, {'P','I'}, {0xb7,0},
706         {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
707         {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
708 #else
709         {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
710         {'D','O'}, {'Y','e'}, {'C','u'}, {'S','E'},
711         {'X','O'}, {'\'','6'},{'"','6'}, {'<','<'},
712         {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
713         {'D','G'}, {'+','-'}, {'2','S'}, {'3','S'},
714         {'*','X'}, {'M','y'}, {'P','I'}, {'.','M'},
715         {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
716         {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
717 #endif
718 };
719
720 /*
721 --- T.61 characters [0xE0 .. 0xFF] -----------------
722 */
723 static Couple trans_t61b_iso8859[48] = {
724 #if (ISO_8859 == 1)
725         {'-','M'}, {0xb9,0},  {0xae,0},  {0xa9,0},
726         {'T','M'}, {'M','8'}, {0xac,0},  {0xa6,0},
727         {0,0},     {0,0},     {0,0},     {0,0},
728         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
729         {'O','m'}, {0xc6,0},  {0xd0,0},  {0xaa,0},
730         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
731         {'L','/'}, {0xd8,0},  {'O','E'}, {0xba,0},
732         {0xde,0},  {'T','/'}, {'N','G'}, {'\'','n'},
733         {'k','k'}, {0xe6,0},  {'d','/'}, {0xf0,0},
734         {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
735         {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
736         {0xfe,0},  {'t','/'}, {'n','g'}, {'-','-'}
737 #elif (ISO_8859 == 2)
738         {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
739         {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
740         {0,0},     {0,0},     {0,0},     {0,0},
741         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
742         {'O','m'}, {'A','E'}, {0xd0,0},  {'-','a'},
743         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
744         {0xa3,0},  {'O','/'}, {'O','E'}, {'-','o'},
745         {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
746         {'k','k'}, {'a','e'}, {0xf0,0},  {'d','-'},
747         {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
748         {0xb3,0},  {'o','/'}, {'o','e'}, {0xdf,0},
749         {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
750 #elif (ISO_8859 == 3)
751         {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
752         {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
753         {0,0},     {0,0},     {0,0},     {0,0},
754         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
755         {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
756         {0xa1,0},  {0,0},     {'I','J'}, {'L','.'},
757         {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
758         {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
759         {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
760         {0xb1,0},  {0xb9,0},  {'i','j'}, {'l','.'},
761         {'l','/'}, {'o','/'}, {'o','e'}, {0xdf,0},
762         {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
763 #elif (ISO_8859 == 4)
764         {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
765         {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
766         {0,0},     {0,0},     {0,0},     {0,0},
767         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
768         {'O','m'}, {0xc6,0},  {0xd0,0},  {'-','a'},
769         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
770         {'L','/'}, {0xd8,0},  {'O','E'}, {'-','o'},
771         {'T','H'}, {0xac,0},  {0xbd,0},  {'\'','n'},
772         {0xa2,0},  {0xe6,0},  {0xf0,0},  {'d','-'},
773         {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
774         {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
775         {'t','h'}, {0xbc,0},  {0xbf,0},  {'-','-'}
776 #elif (ISO_8859 == 9)
777         {'-','M'}, {0xb9,0},  {0xae,0},  {0xa9,0},
778         {'T','M'}, {'M','8'}, {0xac,0},  {0xa6,0},
779         {0,0},     {0,0},     {0,0},     {0,0},
780         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
781         {'O','m'}, {0xc6,0},  {'D','/'}, {0xaa,0},
782         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
783         {'L','/'}, {0xd8,0},  {'O','E'}, {0xba,0},
784         {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
785         {'k','k'}, {0xe6,0},  {'d','/'}, {'d','-'},
786         {'h','/'}, {0xfd,0},  {'i','j'}, {'l','.'},
787         {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
788         {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
789 #elif (ISO_8859 == 10)
790         {0xbd,0},  {'1','S'}, {'R','g'}, {'C','o'},
791         {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
792         {0,0},     {0,0},     {0,0},     {0,0},
793         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
794         {'O','m'}, {0xc6,0},  {0xa9,0},  {'-','a'},
795         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
796         {'L','/'}, {0xd8,0},  {'O','E'}, {'-','o'},
797         {0xde,0},  {0xab,0},  {0xaf,0},  {'\'','n'},
798         {0xff,0},  {0xe6,0},  {0xb9,0},  {0xf0,0},
799         {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
800         {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
801         {0xfe,0},  {0xbb,0},  {0xbf,0},  {'-','-'}
802 #else
803         {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
804         {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
805         {0,0},     {0,0},     {0,0},     {0,0},
806         {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
807         {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
808         {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
809         {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
810         {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
811         {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
812         {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
813         {'l','/'}, {'o','/'}, {'o','e'}, {'s','s'},
814         {'t','h'}, {'t','-'}, {'n','g'}, {'-','-'}
815 #endif
816 };
817
818 /*
819 --- ISO 8859-n characters <0xA0 .. 0xFF> -------------------
820 */
821 #if (ISO_8859 == 1)
822 static Couple trans_iso8859_t61[96] = {
823         {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
824         {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
825         {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
826         {0xd6,0},     {0xff,0},     {0xd2,0},     {0xc5,ALONE},
827         {0xb0,0},     {0xb1,0},     {0xb2,0},     {0xb3,0},
828         {0xc2,ALONE}, {0xb5,0},     {0xb6,0},     {0xb7,0},
829         {0xcb,ALONE}, {0xd1,0},     {0xeb,0},     {0xbb,0},
830         {0xbc,0},     {0xbd,0},     {0xbe,0},     {0xbf,0},
831         {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
832         {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xcb,'C'},
833         {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
834         {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
835         {0xe2,0},     {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
836         {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
837         {0xe9,0},     {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
838         {0xc8,'U'},   {0xc2,'Y'},   {0xec,0},     {0xfb,0},
839         {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
840         {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xcb,'c'},
841         {0xc1,'e'},   {0xc2,'e'},   {0xc3,'e'},   {0xc8,'e'},
842         {0xc1,'i'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
843         {0xf3,0},     {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
844         {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
845         {0xf9,0},     {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
846         {0xc8,'u'},   {0xc2,'y'},   {0xfc,0},     {0xc8,'y'}
847 };
848 #elif (ISO_8859 == 2)
849 static Couple trans_iso8859_t61[96] = {
850         {0xa0,0},     {0xce,'A'},   {0xc6,ALONE}, {0xe8,0},
851         {0xa8,0},     {0xcf,'L'},   {0xc2,'S'},   {0xa7,0},
852         {0xc8,ALONE}, {0xcf,'S'},   {0xcb,'S'},   {0xcf,'T'},
853         {0xc2,'Z'},   {0xff,0},     {0xcf,'Z'},   {0xc7,'Z'},
854         {0xb0,0},     {0xce,'a'},   {0xce,ALONE}, {0xf8,0},
855         {0xc2,ALONE}, {0xcf,'l'},   {0xc2,'s'},   {0xcf,ALONE},
856         {0xcb,ALONE}, {0xcf,'s'},   {0xcb,'s'},   {0xcf,'t'},
857         {0xc2,'z'},   {0xcd,ALONE}, {0xcf,'z'},   {0xc7,'z'},
858         {0xc2,'R'},   {0xc2,'A'},   {0xc3,'A'},   {0xc6,'A'},
859         {0xc8,'A'},   {0xc2,'L'},   {0xc2,'C'},   {0xcb,'C'},
860         {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
861         {0xcf,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xcf,'D'},
862         {0xe2,0},     {0xc2,'N'},   {0xcf,'N'},   {0xc2,'O'},
863         {0xc3,'O'},   {0xcd,'O'},   {0xc8,'O'},   {0xb4,0},
864         {0xcf,'R'},   {0xca,'U'},   {0xc2,'U'},   {0xcd,'U'},
865         {0xc8,'U'},   {0xc2,'Y'},   {0xcb,'T'},   {0xfb,0},
866         {0xc2,'r'},   {0xc2,'a'},   {0xc3,'a'},   {0xc6,'a'},
867         {0xc8,'a'},   {0xc2,'l'},   {0xc2,'c'},   {0xcb,'c'},
868         {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
869         {0xcf,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xcf,'d'},
870         {0xf2,0},     {0xc2,'n'},   {0xcf,'n'},   {0xc2,'o'},
871         {0xc3,'o'},   {0xcd,'o'},   {0xc8,'o'},   {0xb8,0},
872         {0xcf,'r'},   {0xca,'u'},   {0xc2,'u'},   {0xcd,'u'},
873         {0xc8,'u'},   {0xc2,'y'},   {0xcb,'t'},   {0xc7,ALONE}
874 };
875 #elif (ISO_8859 == 3)
876 static Couple trans_iso8859_t61[96] = {
877         {0xa0,0},     {0xe4,0},     {0xc6,ALONE}, {0xa3,0},
878         {0xa8,0},     {0,0},        {0xc3,'H'},   {0xa7,0},
879         {0xc8,ALONE}, {0xc7,'I'},   {0xcb,'S'},   {0xc6,'G'},
880         {0xc3,'J'},   {0xff,0},     {0,0},        {0xc7,'Z'},
881         {0xb0,0},     {0xf4,0},     {0xb2,0},     {0xb3,0},
882         {0xc2,ALONE}, {0xb5,0},     {0xc3,'h'},   {0xb7,0},
883         {0xcb,ALONE}, {0xf5,0},     {0xcb,'s'},   {0xc6,'g'},
884         {0xc3,'j'},   {0xbd,0},     {0,0},        {0xc7,'z'},
885         {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0,0},
886         {0xc8,'A'},   {0xc7,'C'},   {0xc3,'C'},   {0xcb,'C'},
887         {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
888         {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
889         {0,0},        {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
890         {0xc3,'O'},   {0xc7,'G'},   {0xc8,'O'},   {0xb4,0},
891         {0xc3,'G'},   {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
892         {0xc8,'U'},   {0xc6,'U'},   {0xc3,'S'},   {0xfb,0},
893         {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0,0},
894         {0xc8,'a'},   {0xc7,'c'},   {0xc3,'c'},   {0xcb,'c'},
895         {0xc1,'e'},   {0xc2,'e'},   {0xc3,'e'},   {0xc8,'e'},
896         {0xc1,'i'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
897         {0,0},        {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
898         {0xc3,'o'},   {0xc7,'g'},   {0xc8,'o'},   {0xb8,0},
899         {0xc3,'g'},   {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
900         {0xc8,'u'},   {0xc6,'u'},   {0xc3,'s'},   {0xc7,ALONE}
901 };
902 #elif (ISO_8859 == 4)
903 static Couple trans_iso8859_t61[96] = {
904         {0xa0,0},     {0xce,'A'},   {0xf0,0},     {0xcb,'R'},
905         {0xa8,0},     {0xc4,'I'},   {0xcb,'L'},   {0xa7,0},
906         {0xc8,ALONE}, {0xcf,'S'},   {0xc5,'E'},   {0xcb,'G'},
907         {0xed,0},     {0xff,0},     {0xcf,'Z'},   {0xc5,ALONE},
908         {0xb0,0},     {0xce,'a'},   {0xce,ALONE}, {0xcb,'r'},
909         {0xc2,ALONE}, {0xc4,'i'},   {0xcb,'l'},   {0xcf,ALONE},
910         {0xcb,ALONE}, {0xcf,'s'},   {0xc5,'e'},   {0xcb,'g'},
911         {0xfd,0},     {0xee,0},     {0xcf,'z'},   {0xfe,0},
912         {0xc5,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
913         {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xce,'I'},
914         {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
915         {0xc7,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xc5,'I'},
916         {0xe2,0},     {0xcb,'N'},   {0xc5,'O'},   {0xcb,'K'},
917         {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
918         {0xe9,0},     {0xce,'U'},   {0xc2,'U'},   {0xc3,'U'},
919         {0xc8,'U'},   {0xc4,'U'},   {0xc5,'U'},   {0xfb,0},
920         {0xc5,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
921         {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xce,'i'},
922         {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
923         {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc5,'i'},
924         {0xf2,0},     {0xcb,'n'},   {0xc5,'o'},   {0xcb,'k'},
925         {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
926         {0xf9,0},     {0xce,'u'},   {0xc2,'u'},   {0xc3,'u'},
927         {0xc8,'u'},   {0xc4,'u'},   {0xc5,'u'},   {0xc7,ALONE}
928 };
929 #elif (ISO_8859 == 9)
930 static Couple trans_iso8859_t61[96] = {
931         {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
932         {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
933         {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
934         {0xd6,0},     {0xff,0},     {0xd2,0},     {0xc5,ALONE},
935         {0xb0,0},     {0xb1,0},     {0xb2,0},     {0xb3,0},
936         {0xc2,ALONE}, {0xb5,0},     {0xb6,0},     {0xb7,0},
937         {0xcb,ALONE}, {0xd1,0},     {0xeb,0},     {0xbb,0},
938         {0xbc,0},     {0xbd,0},     {0xbe,0},     {0xbf,0},
939         {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
940         {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xcb,'C'},
941         {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
942         {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
943         {0xc6,'G'},   {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
944         {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
945         {0xe9,0},     {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
946         {0xc8,'U'},   {0xc7,'I'},   {0xcb,'S'},   {0xfb,0},
947         {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
948         {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xcb,'c'},
949         {0xc1,'e'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
950         {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc5,'i'},
951         {0xc6,'g'},   {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
952         {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
953         {0xf9,0},     {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
954         {0xc8,'u'},   {0xf5,0},     {0xcb,'s'},   {0xc8,'y'}
955 };
956 #elif (ISO_8859 == 10)
957 static Couple trans_iso8859_t61[96] = {
958         {0xa0,0},     {0xce,'A'},   {0xc5,'E'},   {0xcb,'G'},
959         {0xc5,'I'},   {0xc4,'I'},   {0xcb,'K'},   {0xa7,0},
960         {0xcb,'L'},   {0xe2,0},     {0xcf,'S'},   {0xed,0},
961         {0xcf,'Z'},   {0xff,0},     {0xc5,'U'},   {0xee,0},
962         {0xb0,0},     {0xce,'a'},   {0xc5,'e'},   {0xcb,'g'},
963         {0xc5,'i'},   {0xc4,'i'},   {0xcb,'k'},   {0xb7,0},
964         {0xcb,'l'},   {0xf2,0},     {0xcf,'s'},   {0xfd,0},
965         {0xcf,'z'},   {0xd0,0},     {0xc5,'u'},   {0xfe,0},
966         {0xc5,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
967         {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xce,'I'},
968         {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
969         {0xc7,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
970         {0,0},        {0xcb,'N'},   {0xc5,'O'},   {0xc2,'O'},
971         {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xc4,'U'},
972         {0xe9,0},     {0xce,'U'},   {0xc2,'U'},   {0xc3,'U'},
973         {0xc8,'U'},   {0xc2,'Y'},   {0xec,0},     {0xfb,0},
974         {0xc5,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
975         {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xce,'i'},
976         {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
977         {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
978         {0xf3,0},     {0xcb,'n'},   {0xc5,'o'},   {0xc2,'o'},
979         {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xc4,'u'},
980         {0xf9,0},     {0xce,'u'},   {0xc2,'u'},   {0xc3,'u'},
981         {0xc8,'u'},   {0xc2,'y'},   {0xfc,0},     {0xf0,0}
982 };
983 #endif
984
985
986 static Byte *
987 c_to_hh( Byte *o, Byte c )
988 {
989   Byte n;
990
991   *o++ = '{'; *o++ = 'x';
992   n = c >> 4;
993   *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
994   n = c & 0x0F;
995   *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
996   *o++ = '}';
997   return o;
998 }
999
1000
1001 static Byte *
1002 c_to_cc( Byte *o, Couple *cc, Byte c )
1003 {
1004   if ( (*cc).a != 0 ) {
1005     if ( (*cc).b == 0 )
1006       *o++ = (*cc).a;
1007     else {
1008       *o++ = '{';
1009       *o++ = (*cc).a;
1010       *o++ = (*cc).b;
1011       *o++ = '}';
1012     }
1013     return o;
1014   }
1015   else
1016     return c_to_hh( o, c );
1017 }
1018
1019 /* --- routine to convert from T.61 to ISO 8859-n --- */
1020
1021 int
1022 ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
1023 {
1024   Byte          *s, *oo, *o;
1025   unsigned int  n;
1026   int           c;
1027   unsigned long len;
1028   Couple        *cc;
1029
1030   Debug( LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n",
1031         *buflenp, 0, 0 );
1032
1033   len = *buflenp;
1034   s = (Byte *) *bufp;
1035
1036   if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
1037         return( 1 );
1038   }
1039
1040   while ( (char *)s - *(char **)bufp < len ) {
1041     switch ( *s >> 4 ) {
1042
1043     case 0xA: case 0xB:
1044       o = c_to_cc( o, &trans_t61a_iso8859[ *s - 0xA0 ], *s );
1045       s++;
1046       break;
1047
1048     case 0xD: case 0xE: case 0xF:
1049       o = c_to_cc( o, &trans_t61b_iso8859[ *s - 0xD0 ], *s );
1050       s++;
1051       break;
1052
1053     case 0xC:
1054       if ( (*s == 0xC0) || (*s == 0xC9) || (*s == 0xCC) ) {
1055         o = c_to_hh( o, *s++ );
1056         break;
1057       }
1058
1059       n = (*s++) - 0xC0;
1060       switch ( *s ) {
1061
1062       case 'A':  c = letter_w_diacritic[n][0]; break;
1063       case 'C':  c = letter_w_diacritic[n][1]; break;
1064       case 'D':  c = letter_w_diacritic[n][2]; break;
1065       case 'E':  c = letter_w_diacritic[n][3]; break;
1066       case 'G':  c = letter_w_diacritic[n][4]; break;
1067       case 'H':  c = letter_w_diacritic[n][5]; break;
1068       case 'I':  c = letter_w_diacritic[n][6]; break;
1069       case 'J':  c = letter_w_diacritic[n][7]; break;
1070       case 'K':  c = letter_w_diacritic[n][8]; break;
1071       case 'L':  c = letter_w_diacritic[n][9]; break;
1072       case 'N':  c = letter_w_diacritic[n][10]; break;
1073       case 'O':  c = letter_w_diacritic[n][11]; break;
1074       case 'R':  c = letter_w_diacritic[n][12]; break;
1075       case 'S':  c = letter_w_diacritic[n][13]; break;
1076       case 'T':  c = letter_w_diacritic[n][14]; break;
1077       case 'U':  c = letter_w_diacritic[n][15]; break;
1078       case 'W':  c = letter_w_diacritic[n][16]; break;
1079       case 'Y':  c = letter_w_diacritic[n][17]; break;
1080       case 'Z':  c = letter_w_diacritic[n][18]; break;
1081
1082       case 'a':  c = letter_w_diacritic[n][19]; break;
1083       case 'c':  c = letter_w_diacritic[n][20]; break;
1084       case 'd':  c = letter_w_diacritic[n][21]; break;
1085       case 'e':  c = letter_w_diacritic[n][22]; break;
1086       case 'g':  c = letter_w_diacritic[n][23]; break;
1087       case 'h':  c = letter_w_diacritic[n][24]; break;
1088       case 'i':  c = letter_w_diacritic[n][25]; break;
1089       case 'j':  c = letter_w_diacritic[n][26]; break;
1090       case 'k':  c = letter_w_diacritic[n][27]; break;
1091       case 'l':  c = letter_w_diacritic[n][28]; break;
1092       case 'n':  c = letter_w_diacritic[n][29]; break;
1093       case 'o':  c = letter_w_diacritic[n][30]; break;
1094       case 'r':  c = letter_w_diacritic[n][31]; break;
1095       case 's':  c = letter_w_diacritic[n][32]; break;
1096       case 't':  c = letter_w_diacritic[n][33]; break;
1097       case 'u':  c = letter_w_diacritic[n][34]; break;
1098       case 'w':  c = letter_w_diacritic[n][35]; break;
1099       case 'y':  c = letter_w_diacritic[n][36]; break;
1100       case 'z':  c = letter_w_diacritic[n][37]; break;
1101
1102       case ALONE:  c = (( !diacritic[n].b ) ? diacritic[n].a : -1);
1103                    break;
1104
1105       default:   c = 0;
1106       }
1107
1108       if ( c > 0 ) {
1109         *o++ = c;  s++;
1110       } else {
1111         *o++ = '{';
1112         if ( c == -1 ) {
1113           *o++ = ( ( *s == ALONE ) ? ' ' : *s );
1114           s++;
1115         } else {
1116           *o++ = '"';
1117         }
1118         *o++ = diacritic[n].a;
1119         *o++ = '}';
1120       }
1121       break;
1122
1123 #if (ISO_8859 == 0)
1124     case 0x8: case 0x9:
1125       *o++ = 0x1B; /* <ESC> */
1126       *o++ = *s++ - 0x40;
1127       break;
1128 #endif
1129
1130       default:
1131         *o++ = *s++;
1132     }
1133   }
1134
1135   len = o - oo;
1136   o = oo;
1137
1138   if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
1139     free( o );
1140     return( 1 );
1141   }
1142
1143   if ( free_input ) {
1144     free( *bufp );
1145   }
1146   *bufp = (char *) oo;
1147   *buflenp = len;
1148   return( 0 );
1149 }
1150
1151
1152 static int
1153 hh_to_c( Byte *h )
1154 {
1155   Byte c;
1156
1157   if ( (*h >= '0') && (*h <= '9') )      c = *h++ - '0';
1158   else if ( (*h >= 'A') && (*h <= 'F') ) c = *h++ - 'A' + 10;
1159   else if ( (*h >= 'a') && (*h <= 'f') ) c = *h++ - 'a' + 10;
1160   else return -1;
1161
1162   c <<= 4;
1163
1164   if ( (*h >= '0') && (*h <= '9') )      c |= *h - '0';
1165   else if ( (*h >= 'A') && (*h <= 'F') ) c |= *h - 'A' + 10;
1166   else if ( (*h >= 'a') && (*h <= 'f') ) c |= *h - 'a' + 10;
1167   else return -1;
1168
1169   return c;
1170 }
1171
1172
1173 static Byte *
1174 cc_to_t61( Byte *o, Byte *s )
1175 {
1176   int n, c = 0;
1177
1178   switch ( *(s + 1) ) {
1179
1180   case '`':  c = -1;   break;    /* <grave-accent> */
1181
1182   case '!':
1183     switch ( *s ) {
1184     case '!':  c = 0x7C;  break;  /* <vertical-line> */
1185     case '(':  c = 0x7B;  break;  /* <left-curly-bracket> */
1186     case '-':  c = 0xAD;  break;  /* <upwards-arrow> */
1187     default:   c = -1;            /* <grave-accent> */
1188     }
1189     break;
1190
1191 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1192     (ISO_8859 == 4) || (ISO_8859 == 9)
1193   case 0xB4:
1194 #endif
1195   case '\'': c = -2;  break;    /* <acute-accent> */
1196
1197   case '^':  c = -3;  break;    /* <circumflex-acent> */
1198
1199   case '>':
1200     switch ( *s ) {
1201     case ')':  c = 0x5D;  break;  /* <right-square-bracket> */
1202     case '>':  c = 0xBB;  break;  /* <right-angle-quotation> */
1203     case '-':  c = 0xAE;  break;  /* <rightwards-arrow> */
1204     default:   c = -3;            /* <circumflex-acent> */
1205     }
1206     break;
1207
1208   case '~':
1209   case '?':  c = -4;  break;        /* <tilde> */
1210
1211 #if (ISO_8859 == 1) || (ISO_8859 == 4) || (ISO_8859 == 9)
1212   case 0xAF:  c = -5;  break;       /* <macron> */
1213 #endif
1214
1215   case '-':
1216     switch ( *s ) {
1217     case '-':  c = 0xFF; break; /* <soft-hyphen> */
1218     case '<':  c = 0xAC; break; /* <leftwards arrow> */
1219     case '+':  c = 0xB1; break; /* <plus-minus> */
1220     case 'd':  c = 0xF3; break; /* <eth> */
1221     default:   c = -5;          /* <macron> */
1222     }
1223     break;
1224
1225 #if (ISO_8859 == 2) || (ISO_8859 == 3)
1226   case 0xA2:  c = -6;  break;            /* <breve> */
1227 #endif
1228
1229   case '(':
1230     if ( *s == '<' ) c = 0x5B;  /* <left-square-bracket> */
1231     else             c = -6;    /* <breve> */
1232     break;
1233
1234 #if (ISO_8859 == 2) || (ISO_8859 == 3) || (ISO_8859 == 4)
1235   case 0xFF:  c = -7;  break;    /* <dot-accent> */
1236 #endif
1237
1238   case '.':
1239     switch ( *s ) {
1240     case 'i':  c = 0xF5; break; /* <dotless-i> */
1241     case 'L':  c = 0xE7; break; /* <L-middle-dot> */
1242     case 'l':  c = 0xF7; break; /* <l-middle-dot> */
1243     default:   c = -7;          /* <dot-accent> */
1244     }
1245     break;
1246
1247 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1248     (ISO_8859 == 4) || (ISO_8859 == 9)
1249   case 0xA8:  c = -8; break; /* <diaeresis> */
1250 #endif
1251
1252   case ':':
1253     if ( *s == '-')  c = 0xB8; /* <division-sign> */
1254     else             c = -8;   /* <diaeresis> */
1255     break;
1256
1257 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1258     (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
1259   case 0xB0:
1260 #endif
1261   case '0':  c = -10;  break;  /* <ring-above> */
1262
1263 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1264     (ISO_8859 == 4) || (ISO_8859 == 9)
1265   case 0xB8:
1266 #endif
1267   case ',':  c = -11; break; /* <cedilla> */
1268
1269 #if (ISO_8859 == 2)
1270   case 0xBD:
1271 #endif
1272   case '"':  c = -13; break; /* <double-acute-accent> */
1273
1274 #if (ISO_8859 == 2) || (ISO_8859 == 4)
1275   case 0xB2:
1276 #endif
1277   case ';':  c = -14; break; /* <ogonek> */
1278
1279 #if (ISO_8859 == 2) || (ISO_8859 == 4)
1280   case 0xB7:  c = -15;  break;  /* <caron> */
1281 #endif
1282
1283   case ')':
1284     if ( *s == '!' )  c = 0x7D;  /* <left-curly-bracket> */
1285     break;
1286
1287   case '<':
1288     if ( *s == '<' )  c = 0xAB;  /* <left-angle-quotation> */
1289     else              c = -15;   /* <caron> */
1290     break;
1291
1292   case '/':
1293     switch ( *s ) {
1294     case '/':  c = 0x5C; break; /* <reverse-solidus> */
1295     case 'D':  c = 0xE2; break; /* <D-stroke> */
1296     case 'd':  c = 0xF2; break; /* <d-stroke> */
1297     case 'H':  c = 0xE4; break; /* <H-stroke> */
1298     case 'h':  c = 0xF4; break; /* <h-stroke> */
1299     case 'L':  c = 0xE8; break; /* <L-stroke> */
1300     case 'l':  c = 0xF8; break; /* <l-stroke> */
1301     case 'O':  c = 0xE9; break; /* <O-stroke> */
1302     case 'o':  c = 0xF9; break; /* <o-stroke> */
1303     case 'T':  c = 0xED; break; /* <T-stroke> */
1304     case 't':  c = 0xFD; break; /* <t-stroke> */
1305     }
1306     break;
1307
1308   case '2':
1309     if ( *s == '1' )  c = 0xBD;    /* <one-half> */
1310     break;
1311
1312   case '4':
1313     switch ( *s ) {
1314     case '1':  c = 0xBC; break; /* <one-quarter> */
1315     case '3':  c = 0xBE; break; /* <three-quarters> */
1316     }
1317     break;
1318
1319   case '6':
1320     switch ( *s ) {
1321     case '\'': c = 0xA9; break; /* <left-single-quotation> */
1322     case '"':  c = 0xAA; break; /* <left-double-quotation> */
1323     }
1324     break;
1325
1326   case '8':
1327     switch ( *s ) {
1328     case '1':  c = 0xDC; break; /* <one-eighth> */
1329     case '3':  c = 0xDD; break; /* <three-eighths> */
1330     case '5':  c = 0xDE; break; /* <five-eighths> */
1331     case '7':  c = 0xDF; break; /* <seven-eighths> */
1332     case 'M':  c = 0xD5; break; /* <eighth-note> */
1333     }
1334     break;
1335
1336   case '9':
1337     switch ( *s ) {
1338     case '\'': c = 0xB9; break; /* <right-single-quotation> */
1339     case '"':  c = 0xBA; break; /* <right-double-quotation> */
1340     }
1341     break;
1342
1343   case 'A':
1344     if ( *s == 'A' )  c = -10;  /* <ring-above> + <A> */
1345     break;
1346
1347   case 'a':
1348     switch ( *s ) {
1349     case '-':  c = 0xE3; break; /* <femenine-ordinal-a> */
1350     case 'a':  c = -10;  break; /* <ring-above> + <a> */
1351     }
1352     break;
1353
1354   case 'B':
1355     if ( *s == 'B' )  c = 0xD7; /* <broken-bar> */
1356     break;
1357
1358   case 'b':
1359     if ( *s == 'N' )  c = 0xA6;  /* <number-sign> */
1360     break;
1361
1362   case 'd':
1363     if ( *s == 'P' )  c = 0xA3;  /* <pound-sign> */
1364     break;
1365
1366   case 'E':
1367     switch ( *s ) {
1368     case 'S':  c = 0xA7; break; /* <section-sign> */
1369     case 'A':  c = 0xE1; break; /* <AE> */
1370     case 'O':  c = 0xEA; break; /* <OE> */
1371     }
1372     break;
1373
1374   case 'e':
1375     switch ( *s ) {
1376     case 'a':  c = 0xF1; break; /* <ae> */
1377     case 'o':  c = 0xFA; break; /* <oe> */
1378     case 'Y':  c = 0xA5;  break;  /* <yen-sign> */
1379     }
1380     break;
1381
1382   case 'G':
1383     switch ( *s ) {
1384     case 'D':  c = 0xB0; break; /* <degree-sign> */
1385     case 'N':  c = 0xEE; break; /* <Eng> */
1386     }
1387     break;
1388
1389   case 'g':
1390     switch ( *s ) {
1391     case 'R':  c = 0xD2; break;  /* <registered-sign> */
1392     case 'n':  c = 0xFE; break; /* <eng> */
1393     }
1394     break;
1395
1396   case 'H':
1397     if ( *s == 'T' )  c = 0xEC;  /* <Thorn> */
1398     break;
1399
1400   case 'h':
1401     if ( *s == 't' )  c = 0xFC; /* <thorn> */
1402     break;
1403
1404   case 'I':
1405     switch ( *s ) {
1406     case 'P':  c = 0xB6; break;  /* <pilcrow-sign> */
1407     case '!':  c = 0xA1; break; /* <inverted-exclamation> */
1408     case '?':  c = 0xBF; break; /* <inverted-question> */
1409     }
1410     break;
1411
1412   case 'J':
1413     if ( *s == 'I' )  c = 0xE6; /* <IJ> */
1414     break;
1415
1416   case 'j':
1417     if ( *s == 'i' )  c = 0xF6;  /* <ij> */
1418     break;
1419
1420   case 'k':
1421     if ( *s == 'k' )  c = 0xF0; /* <kra> */
1422     break;
1423
1424   case 'M':
1425     switch ( *s ) {
1426     case '.':  c = 0xB7; break; /* <middle-dot> */
1427     case '-':  c = 0xD0; break; /* <em-dash> */
1428     case 'T':  c = 0xD4; break; /* <trade-mark-sign> */
1429     }
1430     break;
1431
1432   case 'm':
1433     switch ( *s ) {
1434     case '\'':                  /* <macron> RFC 1345 */
1435     case ' ':  c = -5;   break; /* <macron> */
1436     case 'O':  c = 0xE0; break; /* <Ohm sign> */
1437     }
1438     break;
1439
1440   case 'n':
1441     if ( *s == '\'' )  c = 0xEF; /* <n-preceded-by-apostrophe> */
1442     break;
1443
1444   case 'O':
1445     switch ( *s ) {
1446     case 'D':  c = 0xA4; break; /* <dollar-sign> */
1447     case 'N':  c = 0xD6; break; /* <not-sign> */
1448     }
1449     break;
1450
1451   case 'o':
1452     switch ( *s ) {
1453     case 'C':  c = 0xD3; break; /* <copyright-sign> */
1454     case '-':  c = 0xEB; break; /* <masculine-ordinal-o> */
1455     }
1456     break;
1457
1458   case 'S':
1459     switch ( *s ) {
1460     case '1':  c = 0xD1; break; /* <superscript-1> */
1461     case '2':  c = 0xB2; break; /* <superscript-2> */
1462     case '3':  c = 0xB3; break; /* <superscript-3> */
1463     case 'N':  c = 0xA0; break; /* <no-break-space> */
1464     }
1465     break;
1466
1467   case 's':
1468     if ( *s == 's' )  c = 0xFB; /* <sharp-s> */
1469     break;
1470
1471   case 't':
1472     if ( *s == 'C' )  c = 0xA2; /* <cent-sign> */
1473     break;
1474
1475   case 'u':
1476     if ( *s == 'C' )  c = 0xA8; /* <currency-sign> */
1477     break;
1478
1479   case 'v':
1480     if ( *s == '-' )  c = 0xAF; /* <downwards-arrow> */
1481     break;
1482
1483   case 'X':
1484     if ( *s == '*' )  c = 0xB4; /* <multiplication-sign> */
1485     break;
1486
1487   case 'y':
1488     if ( *s == 'M' )  c = 0xB5; /* <micro-sign> */
1489     break;
1490   }
1491
1492   if ( c > 0 ) {
1493     *o++ = c;
1494     return o;
1495   } else if ( !c )
1496     return NULL;
1497
1498   /* else: c < 0 */
1499   n = -c;
1500   switch ( *s ) {
1501
1502   case 'A':  c = letter_w_diacritic[n][0]; break;
1503   case 'C':  c = letter_w_diacritic[n][1]; break;
1504   case 'D':  c = letter_w_diacritic[n][2]; break;
1505   case 'E':  c = letter_w_diacritic[n][3]; break;
1506   case 'G':  c = letter_w_diacritic[n][4]; break;
1507   case 'H':  c = letter_w_diacritic[n][5]; break;
1508   case 'I':  c = letter_w_diacritic[n][6]; break;
1509   case 'J':  c = letter_w_diacritic[n][7]; break;
1510   case 'K':  c = letter_w_diacritic[n][8]; break;
1511   case 'L':  c = letter_w_diacritic[n][9]; break;
1512   case 'N':  c = letter_w_diacritic[n][10]; break;
1513   case 'O':  c = letter_w_diacritic[n][11]; break;
1514   case 'R':  c = letter_w_diacritic[n][12]; break;
1515   case 'S':  c = letter_w_diacritic[n][13]; break;
1516   case 'T':  c = letter_w_diacritic[n][14]; break;
1517   case 'U':  c = letter_w_diacritic[n][15]; break;
1518   case 'W':  c = letter_w_diacritic[n][16]; break;
1519   case 'Y':  c = letter_w_diacritic[n][17]; break;
1520   case 'Z':  c = letter_w_diacritic[n][18]; break;
1521
1522   case 'a':  c = letter_w_diacritic[n][19]; break;
1523   case 'c':  c = letter_w_diacritic[n][20]; break;
1524   case 'd':  c = letter_w_diacritic[n][21]; break;
1525   case 'e':  c = letter_w_diacritic[n][22]; break;
1526   case 'g':  c = letter_w_diacritic[n][23]; break;
1527   case 'h':  c = letter_w_diacritic[n][24]; break;
1528   case 'i':  c = letter_w_diacritic[n][25]; break;
1529   case 'j':  c = letter_w_diacritic[n][26]; break;
1530   case 'k':  c = letter_w_diacritic[n][27]; break;
1531   case 'l':  c = letter_w_diacritic[n][28]; break;
1532   case 'n':  c = letter_w_diacritic[n][29]; break;
1533   case 'o':  c = letter_w_diacritic[n][30]; break;
1534   case 'r':  c = letter_w_diacritic[n][31]; break;
1535   case 's':  c = letter_w_diacritic[n][32]; break;
1536   case 't':  c = letter_w_diacritic[n][33]; break;
1537   case 'u':  c = letter_w_diacritic[n][34]; break;
1538   case 'w':  c = letter_w_diacritic[n][35]; break;
1539   case 'y':  c = letter_w_diacritic[n][36]; break;
1540   case 'z':  c = letter_w_diacritic[n][37]; break;
1541
1542   case '\'':
1543   case ' ':  c = -1; break;
1544
1545   default:   c = 0;
1546   }
1547
1548   if ( !c )
1549     return NULL;
1550
1551   *o++ = n + 0xC0;
1552   *o++ = ( ( (*s == ' ') || (*s == '\'') ) ? ALONE : *s );
1553   return o;
1554 }
1555
1556
1557 /* --- routine to convert from ISO 8859-n to T.61 --- */
1558
1559 int
1560 ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
1561 {
1562   Byte          *s, *oo, *o, *aux;
1563   int           c;
1564   unsigned long len; 
1565   Couple        *cc;
1566
1567   Debug( LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n",
1568         *buflenp, 0, 0 );
1569
1570   len = *buflenp;
1571   s = (Byte *) *bufp;
1572
1573   if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
1574         return( 1 );
1575   }
1576
1577   while ( (char *)s - *(char **)bufp < len ) {
1578     switch( *s >> 5 ) {
1579
1580     case 2:
1581       switch ( *s ) {
1582
1583       case '^':  *o++ = 0xC3; *o++ = ALONE; s++; break;
1584
1585       case '\\':
1586         s++;
1587         if ( (c = hh_to_c( s )) != -1 ) {
1588           *o++ = c;
1589           s += 2;
1590         } else
1591           *o++ = '\\';
1592         break;
1593
1594       default:  *o++ = *s++;
1595       }
1596       break;
1597
1598     case 3:
1599       switch ( *s ) {
1600
1601       case '`':  *o++ = 0xC1; *o++ = ALONE; s++; break;
1602       case '~':  *o++ = 0xC4; *o++ = ALONE; s++; break;
1603
1604       case '{':
1605         s++;
1606         if ( *(s + 2) == '}' ) {
1607           if ( (aux = cc_to_t61( o, s )) != NULL ) {
1608             o = aux;
1609             s += 3;
1610           } else {
1611             *o++ = '{';
1612           }
1613         } else if ( (*(s + 3) == '}') && ( (*s == 'x') || (*s == 'X') ) &&
1614                     ( (c = hh_to_c( s + 1 )) != -1 ) ) {
1615           *o++ = c;
1616           s += 4;
1617         } else {
1618           *o++ = '{';
1619         }
1620         break;
1621
1622       default:
1623         *o++ = *s++;
1624       }
1625       break;
1626
1627 #if (ISO_8859 == 0)
1628     case 4: case 5: case 6: case 7:
1629       s++;
1630       break;
1631 #else
1632     case 5: case 6: case 7:
1633 # if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
1634      (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
1635       if ( (*(cc = &trans_iso8859_t61[ *s - 0xA0 ])).a ) {
1636         *o++ = (*cc).a;
1637         if ( (*cc).b )  *o++ = (*cc).b;
1638       }
1639 # endif
1640       s++;
1641       break;
1642 #endif
1643
1644     default:
1645       *o++ = *s++;
1646     }
1647   }
1648
1649   len = o - oo;
1650   o = oo;
1651
1652   if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
1653     free( o );
1654     return( 1 );
1655   }
1656
1657   if ( free_input ) {
1658     free( *bufp );
1659   }
1660   *bufp = (char *) oo;
1661   *buflenp = len;
1662   return( 0 );
1663 }
1664
1665
1666 #ifdef NOT_NEEDED_IN_LIBLDAP    /* mcs@umich.edu 12 Oct 1995 */
1667 /* --- routine to convert "escaped" (\hh) characters to 8bits --- */
1668
1669 void convert_escaped_to_8bit( s )
1670 char    *s;
1671 {
1672   char  *o = s;
1673   int   c;
1674
1675   while ( *s ) {
1676     if ( *s == '\\' ) {
1677       if ( (c = hh_to_c( ++s )) != -1 ) {
1678         *o++ = c;
1679         s += 2;
1680       } else
1681         *o++ = '\\';
1682     } else
1683       *o++ = *s++;
1684   }
1685   *o = '\0';
1686 }
1687
1688 /* --- routine to convert 8bits characters to the "escaped" (\hh) form --- */
1689
1690 char *convert_8bit_to_escaped( s )
1691 Byte  *s;
1692 {
1693   Byte  *o, *oo;
1694   Byte  n;
1695
1696   if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
1697         return( NULL );
1698   }
1699
1700   while ( *s ) {
1701     if ( *s < 0x80 )
1702       *o++ = *s++;
1703     else {
1704       *o++ = '\\';
1705       n = *s >> 4;
1706       *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1707       n = *s++ & 0x0F;
1708       *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
1709     }
1710   }
1711   *o = '\0';
1712
1713   o = oo;
1714
1715   if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
1716     free( o );
1717     return( NULL );
1718   }
1719
1720   return( (char *)oo );
1721 }
1722
1723 /* --- routine to convert from T.61 to printable characters --- */
1724
1725 /*
1726    printable characters [RFC 1488]: 'A'..'Z', 'a'..'z', '0'..'9',
1727        '\'', '(', ')', '+', ',', '-', '.', '/', ':', '?, ' '.
1728
1729    that conversion is language dependent.
1730 */
1731
1732 static Couple last_t61_printabled[32] = {
1733         {0,0},     {'A','E'}, {'D',0},   {0,0},
1734         {'H',0},   {0,0},     {'I','J'}, {'L',0},
1735         {'L',0},   {'O',0},   {'O','E'}, {0,0},
1736         {'T','H'}, {'T',0},   {'N','G'}, {'n',0},
1737         {'k',0},   {'a','e'}, {'d',0},   {'d',0},
1738         {'h',0},   {'i',0},   {'i','j'}, {'l',0},
1739         {'l',0},   {'o',0},   {'o','e'}, {'s','s'},
1740         {'t','h'}, {'t',0},   {'n','g'}, {0,0}
1741 };
1742
1743 char *t61_printable( s )
1744 Byte  *s;
1745 {
1746   Byte   *o, *oo;
1747   Byte   n;
1748   Couple *cc;
1749
1750   if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
1751         return( NULL );
1752   }
1753
1754   while ( *s ) {
1755     if ( ( (*s >= 'A') && (*s <= 'Z') ) ||
1756          ( (*s >= 'a') && (*s <= 'z') ) ||
1757          ( (*s >= '0') && (*s <= '9') ) ||
1758          ( (*s >= '\'') && (*s <= ')') ) ||
1759          ( (*s >= '+') && (*s <= '/') ) ||
1760          ( *s == '?' ) || ( *s == ' ' ) )
1761       *o++ = *s++;
1762     else {
1763       if ( *s >= 0xE0 ) {
1764         if ( (*(cc = &last_t61_printabled[ *s - 0xE0 ])).a ) {
1765           *o++ = (*cc).a;
1766           if ( (*cc).b )  *o++ = (*cc).b;
1767         }
1768       }
1769       else if ( (*s >> 4) == 0xC ) {
1770         switch ( *s ) {
1771         case 0xCA:                      /* ring */
1772           switch ( *(s + 1) ) {
1773           case 'A':  *o++ = 'A'; *o++ = 'A'; s++; break; /* Swedish */
1774           case 'a':  *o++ = 'a'; *o++ = 'a'; s++; break; /* Swedish */
1775           }
1776           break;
1777
1778         case 0xC8:                      /* diaeresis */
1779           switch ( *(s + 1) ) {
1780           case 'Y':  *o++ = 'I'; *o++ = 'J'; s++; break; /* Dutch */
1781           case 'y':  *o++ = 'i'; *o++ = 'j'; s++; break; /* Dutch */
1782           }
1783           break;
1784         }
1785       }
1786       s++;
1787     }
1788   }
1789   *o = '\0';
1790
1791   o = oo;
1792
1793   if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
1794     free( o );
1795     return( NULL );
1796   }
1797
1798   return( (char *)oo );
1799 }
1800 #endif /* NOT_NEEDED_IN_LIBLDAP */      /* mcs@umich.edu 12 Oct 1995 */
1801
1802 #endif /* LDAP_CHARSET_8859 */
1803 #endif /* STR_TRANSLATION */