ITEM: E8778L

Character translation from EBCDIC to ASCII


Question:

Communication is between a Mainframe (TSO) to a RS/6000, Model 370 
running on AIX 3.2.4. I want to know how to do character translation
from EBCDIC to ASCII. I want to do everything except Packed Decimal.
I am receiving the data over LU6.2 (SNA) and want to convert it using
C subroutine calls.

Response:

Customer was confused about use of obsolete NLXIN that has been replaced
by iconv routines.  He also wanted to know how to change the EBCDIC/ASCII
conversion tables for use by these conversion routines and I will answer
this question first.

To make your own EBCDIC-ASCII conversion tables, modify ones included 
with AIX.
-----------------------------
  1.  mkdir $HOME/iconvTable
      mkdir $HOME/iconvTable/mine
      cd $HOME/iconvTable/mine
      cp -p $LOCPATH/IBM-037_IBM-850_src ./037850.x
      cp -p $LOCPATH/IBM-850_IBM-037_src ./850037.x
  2.  Edit these source files as appropriate, for example:
       When I tn3270 to VM I observe that the conversions for AIX 
       give some strange conversions for the characters \^ [ ] since some
       versions of telnet or ftp or mail manage to send non-037 codes 
       for the ebcdic.  The following table shows what is happening.

                                  tn3270   ftp,mail
                                  sends    send
                         IBM-850  IBM-037  "whatever"  
                 symbol  ascii    ebcdic   ebcdic
                 ------  -------  -------  --------
                      \^     5E       B0        5F (Logical Not)
                      [     5B       BA        AD (y acute capital)
                      ]     5D       BB        BD (umlaut accent)

       If I want these characters (however they are sent) to be displayed
       correctly, the following will accomplish that objective. In the 
       IBM-037_IBM-850_src file:

           replace this       with this
           ------------       -----------
           0x5F   0xAA        0x5F   0x5E
           0xAD   0xED        0xAD   0x5B       
           0xBD   0xF9        0xBD   0x5D

        This means, of course, that AA(Logical Not), ED(y acute capital),
        and F9(umlaut accent) cannot now be translated correctly by any
        program using this conversion table (tn3270, tn -e3270).
  3.  Having changed the source files to your liking, you must generate 
      new conversion tables by:

        genxlt \< 037850.x > ../IBM-037_IBM-850
        genxlt \< 850037.x > ../IBM-850_IBM-037 (not needed, this example)

  4.  In the window that you will use this new conversion, make a change 
      in environment by:

        export LOCPATH=$HOME   ( normally this is /usr/lib/nls/loc )

  5.  Now run the application that is to use the new conversion in the
      window with the new LOCPATH.

Below I have included an example EBCDIC/ASCII conversion program:
-----------------------------------------------------------------
/* ebcasc.c                                              */
/* IBM-037 for EBCDIC (U.S.English)                      */
/* IBM-850 for En_US                                     */
/* ISO8859-1 for en_US                                   */
/* Execute by:                                           */
/*   cc -liconv -o ebcasc ebcasc.c                       */
/*   ebcasc                                              */
/*                                                       */
/* This is a very simple routine that demonstrates how   */
/* to use the EBCDIC/ASCII conversion subroutines.       */
/*                                                       */
/* You will need to read more about iconv routines in    */
/* InfoExplorer or you may choose to use ConsultLine to  */
/* modify this sample program to use your way of reading */
/* data and make this routine safe enough to be trusted. */
/* This program is only intended to illustrate the use   */
/* of the iconv subroutine calls.                        */

\#include \
\#include \
main(int argc, char *argv[])
{  iconv_t cd;
  char inBuf[1024]={'a','b','c','d'}, outBuf[1024]={'A', 'B', 'C', 'D'};
  char *i, *o, *ip, *op;
  size_t iLeft, oLeft;
  size_t ii;
  cd = iconv_open("IBM-037", "IBM-850");
  if (cd == -1) exit(0);
  strcpy(inBuf, ".\<(+!");
  iLeft = 5;
  oLeft = 5;
  ip = inBuf;
  op = outBuf;
  ii = iconv(cd, &ip, &iLeft, &op, &oLeft);
printf("IBM-037 vs IBM-850\\n");
printf("  %s vs   %s\\n", inBuf, outBuf);
  iconv_close(cd);

HR
CENTER
FONT size=2Support Line: Character translation from EBCDIC to ASCII ITEM: E8778L
BRDated: November 1993 Category: N/A
BRThis HTML file was generated 99/06/24~13:30:53
BRComments or suggestions?
A href="../../../../feedback.html"BContact us/B/ABR
/FONT
/CENTER
/BODY
/HTML