Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Codeset_IBM1047.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // -*- C++ -*-
00003 // $Id: Codeset_IBM1047.cpp,v 1.1.1.3.2.1 2003/03/13 19:44:20 chad Exp $
00004 
00005 // ============================================================================
00006 //
00007 // = LIBRARY
00008 //    ace
00009 //
00010 // = FILENAME
00011 //    Codeset_IBM1047.cpp
00012 //
00013 // = DESCRIPTION
00014 //    Defines the arrays required to convert between ISO8859 (aka
00015 //    Latin/1) and IBM1047 (aka EBCDIC).
00016 //
00017 // = AUTHOR
00018 //    Jim Rogers (jrogers@viasoft.com)
00019 //
00020 // ============================================================================
00021 
00022 #include "ace/Codeset_IBM1047.h"
00023 
00024 #if defined(ACE_MVS)
00025 
00026 ACE_RCSID(ace, Codeset_IBM1047, "$Id: Codeset_IBM1047.cpp,v 1.1.1.3.2.1 2003/03/13 19:44:20 chad Exp $")
00027 
00028 // ****************************************************************
00029 
00030 ACE_IBM1047_ISO8859::ACE_IBM1047_ISO8859 (void)
00031 {
00032 }
00033 
00034 ACE_IBM1047_ISO8859::~ACE_IBM1047_ISO8859 (void)
00035 {
00036 }
00037 
00038 ACE_CDR::ULong
00039 ACE_IBM1047_ISO8859::ncs ()
00040 {
00041   return 0x10020417;
00042 }
00043 
00044 ACE_CDR::ULong
00045 ACE_IBM1047_ISO8859::tcs ()
00046 {
00047   return 0x00010001;
00048 }
00049 
00050 ACE_CDR::Boolean
00051 ACE_IBM1047_ISO8859::read_char (ACE_InputCDR &in,
00052                                 ACE_CDR::Char &x)
00053 {
00054   if (this->read_1 (in, ACE_reinterpret_cast (ACE_CDR::Octet*, &x)))
00055     {
00056       x = ACE_to_IBM1047[x];
00057       return 1;
00058     }
00059   return 0;
00060 }
00061 
00062 ACE_CDR::Boolean
00063 ACE_IBM1047_ISO8859::read_string (ACE_InputCDR& in,
00064                                   ACE_CDR::Char *& x)
00065 {
00066   ACE_CDR::ULong len;
00067 
00068   in.read_ulong (len);
00069 
00070   if (len > 0)
00071     {
00072       ACE_NEW_RETURN (x,
00073                       ACE_CDR::Char[len],
00074                       0);
00075 
00076       if (this->read_char_array (in, x, len))
00077         return 1;
00078 
00079       delete [] x;
00080     }
00081 
00082   x = 0;
00083   return 0;
00084 }
00085 
00086 ACE_CDR::Boolean
00087 ACE_IBM1047_ISO8859::read_char_array (ACE_InputCDR& in,
00088                                       ACE_CDR::Char* x,
00089                                       ACE_CDR::ULong len)
00090 {
00091   if (this->read_array (in,
00092                         x,
00093                         ACE_CDR::OCTET_SIZE,
00094                         ACE_CDR::OCTET_ALIGN,
00095                         len))
00096     {
00097       for (ACE_CDR::ULong i = 0; i != len; ++i)
00098         x[i] = ACE_to_IBM1047[x[i]];
00099 
00100       return 1;
00101     }
00102 
00103   return 0;
00104 }
00105 
00106 ACE_CDR::Boolean
00107 ACE_IBM1047_ISO8859::write_char (ACE_OutputCDR& out,
00108                                  ACE_CDR::Char x)
00109 {
00110   return this->write_1 (out,
00111                         ACE_reinterpret_cast (const ACE_CDR::Octet*,
00112                                               &ACE_from_IBM1047[x]));
00113 }
00114 
00115 ACE_CDR::Boolean
00116 ACE_IBM1047_ISO8859::write_string (ACE_OutputCDR& out,
00117                                    ACE_CDR::ULong len,
00118                                    const ACE_CDR::Char* x)
00119 {
00120   if (out.write_ulong (len + 1))
00121     return this->write_char_array (out, x, len + 1);
00122   return 0;
00123 }
00124 
00125 ACE_CDR::Boolean
00126 ACE_IBM1047_ISO8859::write_char_array (ACE_OutputCDR& out,
00127                                        const ACE_CDR::Char* x,
00128                                        ACE_CDR::ULong len)
00129 {
00130   char *buf;
00131   if (this->adjust (out, len, 1, buf) == 0)
00132     {
00133       ACE_OS::memcpy (buf, x, len);
00134 
00135       for (ACE_CDR::ULong i = 0; i != len; ++i)
00136         buf[i] = ACE_from_IBM1047[buf[i]];
00137 
00138       return 1;
00139     }
00140 
00141   this->good_bit(out, 0);
00142   return 0;
00143 }
00144 
00145 // ****************************************************************
00146 
00147 ACE_ISO8859_IBM1047::ACE_ISO8859_IBM1047 (void)
00148 {
00149 }
00150 
00151 ACE_ISO8859_IBM1047::~ACE_ISO8859_IBM1047 (void)
00152 {
00153 }
00154 
00155 ACE_CDR::ULong
00156 ACE_ISO8859_IBM1047::ncs ()
00157 {
00158   return 0x00010001;
00159 }
00160 
00161 ACE_CDR::ULong
00162 ACE_ISO8859_IBM1047::tcs ()
00163 {
00164   return 0x10020417;
00165 }
00166 
00167 
00168 ACE_CDR::Boolean
00169 ACE_ISO8859_IBM1047::read_char (ACE_InputCDR& in,
00170                                 ACE_CDR::Char& x)
00171 {
00172   if (this->read_1 (in, ACE_reinterpret_cast (ACE_CDR::Octet*, &x)))
00173     {
00174       x = ACE_from_IBM1047[x];
00175       return 1;
00176     }
00177   return 0;
00178 }
00179 
00180 ACE_CDR::Boolean
00181 ACE_ISO8859_IBM1047::read_string (ACE_InputCDR &in,
00182                                   ACE_CDR::Char *&x)
00183 {
00184   ACE_CDR::ULong len;
00185 
00186   in.read_ulong (len);
00187 
00188   if (len > 0)
00189     {
00190       ACE_NEW_RETURN (x,
00191                       ACE_CDR::Char[len],
00192                       0);
00193 
00194       if (this->read_char_array (in, x, len))
00195         return 1;
00196 
00197       delete [] x;
00198     }
00199 
00200   x = 0;
00201   return 0;
00202 }
00203 
00204 ACE_CDR::Boolean
00205 ACE_ISO8859_IBM1047::read_char_array (ACE_InputCDR &in,
00206                                       ACE_CDR::Char *x,
00207                                       ACE_CDR::ULong len)
00208 {
00209   if (this->read_array (in,
00210                         x,
00211                         ACE_CDR::OCTET_SIZE,
00212                         ACE_CDR::OCTET_ALIGN,
00213                         len))
00214     {
00215       for (ACE_CDR::ULong i = 0; i != len; ++i)
00216         x[i] = ACE_from_IBM1047[x[i]];
00217 
00218       return 1;
00219     }
00220 
00221   return 0;
00222 }
00223 
00224 ACE_CDR::Boolean
00225 ACE_ISO8859_IBM1047::write_char (ACE_OutputCDR &out,
00226                                  ACE_CDR::Char x)
00227 {
00228   return this->write_1 (out,
00229                         ACE_reinterpret_cast (const ACE_CDR::Octet *,
00230                                               &ACE_to_IBM1047[x]));
00231 }
00232 
00233 ACE_CDR::Boolean
00234 ACE_ISO8859_IBM1047::write_string (ACE_OutputCDR& out,
00235                                    ACE_CDR::ULong len,
00236                                    const ACE_CDR::Char* x)
00237 {
00238   if (out.write_ulong (len + 1))
00239     return this->write_char_array (out, x, len + 1);
00240   else
00241     return 0;
00242 }
00243 
00244 ACE_CDR::Boolean
00245 ACE_ISO8859_IBM1047::write_char_array (ACE_OutputCDR &out,
00246                                        const ACE_CDR::Char *x,
00247                                        ACE_CDR::ULong len)
00248 {
00249   char *buf;
00250 
00251   if (this->adjust (out, len, 1, buf) == 0)
00252     {
00253       ACE_OS::memcpy (buf, x, len);
00254 
00255       for (ACE_CDR::ULong i = 0; i != len; ++i)
00256         buf[i] = ACE_to_IBM1047[buf[i]];
00257 
00258       return 1;
00259     }
00260 
00261   this->good_bit (out, 0);
00262   return 0;
00263 }
00264 
00265 // ****************************************************************
00266 
00267 char ACE_to_IBM1047[257] =
00268 {
00269   "\x00\x01\x02\x03\x37\x2D\x2E\x2F\x16\x05\x25\x0B\x0C\x0D\x0E\x0F" // 00-0F
00270   "\x10\x11\x12\x13\x3C\x3D\x32\x26\x18\x19\x3F\x27\x22\x1D\x35\x1F" // 10-1F
00271   "\x40\x5A\x7F\x7B\x5B\x6C\x50\x7D\x4D\x5D\x5C\x4E\x6B\x60\x4B\x61" // 20-2F
00272   "\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\x7A\x5E\x4C\x7E\x6E\x6F" // 30-3F
00273   "\x7C\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xD1\xD2\xD3\xD4\xD5\xD6" // 40-4F
00274   "\xD7\xD8\xD9\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xAD\xE0\xBD\x5F\x6D" // 50-5F
00275   "\x79\x81\x82\x83\x84\x85\x86\x87\x88\x89\x91\x92\x93\x94\x95\x96" // 60-6F
00276   "\x97\x98\x99\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xC0\x4F\xD0\xA1\x07" // 70-7F
00277   "\x43\x20\x21\x1C\x23\xEB\x24\x9B\x71\x28\x38\x49\x90\xBA\xEC\xDF" // 80-8F
00278   "\x45\x29\x2A\x9D\x72\x2B\x8A\x9A\x67\x56\x64\x4A\x53\x68\x59\x46" // 90-9F
00279   "\xEA\xDA\x2C\xDE\x8B\x55\x41\xFE\x58\x51\x52\x48\x69\xDB\x8E\x8D" // A0-AF
00280   "\x73\x74\x75\xFA\x15\xB0\xB1\xB3\xB4\xB5\x6A\xB7\xB8\xB9\xCC\xBC" // B0-BF
00281   "\xAB\x3E\x3B\x0A\xBF\x8F\x3A\x14\xA0\x17\xCB\xCA\x1A\x1B\x9C\x04" // C0-CF
00282   "\x34\xEF\x1E\x06\x08\x09\x77\x70\xBE\xBB\xAC\x54\x63\x65\x66\x62" // D0-DF
00283   "\x30\x42\x47\x57\xEE\x33\xB6\xE1\xCD\xED\x36\x44\xCE\xCF\x31\xAA" // E0-EF
00284   "\xFC\x9E\xAE\x8C\xDD\xDC\x39\xFB\x80\xAF\xFD\x78\x76\xB2\x9F\xFF" // F0-FF
00285 };
00286 
00287 char ACE_from_IBM1047[257] =
00288 {
00289   "\x00\x01\x02\x03\xCF\x09\xD3\x7F\xD4\xD5\xC3\x0B\x0C\x0D\x0E\x0F" // 00-0F
00290   "\x10\x11\x12\x13\xC7\xB4\x08\xC9\x18\x19\xCC\xCD\x83\x1D\xD2\x1F" // 10-1F
00291   "\x81\x82\x1C\x84\x86\x0A\x17\x1B\x89\x91\x92\x95\xA2\x05\x06\x07" // 20-2F
00292   "\x20\xEE\x16\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\xC1\x1A" // 30-3F
00293   "\x20\xA6\xE1\x80\xEB\x90\x9F\xE2\xAB\x8B\x9B\x2E\x3C\x28\x2B\x7C" // 40-4F
00294   "\x26\xA9\xAA\x9C\xDB\xA5\x99\xE3\xA8\x9E\x21\x24\x2A\x29\x3B\x5E" // 50-5F
00295   "\x2D\x2F\xDF\xDC\x9A\xDD\xDE\x98\x9D\xAC\xBA\x2C\x25\x5F\x3E\x3F" // 60-6F
00296   "\xD7\x88\x94\xB0\xB1\xB2\xFC\xD6\xFB\x60\x3A\x23\x40\x27\x3D\x22" // 70-7F
00297   "\xF8\x61\x62\x63\x64\x65\x66\x67\x68\x69\x96\xA4\xF3\xAF\xAE\xC5" // 80-8F
00298   "\x8C\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x97\x87\xCE\x93\xF1\xFE" // 90-9F
00299   "\xC8\x7E\x73\x74\x75\x76\x77\x78\x79\x7A\xEF\xC0\xDA\x5B\xF2\xF9" // A0-AF
00300   "\xB5\xB6\xFD\xB7\xB8\xB9\xE6\xBB\xBC\xBD\x8D\xD9\xBF\x5D\xD8\xC4" // B0-BF
00301   "\x7B\x41\x42\x43\x44\x45\x46\x47\x48\x49\xCB\xCA\xBE\xE8\xEC\xED" // C0-CF
00302   "\x7D\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\xA1\xAD\xF5\xF4\xA3\x8F" // D0-DF
00303   "\x5C\xE7\x53\x54\x55\x56\x57\x58\x59\x5A\xA0\x85\x8E\xE9\xE4\xD1" // E0-EF
00304   "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\xB3\xF7\xF0\xFA\xA7\xFF" // F0-FF
00305 };
00306 
00307 #elif defined (__HP_aCC)
00308 // Make aC++ stop complaining about an empty translation unit
00309 static int shut_up_aCC = 0;
00310 #endif /* ACE_MVS */

Generated on Mon Jun 16 11:19:22 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002