Back to index

lightning-sunbird  0.9+nobinonly
charset.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code, released
00015  * March 31, 1998.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 /*
00038  *  Copyright (c) 1995 Regents of the University of Michigan.
00039  *  All rights reserved.
00040  */
00041 /*
00042  *  charset.c
00043  */
00044 
00045 #include "ldap-int.h"
00046 
00047 #ifdef STR_TRANSLATION
00048 
00049 void
00050 ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc,
00051        BERTranslateProc decode_proc )
00052 {
00053        if ( ld == NULL ) {
00054               if ( !nsldapi_initialized ) {
00055                      nsldapi_initialize_defaults();
00056               }
00057               ld = &nsldapi_ld_defaults;
00058        }
00059 
00060        if ( NSLDAPI_VALID_LDAP_POINTER( ld )) {
00061               ld->ld_lber_encode_translate_proc = encode_proc;
00062               ld->ld_lber_decode_translate_proc = decode_proc;
00063        }
00064 }
00065 
00066 
00067 void
00068 ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
00069 {
00070        char   *optionsp;
00071 
00072        if ( ld == NULL ) {
00073               if ( !nsldapi_initialized ) {
00074                      nsldapi_initialize_defaults();
00075               }
00076               ld = &nsldapi_ld_defaults;
00077        }
00078 
00079        optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions :
00080            &entry->lm_ber->ber_options;
00081               
00082        if ( enable ) {
00083               *optionsp |= LBER_OPT_TRANSLATE_STRINGS;
00084        } else {
00085               *optionsp &= ~LBER_OPT_TRANSLATE_STRINGS;
00086        }
00087 }
00088 
00089 
00090 int
00091 ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
00092     int free_input )
00093 {
00094        if ( ld->ld_lber_decode_translate_proc == NULL ) {
00095               return( LDAP_SUCCESS );
00096        }
00097            
00098        return( (*ld->ld_lber_decode_translate_proc)( bufp, lenp, free_input ));
00099 }
00100 
00101 
00102 int
00103 ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
00104     int free_input )
00105 {
00106        if ( ld->ld_lber_encode_translate_proc == NULL ) {
00107               return( LDAP_SUCCESS );
00108        }
00109            
00110        return( (*ld->ld_lber_encode_translate_proc)( bufp, lenp, free_input ));
00111 }
00112 
00113 
00114 /*
00115  ** Character translation routine notes:
00116  *
00117  * On entry:  bufp points to a "string" to be converted (not necessarily
00118  *  zero-terminated) and buflenp points to the length of the buffer.
00119  *
00120  * On exit:  bufp should point to a malloc'd result.  If free_input is
00121  *  non-zero then the original bufp will be freed.  *buflenp should be
00122  *  set to the new length.  Zero bytes in the input buffer must be left
00123  *  as zero bytes.
00124  *
00125  * Return values: any ldap error code (LDAP_SUCCESS if all goes well).
00126  */
00127 
00128 
00129 #ifdef LDAP_CHARSET_8859
00130 
00131 #if LDAP_CHARSET_8859 == 88591
00132 #define ISO_8859 1
00133 #elif LDAP_CHARSET_8859 == 88592
00134 #define ISO_8859 2
00135 #elif LDAP_CHARSET_8859 == 88593
00136 #define ISO_8859 3
00137 #elif LDAP_CHARSET_8859 == 88594
00138 #define ISO_8859 4
00139 #elif LDAP_CHARSET_8859 == 88595
00140 #define ISO_8859 5
00141 #elif LDAP_CHARSET_8859 == 88596
00142 #define ISO_8859 6
00143 #elif LDAP_CHARSET_8859 == 88597
00144 #define ISO_8859 7
00145 #elif LDAP_CHARSET_8859 == 88598
00146 #define ISO_8859 8
00147 #elif LDAP_CHARSET_8859 == 88599
00148 #define ISO_8859 9
00149 #elif LDAP_CHARSET_8859 == 885910
00150 #define ISO_8859 10
00151 #else
00152 #define ISO_8859 0
00153 #endif
00154 
00155 /*
00156  * the following ISO_8859 to/afrom T.61 character set translation code is
00157  * based on the code found in Enrique Silvestre Mora's iso-t61.c, found
00158  * as part of this package:
00159  *   ftp://pereiii.uji.es/pub/uji-ftp/unix/ldap/iso-t61.translation.tar.Z
00160  * Enrique is now (10/95) at this address: enrique.silvestre@uv.es
00161  *
00162  * changes made by mcs@umich.edu 12 October 1995:
00163  *   Change calling conventions of iso8859_t61() and t61_iso8859() to
00164  *     match libldap conventions; rename to ldap_8859_to_t61() and
00165  *     ldap_t61_to_8859().
00166  *   Change conversion routines to deal with non-zero terminated strings.
00167  *   ANSI-ize functions and include prototypes.
00168  */
00169 
00170 /* iso-t61.c - ISO-T61 translation routines (version: 0.2.1, July-1994) */
00171 /*
00172  * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain.
00173  * All rights reserved.
00174  *
00175  * Redistribution and use in source and binary forms are permitted
00176  * provided that this notice is preserved and that due credit is given
00177  * to the Universitat Jaume I. The name of the University
00178  * may not be used to endorse or promote products derived from this
00179  * software without specific prior written permission. This software
00180  * is provided ``as is'' without express or implied warranty.
00181 */
00182 
00183 
00184 #include <stdio.h>
00185 #include <stdlib.h>
00186 #include <string.h>
00187 
00188 /* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */
00189 /* #define  ISO_8859      1 */
00190 
00191 #ifndef ISO_8859
00192 #  define ISO_8859     0
00193 #endif
00194 
00195 typedef unsigned char  Byte;
00196 typedef struct { Byte  a, b; } Couple;
00197 
00198 #ifdef NEEDPROTOS
00199 static Byte *c_to_hh( Byte *o, Byte c );
00200 static Byte *c_to_cc( Byte *o, Couple *cc, Byte c );
00201 static int hh_to_c( Byte *h );
00202 static Byte *cc_to_t61( Byte *o, Byte *s );
00203 #else /* NEEDPROTOS */
00204 static Byte *c_to_hh();
00205 static Byte *c_to_cc();
00206 static int hh_to_c();
00207 static Byte *cc_to_t61();
00208 #endif /* NEEDPROTOS */
00209 
00210 /*
00211    Character choosed as base in diacritics alone: NO-BREAK SPACE.
00212    (The standard say it must be a blank space, 0x20.)
00213 */
00214 #define  ALONE  0xA0
00215 
00216 static Couple diacritic[16] = {
00217 #if (ISO_8859 == 1) || (ISO_8859 == 9)
00218        {0,0},       {'`',0},     {0xb4,0},    {'^',0},
00219        {'~',0},     {0xaf,0},    {'(',ALONE}, {'.',ALONE},
00220        {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
00221        {0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE},
00222 #elif (ISO_8859 == 2)
00223        {0,0},       {'`',0},     {0xb4,0},    {'^',0},
00224        {'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
00225        {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
00226        {0,0},       {0xbd,0},    {0xb2,0},    {0xb7,0}
00227 #elif (ISO_8859 == 3)
00228        {0,0},       {'`',0},     {0xb4,0},    {'^',0},
00229        {'~',0},     {'-',ALONE}, {0xa2,0},    {0xff,0},
00230        {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
00231        {0,0},       {'"',ALONE}, {';',ALONE}, {'<',ALONE}
00232 #elif (ISO_8859 == 4)
00233        {0,0},       {'`',0},     {0xb4,0},    {'^',0},
00234        {'~',0},     {0xaf,0},    {'(',ALONE}, {0xff,0},
00235        {0xa8,0},    {0,0},       {'0',ALONE}, {0xb8,0},
00236        {0,0},       {'"',ALONE}, {0xb2,0},    {0xb7,0}
00237 #else
00238        {0,0},       {'`',0},     {'\'',ALONE}, {'^',0},
00239        {'~',0},     {'-',ALONE}, {'(',ALONE},  {'.',ALONE},
00240        {':',ALONE}, {0,0},       {'0',ALONE},  {',',ALONE},
00241        {0,0},       {'"',ALONE}, {';',ALONE},  {'<',ALONE}
00242 #endif
00243 };
00244 
00245 /*
00246    --- T.61 (T.51) letters with diacritics: conversion to ISO 8859-n -----
00247        A,   C,   D,   E,   G,   H,   I,   J,   K,
00248        L,   N,   O,   R,   S,   T,   U,   W,   Y,   Z.
00249    -----------------------------------------------------------------------
00250 */
00251 static int letter_w_diacritic[16][38] = {
00252 #if (ISO_8859 == 1)
00253        0,   0,   0,   0,   0,   0,   0,   0,   0,
00254        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00255        0,   0,   0,   0,   0,   0,   0,   0,   0,
00256        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00257        0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
00258        0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
00259        0xe0,0,   0,   0xe8,0,   0,   0xec,0,   0,
00260        0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
00261        0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
00262        -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   0xdd,-1,
00263        0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
00264        -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   0xfd,-1,
00265        0xc2,-1,  0,   0xca,-1,  -1,  0xce,-1,  0,
00266        0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
00267        0xe2,-1,  0,   0xea,-1,  -1,  0xee,-1,  0,
00268        0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
00269        0xc3,0,   0,   0,   0,   0,   -1,  0,   0,
00270        0,   0xd1,0xd5,0,   0,   0,   -1,  0,   0,   0,
00271        0xe3,0,   0,   0,   0,   0,   -1,  0,   0,
00272        0,   0xf1,0xf5,0,   0,   0,   -1,  0,   0,   0,
00273        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00274        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00275        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00276        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00277        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00278        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00279        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00280        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00281        0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
00282        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00283        0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
00284        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00285        0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
00286        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00287        0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
00288        0,   0,   0xf6,0,   0,   0,   0xfc,0,   0xff,0,
00289        0,   0,   0,   0,   0,   0,   0,   0,   0,
00290        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00291        0,   0,   0,   0,   0,   0,   0,   0,   0,
00292        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00293        0xc5,0,   0,   0,   0,   0,   0,   0,   0,
00294        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00295        0xe5,0,   0,   0,   0,   0,   0,   0,   0,
00296        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00297        0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
00298        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
00299        0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
00300        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
00301        0,   0,   0,   0,   0,   0,   0,   0,   0,
00302        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00303        0,   0,   0,   0,   0,   0,   0,   0,   0,
00304        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00305        0,   0,   0,   0,   0,   0,   0,   0,   0,
00306        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00307        0,   0,   0,   0,   0,   0,   0,   0,   0,
00308        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00309        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00310        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00311        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00312        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00313        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00314        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
00315        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00316        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
00317 #elif (ISO_8859 == 2)
00318        0,   0,   0,   0,   0,   0,   0,   0,   0,
00319        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00320        0,   0,   0,   0,   0,   0,   0,   0,   0,
00321        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00322        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00323        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00324        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00325        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00326        0xc1,0xc6,0,   0xc9,0,   0,   0xcd,0,   0,
00327        0xc5,0xd1,0xd3,0xc0,0xa6,0,   0xda,0,   0xdd,0xac,
00328        0xe1,0xe6,0,   0xe9,0,   0,   0xed,0,   0,
00329        0xe5,0xf1,0xf3,0xe0,0xb6,0,   0xfa,0,   0xfd,0xbc,
00330        0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
00331        0,   0,   0xd4,0,   -1,  0,   -1,  -1,  -1,  0,
00332        0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
00333        0,   0,   0xf4,0,   -1,  0,   -1,  -1,  -1,  0,
00334        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00335        0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
00336        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00337        0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
00338        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00339        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00340        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00341        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00342        0xc3,0,   0,   0,   -1,  0,   0,   0,   0,
00343        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00344        0xe3,0,   0,   0,   -1,  0,   0,   0,   0,
00345        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00346        0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
00347        0,   0,   0,   0,   0,   0,   0,   0,   0,   0xaf,
00348        0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
00349        0,   0,   0,   0,   0,   0,   0,   0,   0,   0xbf,
00350        0xc4,0,   0,   0xcb,0,   0,   -1,  0,   0,
00351        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00352        0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
00353        0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
00354        0,   0,   0,   0,   0,   0,   0,   0,   0,
00355        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00356        0,   0,   0,   0,   0,   0,   0,   0,   0,
00357        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00358        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00359        0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
00360        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00361        0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
00362        0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
00363        -1,  -1,  0,   -1,  0xaa,0xde,0,   0,   0,   0,
00364        0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
00365        -1,  -1,  0,   -1,  0xba,0xfe,0,   0,   0,   0,
00366        0,   0,   0,   0,   0,   0,   0,   0,   0,
00367        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00368        0,   0,   0,   0,   0,   0,   0,   0,   0,
00369        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00370        0,   0,   0,   0,   0,   0,   0,   0,   0,
00371        0,   0,   0xd5,0,   0,   0,   0xdb,0,   0,   0,
00372        0,   0,   0,   0,   0,   0,   0,   0,   0,
00373        0,   0,   0xf5,0,   0,   0,   0xfb,0,   0,   0,
00374        0xa1,0,   0,   0xca,0,   0,   -1,  0,   0,
00375        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00376        0xb1,0,   0,   0xea,0,   0,   -1,  0,   0,
00377        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00378        0,   0xc8,0xcf,0xcc,0,   0,   0,   0,   0,
00379        0xa5,0xd2,0,   0xd8,0xa9,0xab,0,   0,   0,   0xae,
00380        0,   0xe8,0xef,0xec,0,   0,   0,   0,   0,
00381        0xb5,0xf2,0,   0xf8,0xb9,0xbb,0,   0,   0,   0xbe
00382 #elif (ISO_8859 == 3)
00383        0,   0,   0,   0,   0,   0,   0,   0,   0,
00384        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00385        0,   0,   0,   0,   0,   0,   0,   0,   0,
00386        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00387        0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
00388        0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
00389        0xe0,0,   0,   0xe8,0,   0,   0xec,0,   0,
00390        0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
00391        0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
00392        -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   -1,  -1,
00393        0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
00394        -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   -1,  -1,
00395        0xc2,0xc6,0,   0xca,0xd8,0xa6,0xce,0xac,0,
00396        0,   0,   0xd4,0,   0xde,0,   0xdb,-1,  -1,  0,
00397        0xe2,0xe6,0,   0xea,0xf8,0xb6,0xee,0xbc,0,
00398        0,   0,   0xf4,0,   0xfe,0,   0xfb,-1,  -1,  0,
00399        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00400        0,   0xd1,-1,  0,   0,   0,   -1,  0,   0,   0,
00401        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00402        0,   0xf1,-1,  0,   0,   0,   -1,  0,   0,   0,
00403        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00404        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00405        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00406        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00407        -1,  0,   0,   0,   0xab,0,   0,   0,   0,
00408        0,   0,   0,   0,   0,   0,   0xdd,0,   0,   0,
00409        -1,  0,   0,   0,   0xbb,0,   0,   0,   0,
00410        0,   0,   0,   0,   0,   0,   0xfd,0,   0,   0,
00411        0,   0xc5,0,   -1,  0xd5,0,   0xa9,0,   0,
00412        0,   0,   0,   0,   0,   0,   0,   0,   0,   0xaf,
00413        0,   0xe5,0,   -1,  0xf5,0,   0,   0,   0,
00414        0,   0,   0,   0,   0,   0,   0,   0,   0,   0xbf,
00415        0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
00416        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00417        0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
00418        0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
00419        0,   0,   0,   0,   0,   0,   0,   0,   0,
00420        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00421        0,   0,   0,   0,   0,   0,   0,   0,   0,
00422        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00423        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00424        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00425        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00426        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00427        0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
00428        -1,  -1,  0,   -1,  0xaa,-1,  0,   0,   0,   0,
00429        0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
00430        -1,  -1,  0,   -1,  0xba,-1,  0,   0,   0,   0,
00431        0,   0,   0,   0,   0,   0,   0,   0,   0,
00432        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00433        0,   0,   0,   0,   0,   0,   0,   0,   0,
00434        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00435        0,   0,   0,   0,   0,   0,   0,   0,   0,
00436        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00437        0,   0,   0,   0,   0,   0,   0,   0,   0,
00438        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00439        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00440        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00441        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00442        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00443        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00444        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
00445        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00446        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
00447 #elif (ISO_8859 == 4)
00448        0,   0,   0,   0,   0,   0,   0,   0,   0,
00449        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00450        0,   0,   0,   0,   0,   0,   0,   0,   0,
00451        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00452        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00453        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00454        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00455        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00456        0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
00457        -1,  -1,  -1,  -1,  -1,  0,   0xda,0,   -1,  -1,
00458        0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
00459        -1,  -1,  -1,  -1,  -1,  0,   0xfa,0,   -1,  -1,
00460        0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
00461        0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
00462        0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
00463        0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
00464        0xc3,0,   0,   0,   0,   0,   0xa5,0,   0,
00465        0,   -1,  0xd5,0,   0,   0,   0xdd,0,   0,   0,
00466        0xe3,0,   0,   0,   0,   0,   0xb5,0,   0,
00467        0,   -1,  0xf5,0,   0,   0,   0xfd,0,   0,   0,
00468        0xc0,0,   0,   0xaa,0,   0,   0xcf,0,   0,
00469        0,   0,   0xd2,0,   0,   0,   0xde,0,   0,   0,
00470        0xe0,0,   0,   0xba,0,   0,   0xef,0,   0,
00471        0,   0,   0xf2,0,   0,   0,   0xfe,0,   0,   0,
00472        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00473        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00474        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00475        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00476        0,   -1,  0,   0xcc,-1,  0,   -1,  0,   0,
00477        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00478        0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
00479        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00480        0xc4,0,   0,   0xcb,0,   0,   -1,  0,   0,
00481        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00482        0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
00483        0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
00484        0,   0,   0,   0,   0,   0,   0,   0,   0,
00485        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00486        0,   0,   0,   0,   0,   0,   0,   0,   0,
00487        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00488        0xc5,0,   0,   0,   0,   0,   0,   0,   0,
00489        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00490        0xe5,0,   0,   0,   0,   0,   0,   0,   0,
00491        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00492        0,   -1,  0,   0,   0xab,0,   0,   0,   0xd3,
00493        0xa6,0xd1,0,   0xa3,-1,  -1,  0,   0,   0,   0,
00494        0,   -1,  0,   0,   0xbb,0,   0,   0,   0xf3,
00495        0xb6,0xf1,0,   0xb3,-1,  -1,  0,   0,   0,   0,
00496        0,   0,   0,   0,   0,   0,   0,   0,   0,
00497        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00498        0,   0,   0,   0,   0,   0,   0,   0,   0,
00499        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00500        0,   0,   0,   0,   0,   0,   0,   0,   0,
00501        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00502        0,   0,   0,   0,   0,   0,   0,   0,   0,
00503        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00504        0xa1,0,   0,   0xca,0,   0,   0xc7,0,   0,
00505        0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
00506        0xb1,0,   0,   0xea,0,   0,   0xe7,0,   0,
00507        0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
00508        0,   0xc8,-1,  -1,  0,   0,   0,   0,   0,
00509        -1,  -1,  0,   -1,  0xa9,-1,  0,   0,   0,   0xae,
00510        0,   0xe8,-1,  -1,  0,   0,   0,   0,   0,
00511        -1,  -1,  0,   -1,  0xb9,-1,  0,   0,   0,   0xbe
00512 #elif (ISO_8859 == 9)
00513        0,   0,   0,   0,   0,   0,   0,   0,   0,
00514        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00515        0,   0,   0,   0,   0,   0,   0,   0,   0,
00516        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00517        0xc0,0,   0,   0xc8,0,   0,   0xcc,0,   0,
00518        0,   0,   0xd2,0,   0,   0,   0xd9,0,   0,   0,
00519        0xe0,0,   0,   0xe8,0,   0,   -1,  0,   0,
00520        0,   0,   0xf2,0,   0,   0,   0xf9,0,   0,   0,
00521        0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
00522        -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   -1,  -1,
00523        0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
00524        -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   -1,  -1,
00525        0xc2,-1,  0,   0xca,-1,  -1,  0xce,-1,  0,
00526        0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
00527        0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
00528        0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
00529        0xc3,0,   0,   0,   0,   0,   -1,  0,   0,
00530        0,   0xd1,0xd5,0,   0,   0,   -1,  0,   0,   0,
00531        0xe3,0,   0,   0,   0,   0,   -1,  0,   0,
00532        0,   0xf1,0xf5,0,   0,   0,   -1,  0,   0,   0,
00533        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00534        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00535        -1,  0,   0,   -1,  0,   0,   0xef,0,   0,
00536        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00537        -1,  0,   0,   0,   0xd0,0,   0,   0,   0,
00538        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00539        -1,  0,   0,   0,   0xf0,0,   0,   0,   0,
00540        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00541        0,   -1,  0,   -1,  -1,  0,   0xdd,0,   0,
00542        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00543        0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
00544        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00545        0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
00546        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00547        0xe4,0,   0,   0xeb,0,   0,   -1,  0,   0,
00548        0,   0,   0xf6,0,   0,   0,   0xfc,0,   0xff,0,
00549        0,   0,   0,   0,   0,   0,   0,   0,   0,
00550        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00551        0,   0,   0,   0,   0,   0,   0,   0,   0,
00552        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00553        0xc5,0,   0,   0,   0,   0,   0,   0,   0,
00554        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00555        0xe5,0,   0,   0,   0,   0,   0,   0,   0,
00556        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00557        0,   0xc7,0,   0,   -1,  0,   0,   0,   -1,
00558        -1,  -1,  0,   -1,  0xde,-1,  0,   0,   0,   0,
00559        0,   0xe7,0,   0,   -1,  0,   0,   0,   -1,
00560        -1,  -1,  0,   -1,  0xfe,-1,  0,   0,   0,   0,
00561        0,   0,   0,   0,   0,   0,   0,   0,   0,
00562        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00563        0,   0,   0,   0,   0,   0,   0,   0,   0,
00564        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00565        0,   0,   0,   0,   0,   0,   0,   0,   0,
00566        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00567        0,   0,   0,   0,   0,   0,   0,   0,   0,
00568        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00569        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00570        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00571        -1,  0,   0,   0xea,0,   0,   -1,  0,   0,
00572        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00573        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00574        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
00575        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00576        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
00577 #elif (ISO_8859 == 10)
00578        0,   0,   0,   0,   0,   0,   0,   0,   0,
00579        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00580        0,   0,   0,   0,   0,   0,   0,   0,   0,
00581        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00582        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00583        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00584        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00585        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00586        0xc1,-1,  0,   0xc9,0,   0,   0xcd,0,   0,
00587        -1,  -1,  0xd3,-1,  -1,  0,   0xda,0,   0xdd,-1,
00588        0xe1,-1,  0,   0xe9,0,   0,   0xed,0,   0,
00589        -1,  -1,  0xf3,-1,  -1,  0,   0xfa,0,   0xfd,-1,
00590        0xc2,-1,  0,   -1,  -1,  -1,  0xce,-1,  0,
00591        0,   0,   0xd4,0,   -1,  0,   0xdb,-1,  -1,  0,
00592        0xe2,-1,  0,   -1,  -1,  -1,  0xee,-1,  0,
00593        0,   0,   0xf4,0,   -1,  0,   0xfb,-1,  -1,  0,
00594        0xc3,0,   0,   0,   0,   0,   0xa5,0,   0,
00595        0,   -1,  0xd5,0,   0,   0,   0xd7,0,   0,   0,
00596        0xe3,0,   0,   0,   0,   0,   0xb5,0,   0,
00597        0,   -1,  0xf5,0,   0,   0,   0xf7,0,   0,   0,
00598        0xc0,0,   0,   0xa2,0,   0,   0xa4,0,   0,
00599        0,   0,   0xd2,0,   0,   0,   0xae,0,   0,   0,
00600        0xe0,0,   0,   0xb2,0,   0,   0xb4,0,   0,
00601        0,   0,   0xf2,0,   0,   0,   0xbe,0,   0,   0,
00602        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00603        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00604        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00605        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00606        0,   -1,  0,   0xcc,-1,  0,   -1,  0,   0,
00607        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00608        0,   -1,  0,   0xec,-1,  0,   0,   0,   0,
00609        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00610        0xc4,0,   0,   0xcb,0,   0,   0xcf,0,   0,
00611        0,   0,   0xd6,0,   0,   0,   0xdc,0,   -1,  0,
00612        0xe4,0,   0,   0xeb,0,   0,   0xef,0,   0,
00613        0,   0,   0xf6,0,   0,   0,   0xfc,0,   -1,  0,
00614        0,   0,   0,   0,   0,   0,   0,   0,   0,
00615        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00616        0,   0,   0,   0,   0,   0,   0,   0,   0,
00617        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00618        0xc5,0,   0,   0,   0,   0,   0,   0,   0,
00619        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00620        0xe5,0,   0,   0,   0,   0,   0,   0,   0,
00621        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00622        0,   -1,  0,   0,   0xa3,0,   0,   0,   0xa6,
00623        0xa8,0xd1,0,   -1,  -1,  -1,  0,   0,   0,   0,
00624        0,   -1,  0,   0,   0xb3,0,   0,   0,   0xb6,
00625        0xb8,0xf1,0,   -1,  -1,  -1,  0,   0,   0,   0,
00626        0,   0,   0,   0,   0,   0,   0,   0,   0,
00627        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00628        0,   0,   0,   0,   0,   0,   0,   0,   0,
00629        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00630        0,   0,   0,   0,   0,   0,   0,   0,   0,
00631        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00632        0,   0,   0,   0,   0,   0,   0,   0,   0,
00633        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00634        0xa1,0,   0,   0xca,0,   0,   0xc7,0,   0,
00635        0,   0,   0,   0,   0,   0,   0xd9,0,   0,   0,
00636        0xb1,0,   0,   0xea,0,   0,   0xe7,0,   0,
00637        0,   0,   0,   0,   0,   0,   0xf9,0,   0,   0,
00638        0,   0xc8,-1,  -1,  0,   0,   0,   0,   0,
00639        -1,  -1,  0,   -1,  0xaa,-1,  0,   0,   0,   0xac,
00640        0,   0xe8,-1,  -1,  0,   0,   0,   0,   0,
00641        -1,  -1,  0,   -1,  0xba,-1,  0,   0,   0,   0xbc
00642 #else
00643        0,   0,   0,   0,   0,   0,   0,   0,   0,
00644        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00645        0,   0,   0,   0,   0,   0,   0,   0,   0,
00646        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00647        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00648        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00649        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00650        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00651        -1,  -1,  0,   -1,  0,   0,   -1,  0,   0,
00652        -1,  -1,  -1,  -1,  -1,  0,   -1,  0,   -1,  -1,
00653        -1,  -1,  0,   -1,  0,   0,   -1,  0,   0,
00654        -1,  -1,  -1,  -1,  -1,  0,   -1,  0,   -1,  -1,
00655        -1,  -1,  0,   -1,  -1,  -1,  -1,  -1,  0,
00656        0,   0,   -1,  0,   -1,  0,   -1,  -1,  -1,  0,
00657        -1,  -1,  0,   -1,  -1,  -1,  -1,  -1,  0,
00658        0,   0,   -1,  0,   -1,  0,   -1,  -1,  -1,  0,
00659        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00660        0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
00661        -1,  0,   0,   0,   0,   0,   -1,  0,   0,
00662        0,   -1,  -1,  0,   0,   0,   -1,  0,   0,   0,
00663        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00664        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00665        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00666        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00667        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00668        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00669        -1,  0,   0,   0,   -1,  0,   0,   0,   0,
00670        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00671        0,   -1,  0,   -1,  -1,  0,   -1,  0,   0,
00672        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00673        0,   -1,  0,   -1,  -1,  0,   0,   0,   0,
00674        0,   0,   0,   0,   0,   0,   0,   0,   0,   -1,
00675        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00676        0,   0,   -1,  0,   0,   0,   -1,  0,   -1,  0,
00677        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00678        0,   0,   -1,  0,   0,   0,   -1,  0,   -1,  0,
00679        0,   0,   0,   0,   0,   0,   0,   0,   0,
00680        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00681        0,   0,   0,   0,   0,   0,   0,   0,   0,
00682        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00683        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00684        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00685        -1,  0,   0,   0,   0,   0,   0,   0,   0,
00686        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00687        0,   -1,  0,   0,   -1,  0,   0,   0,   -1,
00688        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
00689        0,   -1,  0,   0,   -1,  0,   0,   0,   -1,
00690        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   0,
00691        0,   0,   0,   0,   0,   0,   0,   0,   0,
00692        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00693        0,   0,   0,   0,   0,   0,   0,   0,   0,
00694        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
00695        0,   0,   0,   0,   0,   0,   0,   0,   0,
00696        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00697        0,   0,   0,   0,   0,   0,   0,   0,   0,
00698        0,   0,   -1,  0,   0,   0,   -1,  0,   0,   0,
00699        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00700        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00701        -1,  0,   0,   -1,  0,   0,   -1,  0,   0,
00702        0,   0,   0,   0,   0,   0,   -1,  0,   0,   0,
00703        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00704        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1,
00705        0,   -1,  -1,  -1,  0,   0,   0,   0,   0,
00706        -1,  -1,  0,   -1,  -1,  -1,  0,   0,   0,   -1
00707 #endif
00708 };
00709 
00710 /*
00711 --- T.61 characters [0xA0 .. 0xBF] -----------------
00712 */
00713 static Couple trans_t61a_iso8859[32] = {
00714 #if (ISO_8859 == 1) || (ISO_8859 == 9)
00715        {'N','S'}, {0xa1,0},  {0xa2,0},  {0xa3,0},
00716        {'D','O'}, {0xa5,0},  {'C','u'}, {0xa7,0},
00717        {0xa4,0},  {'\'','6'},{'"','6'}, {0xab,0},
00718        {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
00719        {0xb0,0},  {0xb1,0},  {0xb2,0},  {0xb3,0},
00720        {0xd7,0},  {0xb5,0},  {0xb6,0},  {0xb7,0},
00721        {0xf7,0},  {'\'','9'},{'"','9'}, {0xbb,0},
00722        {0xbc,0},  {0xbd,0},  {0xbe,0},  {0xbf,0}
00723 #elif (ISO_8859 == 2) || (ISO_8859 == 4)
00724        {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
00725        {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
00726        {0xa4,0},  {'\'','6'},{'"','6'}, {'<','<'},
00727        {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
00728        {0xb0,0},  {'+','-'}, {'2','S'}, {'3','S'},
00729        {0xd7,0},  {'M','y'}, {'P','I'}, {'.','M'},
00730        {0xf7,0},  {'\'','9'},{'"','9'}, {'>','>'},
00731        {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'},
00732 #elif (ISO_8859 == 3)
00733        {'N','S'}, {'!','I'}, {'C','t'}, {0xa3,0},
00734        {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
00735        {0xa4,0},  {'\'','6'},{'"','6'}, {'<','<'},
00736        {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
00737        {0xb0,0},  {'+','-'}, {0xb2,0},  {0xb3,0},
00738        {0xd7,0},  {0xb5,0},  {'P','I'}, {0xb7,0},
00739        {0xf7,0},  {'\'','9'},{'"','9'}, {'>','>'},
00740        {'1','4'}, {0xbd,0},  {'3','4'}, {'?','I'}
00741 #elif (ISO_8859 == 10)
00742        {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
00743        {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0},
00744        {'C','u'}, {'\'','6'},{'"','6'}, {'<','<'},
00745        {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
00746        {0xb0,0},  {'+','-'}, {'2','S'}, {'3','S'},
00747        {'*','X'}, {'M','y'}, {'P','I'}, {0xb7,0},
00748        {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
00749        {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
00750 #else
00751        {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'},
00752        {'D','O'}, {'Y','e'}, {'C','u'}, {'S','E'},
00753        {'X','O'}, {'\'','6'},{'"','6'}, {'<','<'},
00754        {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'},
00755        {'D','G'}, {'+','-'}, {'2','S'}, {'3','S'},
00756        {'*','X'}, {'M','y'}, {'P','I'}, {'.','M'},
00757        {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'},
00758        {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}
00759 #endif
00760 };
00761 
00762 /*
00763 --- T.61 characters [0xE0 .. 0xFF] -----------------
00764 */
00765 static Couple trans_t61b_iso8859[48] = {
00766 #if (ISO_8859 == 1)
00767        {'-','M'}, {0xb9,0},  {0xae,0},  {0xa9,0},
00768        {'T','M'}, {'M','8'}, {0xac,0},  {0xa6,0},
00769        {0,0},     {0,0},     {0,0},     {0,0},
00770        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00771        {'O','m'}, {0xc6,0},  {0xd0,0},  {0xaa,0},
00772        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00773        {'L','/'}, {0xd8,0},  {'O','E'}, {0xba,0},
00774        {0xde,0},  {'T','/'}, {'N','G'}, {'\'','n'},
00775        {'k','k'}, {0xe6,0},  {'d','/'}, {0xf0,0},
00776        {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
00777        {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
00778        {0xfe,0},  {'t','/'}, {'n','g'}, {'-','-'}
00779 #elif (ISO_8859 == 2)
00780        {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
00781        {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
00782        {0,0},     {0,0},     {0,0},     {0,0},
00783        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00784        {'O','m'}, {'A','E'}, {0xd0,0},  {'-','a'},
00785        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00786        {0xa3,0},  {'O','/'}, {'O','E'}, {'-','o'},
00787        {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
00788        {'k','k'}, {'a','e'}, {0xf0,0},  {'d','-'},
00789        {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
00790        {0xb3,0},  {'o','/'}, {'o','e'}, {0xdf,0},
00791        {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
00792 #elif (ISO_8859 == 3)
00793        {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
00794        {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
00795        {0,0},     {0,0},     {0,0},     {0,0},
00796        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00797        {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
00798        {0xa1,0},  {0,0},     {'I','J'}, {'L','.'},
00799        {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
00800        {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
00801        {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
00802        {0xb1,0},  {0xb9,0},  {'i','j'}, {'l','.'},
00803        {'l','/'}, {'o','/'}, {'o','e'}, {0xdf,0},
00804        {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
00805 #elif (ISO_8859 == 4)
00806        {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
00807        {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
00808        {0,0},     {0,0},     {0,0},     {0,0},
00809        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00810        {'O','m'}, {0xc6,0},  {0xd0,0},  {'-','a'},
00811        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00812        {'L','/'}, {0xd8,0},  {'O','E'}, {'-','o'},
00813        {'T','H'}, {0xac,0},  {0xbd,0},  {'\'','n'},
00814        {0xa2,0},  {0xe6,0},  {0xf0,0},  {'d','-'},
00815        {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
00816        {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
00817        {'t','h'}, {0xbc,0},  {0xbf,0},  {'-','-'}
00818 #elif (ISO_8859 == 9)
00819        {'-','M'}, {0xb9,0},  {0xae,0},  {0xa9,0},
00820        {'T','M'}, {'M','8'}, {0xac,0},  {0xa6,0},
00821        {0,0},     {0,0},     {0,0},     {0,0},
00822        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00823        {'O','m'}, {0xc6,0},  {'D','/'}, {0xaa,0},
00824        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00825        {'L','/'}, {0xd8,0},  {'O','E'}, {0xba,0},
00826        {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
00827        {'k','k'}, {0xe6,0},  {'d','/'}, {'d','-'},
00828        {'h','/'}, {0xfd,0},  {'i','j'}, {'l','.'},
00829        {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
00830        {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'}
00831 #elif (ISO_8859 == 10)
00832        {0xbd,0},  {'1','S'}, {'R','g'}, {'C','o'},
00833        {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
00834        {0,0},     {0,0},     {0,0},     {0,0},
00835        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00836        {'O','m'}, {0xc6,0},  {0xa9,0},  {'-','a'},
00837        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00838        {'L','/'}, {0xd8,0},  {'O','E'}, {'-','o'},
00839        {0xde,0},  {0xab,0},  {0xaf,0},  {'\'','n'},
00840        {0xff,0},  {0xe6,0},  {0xb9,0},  {0xf0,0},
00841        {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
00842        {'l','/'}, {0xf8,0},  {'o','e'}, {0xdf,0},
00843        {0xfe,0},  {0xbb,0},  {0xbf,0},  {'-','-'}
00844 #else
00845        {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'},
00846        {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'},
00847        {0,0},     {0,0},     {0,0},     {0,0},
00848        {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'},
00849        {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'},
00850        {'H','/'}, {0,0},     {'I','J'}, {'L','.'},
00851        {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'},
00852        {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'},
00853        {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'},
00854        {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'},
00855        {'l','/'}, {'o','/'}, {'o','e'}, {'s','s'},
00856        {'t','h'}, {'t','-'}, {'n','g'}, {'-','-'}
00857 #endif
00858 };
00859 
00860 /*
00861 --- ISO 8859-n characters <0xA0 .. 0xFF> -------------------
00862 */
00863 #if (ISO_8859 == 1)
00864 static Couple trans_iso8859_t61[96] = {
00865        {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
00866        {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
00867        {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
00868        {0xd6,0},     {0xff,0},     {0xd2,0},     {0xc5,ALONE},
00869        {0xb0,0},     {0xb1,0},     {0xb2,0},     {0xb3,0},
00870        {0xc2,ALONE}, {0xb5,0},     {0xb6,0},     {0xb7,0},
00871        {0xcb,ALONE}, {0xd1,0},     {0xeb,0},     {0xbb,0},
00872        {0xbc,0},     {0xbd,0},     {0xbe,0},     {0xbf,0},
00873        {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
00874        {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xcb,'C'},
00875        {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
00876        {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
00877        {0xe2,0},     {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
00878        {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
00879        {0xe9,0},     {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
00880        {0xc8,'U'},   {0xc2,'Y'},   {0xec,0},     {0xfb,0},
00881        {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
00882        {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xcb,'c'},
00883        {0xc1,'e'},   {0xc2,'e'},   {0xc3,'e'},   {0xc8,'e'},
00884        {0xc1,'i'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
00885        {0xf3,0},     {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
00886        {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
00887        {0xf9,0},     {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
00888        {0xc8,'u'},   {0xc2,'y'},   {0xfc,0},     {0xc8,'y'}
00889 };
00890 #elif (ISO_8859 == 2)
00891 static Couple trans_iso8859_t61[96] = {
00892        {0xa0,0},     {0xce,'A'},   {0xc6,ALONE}, {0xe8,0},
00893        {0xa8,0},     {0xcf,'L'},   {0xc2,'S'},   {0xa7,0},
00894        {0xc8,ALONE}, {0xcf,'S'},   {0xcb,'S'},   {0xcf,'T'},
00895        {0xc2,'Z'},   {0xff,0},     {0xcf,'Z'},   {0xc7,'Z'},
00896        {0xb0,0},     {0xce,'a'},   {0xce,ALONE}, {0xf8,0},
00897        {0xc2,ALONE}, {0xcf,'l'},   {0xc2,'s'},   {0xcf,ALONE},
00898        {0xcb,ALONE}, {0xcf,'s'},   {0xcb,'s'},   {0xcf,'t'},
00899        {0xc2,'z'},   {0xcd,ALONE}, {0xcf,'z'},   {0xc7,'z'},
00900        {0xc2,'R'},   {0xc2,'A'},   {0xc3,'A'},   {0xc6,'A'},
00901        {0xc8,'A'},   {0xc2,'L'},   {0xc2,'C'},   {0xcb,'C'},
00902        {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
00903        {0xcf,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xcf,'D'},
00904        {0xe2,0},     {0xc2,'N'},   {0xcf,'N'},   {0xc2,'O'},
00905        {0xc3,'O'},   {0xcd,'O'},   {0xc8,'O'},   {0xb4,0},
00906        {0xcf,'R'},   {0xca,'U'},   {0xc2,'U'},   {0xcd,'U'},
00907        {0xc8,'U'},   {0xc2,'Y'},   {0xcb,'T'},   {0xfb,0},
00908        {0xc2,'r'},   {0xc2,'a'},   {0xc3,'a'},   {0xc6,'a'},
00909        {0xc8,'a'},   {0xc2,'l'},   {0xc2,'c'},   {0xcb,'c'},
00910        {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
00911        {0xcf,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xcf,'d'},
00912        {0xf2,0},     {0xc2,'n'},   {0xcf,'n'},   {0xc2,'o'},
00913        {0xc3,'o'},   {0xcd,'o'},   {0xc8,'o'},   {0xb8,0},
00914        {0xcf,'r'},   {0xca,'u'},   {0xc2,'u'},   {0xcd,'u'},
00915        {0xc8,'u'},   {0xc2,'y'},   {0xcb,'t'},   {0xc7,ALONE}
00916 };
00917 #elif (ISO_8859 == 3)
00918 static Couple trans_iso8859_t61[96] = {
00919        {0xa0,0},     {0xe4,0},     {0xc6,ALONE}, {0xa3,0},
00920        {0xa8,0},     {0,0},        {0xc3,'H'},   {0xa7,0},
00921        {0xc8,ALONE}, {0xc7,'I'},   {0xcb,'S'},   {0xc6,'G'},
00922        {0xc3,'J'},   {0xff,0},     {0,0},        {0xc7,'Z'},
00923        {0xb0,0},     {0xf4,0},     {0xb2,0},     {0xb3,0},
00924        {0xc2,ALONE}, {0xb5,0},     {0xc3,'h'},   {0xb7,0},
00925        {0xcb,ALONE}, {0xf5,0},     {0xcb,'s'},   {0xc6,'g'},
00926        {0xc3,'j'},   {0xbd,0},     {0,0},        {0xc7,'z'},
00927        {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0,0},
00928        {0xc8,'A'},   {0xc7,'C'},   {0xc3,'C'},   {0xcb,'C'},
00929        {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
00930        {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
00931        {0,0},        {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
00932        {0xc3,'O'},   {0xc7,'G'},   {0xc8,'O'},   {0xb4,0},
00933        {0xc3,'G'},   {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
00934        {0xc8,'U'},   {0xc6,'U'},   {0xc3,'S'},   {0xfb,0},
00935        {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0,0},
00936        {0xc8,'a'},   {0xc7,'c'},   {0xc3,'c'},   {0xcb,'c'},
00937        {0xc1,'e'},   {0xc2,'e'},   {0xc3,'e'},   {0xc8,'e'},
00938        {0xc1,'i'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
00939        {0,0},        {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
00940        {0xc3,'o'},   {0xc7,'g'},   {0xc8,'o'},   {0xb8,0},
00941        {0xc3,'g'},   {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
00942        {0xc8,'u'},   {0xc6,'u'},   {0xc3,'s'},   {0xc7,ALONE}
00943 };
00944 #elif (ISO_8859 == 4)
00945 static Couple trans_iso8859_t61[96] = {
00946        {0xa0,0},     {0xce,'A'},   {0xf0,0},     {0xcb,'R'},
00947        {0xa8,0},     {0xc4,'I'},   {0xcb,'L'},   {0xa7,0},
00948        {0xc8,ALONE}, {0xcf,'S'},   {0xc5,'E'},   {0xcb,'G'},
00949        {0xed,0},     {0xff,0},     {0xcf,'Z'},   {0xc5,ALONE},
00950        {0xb0,0},     {0xce,'a'},   {0xce,ALONE}, {0xcb,'r'},
00951        {0xc2,ALONE}, {0xc4,'i'},   {0xcb,'l'},   {0xcf,ALONE},
00952        {0xcb,ALONE}, {0xcf,'s'},   {0xc5,'e'},   {0xcb,'g'},
00953        {0xfd,0},     {0xee,0},     {0xcf,'z'},   {0xfe,0},
00954        {0xc5,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
00955        {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xce,'I'},
00956        {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
00957        {0xc7,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xc5,'I'},
00958        {0xe2,0},     {0xcb,'N'},   {0xc5,'O'},   {0xcb,'K'},
00959        {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
00960        {0xe9,0},     {0xce,'U'},   {0xc2,'U'},   {0xc3,'U'},
00961        {0xc8,'U'},   {0xc4,'U'},   {0xc5,'U'},   {0xfb,0},
00962        {0xc5,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
00963        {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xce,'i'},
00964        {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
00965        {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc5,'i'},
00966        {0xf2,0},     {0xcb,'n'},   {0xc5,'o'},   {0xcb,'k'},
00967        {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
00968        {0xf9,0},     {0xce,'u'},   {0xc2,'u'},   {0xc3,'u'},
00969        {0xc8,'u'},   {0xc4,'u'},   {0xc5,'u'},   {0xc7,ALONE}
00970 };
00971 #elif (ISO_8859 == 9)
00972 static Couple trans_iso8859_t61[96] = {
00973        {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
00974        {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
00975        {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
00976        {0xd6,0},     {0xff,0},     {0xd2,0},     {0xc5,ALONE},
00977        {0xb0,0},     {0xb1,0},     {0xb2,0},     {0xb3,0},
00978        {0xc2,ALONE}, {0xb5,0},     {0xb6,0},     {0xb7,0},
00979        {0xcb,ALONE}, {0xd1,0},     {0xeb,0},     {0xbb,0},
00980        {0xbc,0},     {0xbd,0},     {0xbe,0},     {0xbf,0},
00981        {0xc1,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
00982        {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xcb,'C'},
00983        {0xc1,'E'},   {0xc2,'E'},   {0xc3,'E'},   {0xc8,'E'},
00984        {0xc1,'I'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
00985        {0xc6,'G'},   {0xc4,'N'},   {0xc1,'O'},   {0xc2,'O'},
00986        {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xb4,0},
00987        {0xe9,0},     {0xc1,'U'},   {0xc2,'U'},   {0xc3,'U'},
00988        {0xc8,'U'},   {0xc7,'I'},   {0xcb,'S'},   {0xfb,0},
00989        {0xc1,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
00990        {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xcb,'c'},
00991        {0xc1,'e'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
00992        {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc5,'i'},
00993        {0xc6,'g'},   {0xc4,'n'},   {0xc1,'o'},   {0xc2,'o'},
00994        {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xb8,0},
00995        {0xf9,0},     {0xc1,'u'},   {0xc2,'u'},   {0xc3,'u'},
00996        {0xc8,'u'},   {0xf5,0},     {0xcb,'s'},   {0xc8,'y'}
00997 };
00998 #elif (ISO_8859 == 10)
00999 static Couple trans_iso8859_t61[96] = {
01000        {0xa0,0},     {0xce,'A'},   {0xc5,'E'},   {0xcb,'G'},
01001        {0xc5,'I'},   {0xc4,'I'},   {0xcb,'K'},   {0xa7,0},
01002        {0xcb,'L'},   {0xe2,0},     {0xcf,'S'},   {0xed,0},
01003        {0xcf,'Z'},   {0xff,0},     {0xc5,'U'},   {0xee,0},
01004        {0xb0,0},     {0xce,'a'},   {0xc5,'e'},   {0xcb,'g'},
01005        {0xc5,'i'},   {0xc4,'i'},   {0xcb,'k'},   {0xb7,0},
01006        {0xcb,'l'},   {0xf2,0},     {0xcf,'s'},   {0xfd,0},
01007        {0xcf,'z'},   {0xd0,0},     {0xc5,'u'},   {0xfe,0},
01008        {0xc5,'A'},   {0xc2,'A'},   {0xc3,'A'},   {0xc4,'A'},
01009        {0xc8,'A'},   {0xca,'A'},   {0xe1,0},     {0xce,'I'},
01010        {0xcf,'C'},   {0xc2,'E'},   {0xce,'E'},   {0xc8,'E'},
01011        {0xc7,'E'},   {0xc2,'I'},   {0xc3,'I'},   {0xc8,'I'},
01012        {0,0},        {0xcb,'N'},   {0xc5,'O'},   {0xc2,'O'},
01013        {0xc3,'O'},   {0xc4,'O'},   {0xc8,'O'},   {0xc4,'U'},
01014        {0xe9,0},     {0xce,'U'},   {0xc2,'U'},   {0xc3,'U'},
01015        {0xc8,'U'},   {0xc2,'Y'},   {0xec,0},     {0xfb,0},
01016        {0xc5,'a'},   {0xc2,'a'},   {0xc3,'a'},   {0xc4,'a'},
01017        {0xc8,'a'},   {0xca,'a'},   {0xf1,0},     {0xce,'i'},
01018        {0xcf,'c'},   {0xc2,'e'},   {0xce,'e'},   {0xc8,'e'},
01019        {0xc7,'e'},   {0xc2,'i'},   {0xc3,'i'},   {0xc8,'i'},
01020        {0xf3,0},     {0xcb,'n'},   {0xc5,'o'},   {0xc2,'o'},
01021        {0xc3,'o'},   {0xc4,'o'},   {0xc8,'o'},   {0xc4,'u'},
01022        {0xf9,0},     {0xce,'u'},   {0xc2,'u'},   {0xc3,'u'},
01023        {0xc8,'u'},   {0xc2,'y'},   {0xfc,0},     {0xf0,0}
01024 };
01025 #endif
01026 
01027 
01028 static Byte *
01029 c_to_hh( Byte *o, Byte c )
01030 {
01031   Byte n;
01032 
01033   *o++ = '{'; *o++ = 'x';
01034   n = c >> 4;
01035   *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
01036   n = c & 0x0F;
01037   *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
01038   *o++ = '}';
01039   return o;
01040 }
01041 
01042 
01043 static Byte *
01044 c_to_cc( Byte *o, Couple *cc, Byte c )
01045 {
01046   if ( (*cc).a != 0 ) {
01047     if ( (*cc).b == 0 )
01048       *o++ = (*cc).a;
01049     else {
01050       *o++ = '{';
01051       *o++ = (*cc).a;
01052       *o++ = (*cc).b;
01053       *o++ = '}';
01054     }
01055     return o;
01056   }
01057   else
01058     return c_to_hh( o, c );
01059 }
01060 
01061 /* --- routine to convert from T.61 to ISO 8859-n --- */
01062 
01063 int
01064 ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
01065 {
01066   Byte        *s, *oo, *o;
01067   unsigned int  n;
01068   int           c;
01069   unsigned long len;
01070   Couple        *cc;
01071 
01072   LDAPDebug( LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n",
01073        *buflenp, 0, 0 );
01074 
01075   len = *buflenp;
01076   s = (Byte *) *bufp;
01077 
01078   if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * len + 64 )) == NULL ) {
01079         return( 1 );
01080   }
01081 
01082   while ( (char *)s - *(char **)bufp < len ) {
01083     switch ( *s >> 4 ) {
01084 
01085     case 0xA: case 0xB:
01086       o = c_to_cc( o, &trans_t61a_iso8859[ *s - 0xA0 ], *s );
01087       s++;
01088       break;
01089 
01090     case 0xD: case 0xE: case 0xF:
01091       o = c_to_cc( o, &trans_t61b_iso8859[ *s - 0xD0 ], *s );
01092       s++;
01093       break;
01094 
01095     case 0xC:
01096       if ( (*s == 0xC0) || (*s == 0xC9) || (*s == 0xCC) ) {
01097         o = c_to_hh( o, *s++ );
01098         break;
01099       }
01100 
01101       n = (*s++) - 0xC0;
01102       switch ( *s ) {
01103 
01104       case 'A':  c = letter_w_diacritic[n][0]; break;
01105       case 'C':  c = letter_w_diacritic[n][1]; break;
01106       case 'D':  c = letter_w_diacritic[n][2]; break;
01107       case 'E':  c = letter_w_diacritic[n][3]; break;
01108       case 'G':  c = letter_w_diacritic[n][4]; break;
01109       case 'H':  c = letter_w_diacritic[n][5]; break;
01110       case 'I':  c = letter_w_diacritic[n][6]; break;
01111       case 'J':  c = letter_w_diacritic[n][7]; break;
01112       case 'K':  c = letter_w_diacritic[n][8]; break;
01113       case 'L':  c = letter_w_diacritic[n][9]; break;
01114       case 'N':  c = letter_w_diacritic[n][10]; break;
01115       case 'O':  c = letter_w_diacritic[n][11]; break;
01116       case 'R':  c = letter_w_diacritic[n][12]; break;
01117       case 'S':  c = letter_w_diacritic[n][13]; break;
01118       case 'T':  c = letter_w_diacritic[n][14]; break;
01119       case 'U':  c = letter_w_diacritic[n][15]; break;
01120       case 'W':  c = letter_w_diacritic[n][16]; break;
01121       case 'Y':  c = letter_w_diacritic[n][17]; break;
01122       case 'Z':  c = letter_w_diacritic[n][18]; break;
01123 
01124       case 'a':  c = letter_w_diacritic[n][19]; break;
01125       case 'c':  c = letter_w_diacritic[n][20]; break;
01126       case 'd':  c = letter_w_diacritic[n][21]; break;
01127       case 'e':  c = letter_w_diacritic[n][22]; break;
01128       case 'g':  c = letter_w_diacritic[n][23]; break;
01129       case 'h':  c = letter_w_diacritic[n][24]; break;
01130       case 'i':  c = letter_w_diacritic[n][25]; break;
01131       case 'j':  c = letter_w_diacritic[n][26]; break;
01132       case 'k':  c = letter_w_diacritic[n][27]; break;
01133       case 'l':  c = letter_w_diacritic[n][28]; break;
01134       case 'n':  c = letter_w_diacritic[n][29]; break;
01135       case 'o':  c = letter_w_diacritic[n][30]; break;
01136       case 'r':  c = letter_w_diacritic[n][31]; break;
01137       case 's':  c = letter_w_diacritic[n][32]; break;
01138       case 't':  c = letter_w_diacritic[n][33]; break;
01139       case 'u':  c = letter_w_diacritic[n][34]; break;
01140       case 'w':  c = letter_w_diacritic[n][35]; break;
01141       case 'y':  c = letter_w_diacritic[n][36]; break;
01142       case 'z':  c = letter_w_diacritic[n][37]; break;
01143 
01144       case ALONE:  c = (( !diacritic[n].b ) ? diacritic[n].a : -1);
01145                    break;
01146 
01147       default:   c = 0;
01148       }
01149 
01150       if ( c > 0 ) {
01151         *o++ = c;  s++;
01152       } else {
01153         *o++ = '{';
01154         if ( c == -1 ) {
01155           *o++ = ( ( *s == ALONE ) ? ' ' : *s );
01156           s++;
01157         } else {
01158           *o++ = '"';
01159         }
01160         *o++ = diacritic[n].a;
01161         *o++ = '}';
01162       }
01163       break;
01164 
01165 #if (ISO_8859 == 0)
01166     case 0x8: case 0x9:
01167       *o++ = 0x1B; /* <ESC> */
01168       *o++ = *s++ - 0x40;
01169       break;
01170 #endif
01171 
01172       default:
01173         *o++ = *s++;
01174     }
01175   }
01176 
01177   len = o - oo;
01178   o = oo;
01179 
01180   if ( (oo = (Byte *)NSLDAPI_REALLOC( o, len )) == NULL ) {
01181     NSLDAPI_FREE( o );
01182     return( 1 );
01183   }
01184 
01185   if ( free_input ) {
01186     NSLDAPI_FREE( *bufp );
01187   }
01188   *bufp = (char *) oo;
01189   *buflenp = len;
01190   return( 0 );
01191 }
01192 
01193 
01194 static int
01195 hh_to_c( Byte *h )
01196 {
01197   Byte c;
01198 
01199   if ( (*h >= '0') && (*h <= '9') )      c = *h++ - '0';
01200   else if ( (*h >= 'A') && (*h <= 'F') ) c = *h++ - 'A' + 10;
01201   else if ( (*h >= 'a') && (*h <= 'f') ) c = *h++ - 'a' + 10;
01202   else return -1;
01203 
01204   c <<= 4;
01205 
01206   if ( (*h >= '0') && (*h <= '9') )      c |= *h - '0';
01207   else if ( (*h >= 'A') && (*h <= 'F') ) c |= *h - 'A' + 10;
01208   else if ( (*h >= 'a') && (*h <= 'f') ) c |= *h - 'a' + 10;
01209   else return -1;
01210 
01211   return c;
01212 }
01213 
01214 
01215 static Byte *
01216 cc_to_t61( Byte *o, Byte *s )
01217 {
01218   int n, c = 0;
01219 
01220   switch ( *(s + 1) ) {
01221 
01222   case '`':  c = -1;   break;    /* <grave-accent> */
01223 
01224   case '!':
01225     switch ( *s ) {
01226     case '!':  c = 0x7C;  break;  /* <vertical-line> */
01227     case '(':  c = 0x7B;  break;  /* <left-curly-bracket> */
01228     case '-':  c = 0xAD;  break;  /* <upwards-arrow> */
01229     default:   c = -1;            /* <grave-accent> */
01230     }
01231     break;
01232 
01233 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
01234     (ISO_8859 == 4) || (ISO_8859 == 9)
01235   case 0xB4:
01236 #endif
01237   case '\'': c = -2;  break;    /* <acute-accent> */
01238 
01239   case '^':  c = -3;  break;    /* <circumflex-acent> */
01240 
01241   case '>':
01242     switch ( *s ) {
01243     case ')':  c = 0x5D;  break;  /* <right-square-bracket> */
01244     case '>':  c = 0xBB;  break;  /* <right-angle-quotation> */
01245     case '-':  c = 0xAE;  break;  /* <rightwards-arrow> */
01246     default:   c = -3;            /* <circumflex-acent> */
01247     }
01248     break;
01249 
01250   case '~':
01251   case '?':  c = -4;  break;        /* <tilde> */
01252 
01253 #if (ISO_8859 == 1) || (ISO_8859 == 4) || (ISO_8859 == 9)
01254   case 0xAF:  c = -5;  break;       /* <macron> */
01255 #endif
01256 
01257   case '-':
01258     switch ( *s ) {
01259     case '-':  c = 0xFF; break; /* <soft-hyphen> */
01260     case '<':  c = 0xAC; break; /* <leftwards arrow> */
01261     case '+':  c = 0xB1; break; /* <plus-minus> */
01262     case 'd':  c = 0xF3; break; /* <eth> */
01263     default:   c = -5;          /* <macron> */
01264     }
01265     break;
01266 
01267 #if (ISO_8859 == 2) || (ISO_8859 == 3)
01268   case 0xA2:  c = -6;  break;            /* <breve> */
01269 #endif
01270 
01271   case '(':
01272     if ( *s == '<' ) c = 0x5B;  /* <left-square-bracket> */
01273     else             c = -6;    /* <breve> */
01274     break;
01275 
01276 #if (ISO_8859 == 2) || (ISO_8859 == 3) || (ISO_8859 == 4)
01277   case 0xFF:  c = -7;  break;    /* <dot-accent> */
01278 #endif
01279 
01280   case '.':
01281     switch ( *s ) {
01282     case 'i':  c = 0xF5; break; /* <dotless-i> */
01283     case 'L':  c = 0xE7; break; /* <L-middle-dot> */
01284     case 'l':  c = 0xF7; break; /* <l-middle-dot> */
01285     default:   c = -7;          /* <dot-accent> */
01286     }
01287     break;
01288 
01289 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
01290     (ISO_8859 == 4) || (ISO_8859 == 9)
01291   case 0xA8:  c = -8; break; /* <diaeresis> */
01292 #endif
01293 
01294   case ':':
01295     if ( *s == '-')  c = 0xB8; /* <division-sign> */
01296     else             c = -8;   /* <diaeresis> */
01297     break;
01298 
01299 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
01300     (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
01301   case 0xB0:
01302 #endif
01303   case '0':  c = -10;  break;  /* <ring-above> */
01304 
01305 #if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
01306     (ISO_8859 == 4) || (ISO_8859 == 9)
01307   case 0xB8:
01308 #endif
01309   case ',':  c = -11; break; /* <cedilla> */
01310 
01311 #if (ISO_8859 == 2)
01312   case 0xBD:
01313 #endif
01314   case '"':  c = -13; break; /* <double-acute-accent> */
01315 
01316 #if (ISO_8859 == 2) || (ISO_8859 == 4)
01317   case 0xB2:
01318 #endif
01319   case ';':  c = -14; break; /* <ogonek> */
01320 
01321 #if (ISO_8859 == 2) || (ISO_8859 == 4)
01322   case 0xB7:  c = -15;  break;  /* <caron> */
01323 #endif
01324 
01325   case ')':
01326     if ( *s == '!' )  c = 0x7D;  /* <left-curly-bracket> */
01327     break;
01328 
01329   case '<':
01330     if ( *s == '<' )  c = 0xAB;  /* <left-angle-quotation> */
01331     else              c = -15;   /* <caron> */
01332     break;
01333 
01334   case '/':
01335     switch ( *s ) {
01336     case '/':  c = 0x5C; break; /* <reverse-solidus> */
01337     case 'D':  c = 0xE2; break; /* <D-stroke> */
01338     case 'd':  c = 0xF2; break; /* <d-stroke> */
01339     case 'H':  c = 0xE4; break; /* <H-stroke> */
01340     case 'h':  c = 0xF4; break; /* <h-stroke> */
01341     case 'L':  c = 0xE8; break; /* <L-stroke> */
01342     case 'l':  c = 0xF8; break; /* <l-stroke> */
01343     case 'O':  c = 0xE9; break; /* <O-stroke> */
01344     case 'o':  c = 0xF9; break; /* <o-stroke> */
01345     case 'T':  c = 0xED; break; /* <T-stroke> */
01346     case 't':  c = 0xFD; break; /* <t-stroke> */
01347     }
01348     break;
01349 
01350   case '2':
01351     if ( *s == '1' )  c = 0xBD;    /* <one-half> */
01352     break;
01353 
01354   case '4':
01355     switch ( *s ) {
01356     case '1':  c = 0xBC; break; /* <one-quarter> */
01357     case '3':  c = 0xBE; break; /* <three-quarters> */
01358     }
01359     break;
01360 
01361   case '6':
01362     switch ( *s ) {
01363     case '\'': c = 0xA9; break; /* <left-single-quotation> */
01364     case '"':  c = 0xAA; break; /* <left-double-quotation> */
01365     }
01366     break;
01367 
01368   case '8':
01369     switch ( *s ) {
01370     case '1':  c = 0xDC; break; /* <one-eighth> */
01371     case '3':  c = 0xDD; break; /* <three-eighths> */
01372     case '5':  c = 0xDE; break; /* <five-eighths> */
01373     case '7':  c = 0xDF; break; /* <seven-eighths> */
01374     case 'M':  c = 0xD5; break; /* <eighth-note> */
01375     }
01376     break;
01377 
01378   case '9':
01379     switch ( *s ) {
01380     case '\'': c = 0xB9; break; /* <right-single-quotation> */
01381     case '"':  c = 0xBA; break; /* <right-double-quotation> */
01382     }
01383     break;
01384 
01385   case 'A':
01386     if ( *s == 'A' )  c = -10;  /* <ring-above> + <A> */
01387     break;
01388 
01389   case 'a':
01390     switch ( *s ) {
01391     case '-':  c = 0xE3; break; /* <femenine-ordinal-a> */
01392     case 'a':  c = -10;  break; /* <ring-above> + <a> */
01393     }
01394     break;
01395 
01396   case 'B':
01397     if ( *s == 'B' )  c = 0xD7; /* <broken-bar> */
01398     break;
01399 
01400   case 'b':
01401     if ( *s == 'N' )  c = 0xA6;  /* <number-sign> */
01402     break;
01403 
01404   case 'd':
01405     if ( *s == 'P' )  c = 0xA3;  /* <pound-sign> */
01406     break;
01407 
01408   case 'E':
01409     switch ( *s ) {
01410     case 'S':  c = 0xA7; break; /* <section-sign> */
01411     case 'A':  c = 0xE1; break; /* <AE> */
01412     case 'O':  c = 0xEA; break; /* <OE> */
01413     }
01414     break;
01415 
01416   case 'e':
01417     switch ( *s ) {
01418     case 'a':  c = 0xF1; break; /* <ae> */
01419     case 'o':  c = 0xFA; break; /* <oe> */
01420     case 'Y':  c = 0xA5;  break;  /* <yen-sign> */
01421     }
01422     break;
01423 
01424   case 'G':
01425     switch ( *s ) {
01426     case 'D':  c = 0xB0; break; /* <degree-sign> */
01427     case 'N':  c = 0xEE; break; /* <Eng> */
01428     }
01429     break;
01430 
01431   case 'g':
01432     switch ( *s ) {
01433     case 'R':  c = 0xD2; break;  /* <registered-sign> */
01434     case 'n':  c = 0xFE; break; /* <eng> */
01435     }
01436     break;
01437 
01438   case 'H':
01439     if ( *s == 'T' )  c = 0xEC;  /* <Thorn> */
01440     break;
01441 
01442   case 'h':
01443     if ( *s == 't' )  c = 0xFC; /* <thorn> */
01444     break;
01445 
01446   case 'I':
01447     switch ( *s ) {
01448     case 'P':  c = 0xB6; break;  /* <pilcrow-sign> */
01449     case '!':  c = 0xA1; break; /* <inverted-exclamation> */
01450     case '?':  c = 0xBF; break; /* <inverted-question> */
01451     }
01452     break;
01453 
01454   case 'J':
01455     if ( *s == 'I' )  c = 0xE6; /* <IJ> */
01456     break;
01457 
01458   case 'j':
01459     if ( *s == 'i' )  c = 0xF6;  /* <ij> */
01460     break;
01461 
01462   case 'k':
01463     if ( *s == 'k' )  c = 0xF0; /* <kra> */
01464     break;
01465 
01466   case 'M':
01467     switch ( *s ) {
01468     case '.':  c = 0xB7; break; /* <middle-dot> */
01469     case '-':  c = 0xD0; break; /* <em-dash> */
01470     case 'T':  c = 0xD4; break; /* <trade-mark-sign> */
01471     }
01472     break;
01473 
01474   case 'm':
01475     switch ( *s ) {
01476     case '\'':                  /* <macron> RFC 1345 */
01477     case ' ':  c = -5;   break; /* <macron> */
01478     case 'O':  c = 0xE0; break; /* <Ohm sign> */
01479     }
01480     break;
01481 
01482   case 'n':
01483     if ( *s == '\'' )  c = 0xEF; /* <n-preceded-by-apostrophe> */
01484     break;
01485 
01486   case 'O':
01487     switch ( *s ) {
01488     case 'D':  c = 0xA4; break; /* <dollar-sign> */
01489     case 'N':  c = 0xD6; break; /* <not-sign> */
01490     }
01491     break;
01492 
01493   case 'o':
01494     switch ( *s ) {
01495     case 'C':  c = 0xD3; break; /* <copyright-sign> */
01496     case '-':  c = 0xEB; break; /* <masculine-ordinal-o> */
01497     }
01498     break;
01499 
01500   case 'S':
01501     switch ( *s ) {
01502     case '1':  c = 0xD1; break; /* <superscript-1> */
01503     case '2':  c = 0xB2; break; /* <superscript-2> */
01504     case '3':  c = 0xB3; break; /* <superscript-3> */
01505     case 'N':  c = 0xA0; break; /* <no-break-space> */
01506     }
01507     break;
01508 
01509   case 's':
01510     if ( *s == 's' )  c = 0xFB; /* <sharp-s> */
01511     break;
01512 
01513   case 't':
01514     if ( *s == 'C' )  c = 0xA2; /* <cent-sign> */
01515     break;
01516 
01517   case 'u':
01518     if ( *s == 'C' )  c = 0xA8; /* <currency-sign> */
01519     break;
01520 
01521   case 'v':
01522     if ( *s == '-' )  c = 0xAF; /* <downwards-arrow> */
01523     break;
01524 
01525   case 'X':
01526     if ( *s == '*' )  c = 0xB4; /* <multiplication-sign> */
01527     break;
01528 
01529   case 'y':
01530     if ( *s == 'M' )  c = 0xB5; /* <micro-sign> */
01531     break;
01532   }
01533 
01534   if ( c > 0 ) {
01535     *o++ = c;
01536     return o;
01537   } else if ( !c )
01538     return NULL;
01539 
01540   /* else: c < 0 */
01541   n = -c;
01542   switch ( *s ) {
01543 
01544   case 'A':  c = letter_w_diacritic[n][0]; break;
01545   case 'C':  c = letter_w_diacritic[n][1]; break;
01546   case 'D':  c = letter_w_diacritic[n][2]; break;
01547   case 'E':  c = letter_w_diacritic[n][3]; break;
01548   case 'G':  c = letter_w_diacritic[n][4]; break;
01549   case 'H':  c = letter_w_diacritic[n][5]; break;
01550   case 'I':  c = letter_w_diacritic[n][6]; break;
01551   case 'J':  c = letter_w_diacritic[n][7]; break;
01552   case 'K':  c = letter_w_diacritic[n][8]; break;
01553   case 'L':  c = letter_w_diacritic[n][9]; break;
01554   case 'N':  c = letter_w_diacritic[n][10]; break;
01555   case 'O':  c = letter_w_diacritic[n][11]; break;
01556   case 'R':  c = letter_w_diacritic[n][12]; break;
01557   case 'S':  c = letter_w_diacritic[n][13]; break;
01558   case 'T':  c = letter_w_diacritic[n][14]; break;
01559   case 'U':  c = letter_w_diacritic[n][15]; break;
01560   case 'W':  c = letter_w_diacritic[n][16]; break;
01561   case 'Y':  c = letter_w_diacritic[n][17]; break;
01562   case 'Z':  c = letter_w_diacritic[n][18]; break;
01563 
01564   case 'a':  c = letter_w_diacritic[n][19]; break;
01565   case 'c':  c = letter_w_diacritic[n][20]; break;
01566   case 'd':  c = letter_w_diacritic[n][21]; break;
01567   case 'e':  c = letter_w_diacritic[n][22]; break;
01568   case 'g':  c = letter_w_diacritic[n][23]; break;
01569   case 'h':  c = letter_w_diacritic[n][24]; break;
01570   case 'i':  c = letter_w_diacritic[n][25]; break;
01571   case 'j':  c = letter_w_diacritic[n][26]; break;
01572   case 'k':  c = letter_w_diacritic[n][27]; break;
01573   case 'l':  c = letter_w_diacritic[n][28]; break;
01574   case 'n':  c = letter_w_diacritic[n][29]; break;
01575   case 'o':  c = letter_w_diacritic[n][30]; break;
01576   case 'r':  c = letter_w_diacritic[n][31]; break;
01577   case 's':  c = letter_w_diacritic[n][32]; break;
01578   case 't':  c = letter_w_diacritic[n][33]; break;
01579   case 'u':  c = letter_w_diacritic[n][34]; break;
01580   case 'w':  c = letter_w_diacritic[n][35]; break;
01581   case 'y':  c = letter_w_diacritic[n][36]; break;
01582   case 'z':  c = letter_w_diacritic[n][37]; break;
01583 
01584   case '\'':
01585   case ' ':  c = -1; break;
01586 
01587   default:   c = 0;
01588   }
01589 
01590   if ( !c )
01591     return NULL;
01592 
01593   *o++ = n + 0xC0;
01594   *o++ = ( ( (*s == ' ') || (*s == '\'') ) ? ALONE : *s );
01595   return o;
01596 }
01597 
01598 
01599 /* --- routine to convert from ISO 8859-n to T.61 --- */
01600 
01601 int
01602 ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
01603 {
01604   Byte        *s, *oo, *o, *aux;
01605   int         c;
01606   unsigned long len; 
01607   Couple      *cc;
01608 
01609   LDAPDebug( LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n",
01610        *buflenp, 0, 0 );
01611 
01612   len = *buflenp;
01613   s = (Byte *) *bufp;
01614 
01615   if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * len + 64 )) == NULL ) {
01616         return( 1 );
01617   }
01618 
01619   while ( (char *)s - *(char **)bufp < len ) {
01620     switch( *s >> 5 ) {
01621 
01622     case 2:
01623       switch ( *s ) {
01624 
01625       case '^':  *o++ = 0xC3; *o++ = ALONE; s++; break;
01626 
01627       case '\\':
01628         s++;
01629         if ( (c = hh_to_c( s )) != -1 ) {
01630           *o++ = c;
01631           s += 2;
01632         } else
01633           *o++ = '\\';
01634         break;
01635 
01636       default:  *o++ = *s++;
01637       }
01638       break;
01639 
01640     case 3:
01641       switch ( *s ) {
01642 
01643       case '`':  *o++ = 0xC1; *o++ = ALONE; s++; break;
01644       case '~':  *o++ = 0xC4; *o++ = ALONE; s++; break;
01645 
01646       case '{':
01647         s++;
01648         if ( *(s + 2) == '}' ) {
01649           if ( (aux = cc_to_t61( o, s )) != NULL ) {
01650             o = aux;
01651             s += 3;
01652           } else {
01653             *o++ = '{';
01654           }
01655         } else if ( (*(s + 3) == '}') && ( (*s == 'x') || (*s == 'X') ) &&
01656                     ( (c = hh_to_c( s + 1 )) != -1 ) ) {
01657           *o++ = c;
01658           s += 4;
01659         } else {
01660           *o++ = '{';
01661         }
01662         break;
01663 
01664       default:
01665         *o++ = *s++;
01666       }
01667       break;
01668 
01669 #if (ISO_8859 == 0)
01670     case 4: case 5: case 6: case 7:
01671       s++;
01672       break;
01673 #else
01674     case 5: case 6: case 7:
01675 # if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \
01676      (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10)
01677       if ( (*(cc = &trans_iso8859_t61[ *s - 0xA0 ])).a ) {
01678        *o++ = (*cc).a;
01679        if ( (*cc).b )  *o++ = (*cc).b;
01680       }
01681 # endif
01682       s++;
01683       break;
01684 #endif
01685 
01686     default:
01687       *o++ = *s++;
01688     }
01689   }
01690 
01691   len = o - oo;
01692   o = oo;
01693 
01694   if ( (oo = (Byte *)NSLDAPI_REALLOC( o, len )) == NULL ) {
01695     NSLDAPI_FREE( o );
01696     return( 1 );
01697   }
01698 
01699   if ( free_input ) {
01700     NSLDAPI_FREE( *bufp );
01701   }
01702   *bufp = (char *) oo;
01703   *buflenp = len;
01704   return( 0 );
01705 }
01706 
01707 
01708 #ifdef NOT_NEEDED_IN_LIBLDAP       /* mcs@umich.edu 12 Oct 1995 */
01709 /* --- routine to convert "escaped" (\hh) characters to 8bits --- */
01710 
01711 void convert_escaped_to_8bit( s )
01712 char   *s;
01713 {
01714   char *o = s;
01715   int  c;
01716 
01717   while ( *s ) {
01718     if ( *s == '\\' ) {
01719       if ( (c = hh_to_c( ++s )) != -1 ) {
01720        *o++ = c;
01721        s += 2;
01722       } else
01723         *o++ = '\\';
01724     } else
01725       *o++ = *s++;
01726   }
01727   *o = '\0';
01728 }
01729 
01730 /* --- routine to convert 8bits characters to the "escaped" (\hh) form --- */
01731 
01732 char *convert_8bit_to_escaped( s )
01733 Byte  *s;
01734 {
01735   Byte *o, *oo;
01736   Byte n;
01737 
01738   if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
01739         return( NULL );
01740   }
01741 
01742   while ( *s ) {
01743     if ( *s < 0x80 )
01744       *o++ = *s++;
01745     else {
01746       *o++ = '\\';
01747       n = *s >> 4;
01748       *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
01749       n = *s++ & 0x0F;
01750       *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n;
01751     }
01752   }
01753   *o = '\0';
01754 
01755   o = oo;
01756 
01757   if ( (oo = (Byte *)NSLDAPI_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
01758     NSLDAPI_FREE( o );
01759     return( NULL );
01760   }
01761 
01762   return( (char *)oo );
01763 }
01764 
01765 /* --- routine to convert from T.61 to printable characters --- */
01766 
01767 /*
01768    printable characters [RFC 1488]: 'A'..'Z', 'a'..'z', '0'..'9',
01769        '\'', '(', ')', '+', ',', '-', '.', '/', ':', '?, ' '.
01770 
01771    that conversion is language dependent.
01772 */
01773 
01774 static Couple last_t61_printabled[32] = {
01775        {0,0},     {'A','E'}, {'D',0},   {0,0},
01776        {'H',0},   {0,0},     {'I','J'}, {'L',0},
01777        {'L',0},   {'O',0},   {'O','E'}, {0,0},
01778        {'T','H'}, {'T',0},   {'N','G'}, {'n',0},
01779        {'k',0},   {'a','e'}, {'d',0},   {'d',0},
01780        {'h',0},   {'i',0},   {'i','j'}, {'l',0},
01781        {'l',0},   {'o',0},   {'o','e'}, {'s','s'},
01782        {'t','h'}, {'t',0},   {'n','g'}, {0,0}
01783 };
01784 
01785 char *t61_printable( s )
01786 Byte  *s;
01787 {
01788   Byte   *o, *oo;
01789   Byte   n;
01790   Couple *cc;
01791 
01792   if ( (o = oo = (Byte *)NSLDAPI_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
01793         return( NULL );
01794   }
01795 
01796   while ( *s ) {
01797     if ( ( (*s >= 'A') && (*s <= 'Z') ) ||
01798          ( (*s >= 'a') && (*s <= 'z') ) ||
01799          ( (*s >= '0') && (*s <= '9') ) ||
01800          ( (*s >= '\'') && (*s <= ')') ) ||
01801          ( (*s >= '+') && (*s <= '/') ) ||
01802          ( *s == '?' ) || ( *s == ' ' ) )
01803       *o++ = *s++;
01804     else {
01805       if ( *s >= 0xE0 ) {
01806        if ( (*(cc = &last_t61_printabled[ *s - 0xE0 ])).a ) {
01807           *o++ = (*cc).a;
01808           if ( (*cc).b )  *o++ = (*cc).b;
01809         }
01810       }
01811       else if ( (*s >> 4) == 0xC ) {
01812         switch ( *s ) {
01813        case 0xCA:                  /* ring */
01814          switch ( *(s + 1) ) {
01815          case 'A':  *o++ = 'A'; *o++ = 'A'; s++; break; /* Swedish */
01816          case 'a':  *o++ = 'a'; *o++ = 'a'; s++; break; /* Swedish */
01817          }
01818          break;
01819 
01820        case 0xC8:                  /* diaeresis */
01821          switch ( *(s + 1) ) {
01822          case 'Y':  *o++ = 'I'; *o++ = 'J'; s++; break; /* Dutch */
01823          case 'y':  *o++ = 'i'; *o++ = 'j'; s++; break; /* Dutch */
01824           }
01825          break;
01826         }
01827       }
01828       s++;
01829     }
01830   }
01831   *o = '\0';
01832 
01833   o = oo;
01834 
01835   if ( (oo = (Byte *)NSLDAPI_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
01836     NSLDAPI_FREE( o );
01837     return( NULL );
01838   }
01839 
01840   return( (char *)oo );
01841 }
01842 #endif /* NOT_NEEDED_IN_LIBLDAP */ /* mcs@umich.edu 12 Oct 1995 */
01843 
01844 #endif /* LDAP_CHARSET_8859 */
01845 #endif /* STR_TRANSLATION */