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