home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxgwa1.zip / rxgwa.c < prev    next >
Text File  |  1993-03-13  |  8KB  |  172 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* Module Name: RXGWA.C (version 1.0 - 3/13/93)                    */
  4. /*                                                                 */
  5. /* Description: ASCII to EBCDIC String Conversion for              */
  6. /*              OS/2 REXX                                          */
  7. /*                                                                 */
  8. /* Author     : Gerald W. (Jerry) am Ende Compuserve 73237,131     */
  9. /*                                                                 */
  10. /* Notes      : Use the following files included in this ZIP file  */
  11. /*              to compile & link this module:                     */
  12. /*                 RXGWA.DEF RXGWA.DEP RXGWA.MAK                   */
  13. /*                                                                 */
  14. /* Disclaimers: I freely admit I'm not an expert in writing REXX   */
  15. /*              functions, I just followed the examples that came  */
  16. /*              with the CSET/2 toolkit (thanx IBM).  So, be       */
  17. /*              careful about using these functions in anything    */
  18. /*              you consider critical.  RXGWA.DLL is freeware.     */
  19. /*              Feel free to use or modify these programs however  */
  20. /*              you see fit.  HOWEVER, please do not hold me       */
  21. /*              responsible for any damage they might cause you    */
  22. /*              or your data.                                      */
  23. /*                                                                 */
  24. /*******************************************************************/
  25.  
  26.  
  27. #include    <os2.h>
  28. #include    <stdio.h>
  29. #include    <stdlib.h>
  30. #include    <string.h>
  31. #include    <bsememf.h>         /* Get Flags for memory Mgmt */
  32. #define     INCL_DOSMEMMGR      /* Memory Manager Values     */
  33. #define     INCL_RXSHV
  34. #define     INCL_RXSUBCOM
  35. #define     INCL_REXXSAA
  36. #define     INVALID_ROUTINE 40
  37. #define     VALID_ROUTINE 0
  38. #include    <rexxsaa.h>
  39.  
  40. #define  MAX            256        /* temporary buffer length        */
  41. #define  IBUF_LEN       4096       /* Input buffer length            */
  42.  
  43. RexxFunctionHandler E2A;
  44. RexxFunctionHandler A2E;
  45.  
  46. ULONG E2A(CHAR *name, ULONG numargs, RXSTRING args[],
  47.           CHAR *queuename, RXSTRING *retstr)
  48.  
  49. {
  50.    USHORT i;
  51.    APIRET rc;
  52.    ULONG AllocFlags = PAG_WRITE | PAG_COMMIT;
  53.    UCHAR convert[256] = {
  54.                     0x00,0x01,0x02,0x03,0xFF,0x09,0xFF,0x7F,
  55.                     0xFF,0xFF,0xFF,0x0B,0x0C,0x0D,0x0E,0x0F,
  56.                     0x10,0x11,0x12,0x13,0xFF,0xFF,0x08,0xFF,
  57.                     0x18,0x19,0xFF,0xFF,0xFF,0x1D,0xFF,0x1F,
  58.                     0xFF,0xFF,0x1C,0xFF,0xFF,0x0A,0x17,0x1B,
  59.                     0xFF,0xFF,0xFF,0xFF,0xFF,0x05,0x06,0x07,
  60.                     0xFF,0xFF,0x16,0xFF,0xFF,0x1E,0xFF,0x04,
  61.                     0xFF,0xFF,0xFF,0xFF,0x14,0x15,0xFF,0x1A,
  62.                     0x20,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  63.                     0xFF,0xFF,0xFF,0x2E,0x3C,0x28,0x2B,0xFF,
  64.                     0x26,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  65.                     0xFF,0xFF,0x21,0x24,0x2A,0x29,0x3B,0x5E,
  66.                     0x2D,0x2F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  67.                     0xFF,0xFF,0x7C,0x2C,0x25,0x5F,0x3E,0x3F,
  68.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  69.                     0xFF,0x60,0x3A,0x23,0x40,0x27,0x3D,0x22,
  70.                     0xFF,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
  71.                     0x68,0x69,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  72.                     0xFF,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,
  73.                     0x71,0x72,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  74.                     0xFF,0x7E,0x73,0x74,0x75,0x76,0x77,0x78,
  75.                     0x79,0x7A,0xFF,0xFF,0xFF,0x5B,0xFF,0xFF,
  76.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  77.                     0xFF,0xFF,0xFF,0xFF,0xFF,0x5D,0xFF,0xFF,
  78.                     0x7B,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
  79.                     0x48,0x49,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  80.                     0x7D,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,
  81.                     0x51,0x52,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  82.                     0x5C,0xFF,0x53,0x54,0x55,0x56,0x57,0x58,
  83.                     0x59,0x5A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  84.                     0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
  85.                     0x38,0x39,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  86.  
  87.    if ((numargs != 1) | (args[0].strlength > 0xffff)) {
  88.       return INVALID_ROUTINE;
  89.       }
  90.  
  91.    if (args[0].strlength > 255) {
  92.       rc = DosAllocMem((PPVOID)&retstr->strptr,
  93.                        (ULONG)args[0].strlength+1,
  94.                        AllocFlags);
  95.       if (rc != 0)
  96.          return INVALID_ROUTINE;
  97.       }
  98.  
  99.    for (i=0;i<args[0].strlength;i++)
  100.       {
  101.          retstr->strptr[i] = convert[(UCHAR)args[0].strptr[i]];
  102.       }
  103.  
  104.    retstr->strlength = args[0].strlength;
  105.  
  106.    return VALID_ROUTINE;
  107. }
  108.  
  109. ULONG A2E(CHAR *name, ULONG numargs, RXSTRING args[],
  110.           CHAR *queuename, RXSTRING *retstr)
  111.  
  112. {
  113.    USHORT i;
  114.    APIRET rc;
  115.    ULONG AllocFlags = PAG_WRITE | PAG_COMMIT;
  116.    UCHAR convert[256] = {
  117.                     0x00,0x01,0x02,0x03,0x37,0x2D,0x2E,0x2F,
  118.                     0x16,0x05,0x25,0x0B,0x0C,0x0D,0x0E,0x0F,
  119.                     0x10,0x11,0x12,0x13,0x3C,0x3D,0x32,0x26,
  120.                     0x18,0x19,0x3F,0x27,0x22,0x1D,0x35,0x1F,
  121.                     0x40,0x5A,0x7F,0x7B,0x5B,0x6C,0x50,0x7D,
  122.                     0x4D,0x5D,0x5C,0x4E,0x6B,0x60,0x4B,0x61,
  123.                     0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,
  124.                     0xF8,0xF9,0x7A,0x5E,0x4C,0x7E,0x6E,0x6F,
  125.                     0x7C,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,
  126.                     0xC8,0xC9,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,
  127.                     0xD7,0xD8,0xD9,0xE2,0xE3,0xE4,0xE5,0xE6,
  128.                     0xE7,0xE8,0xE9,0xAD,0xE0,0xBD,0x5F,0x6D,
  129.                     0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
  130.                     0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96,
  131.                     0x97,0x98,0x99,0xA2,0xA3,0xA4,0xA5,0xA6,
  132.                     0xA7,0xA8,0xA9,0xC0,0x6A,0xD0,0xA1,0x07,
  133.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  134.                     0xFF,0xFF,0xFF,0xFF,0xFF,0x0D,0x25,0xFF,
  135.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  136.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  137.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  138.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  139.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  140.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  141.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  142.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  143.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  144.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  145.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  146.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  147.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  148.                     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  149.  
  150.    if ((numargs != 1) | (args[0].strlength > 0xffff)) {
  151.       return INVALID_ROUTINE;
  152.       }
  153.  
  154.    if (args[0].strlength > 255) {
  155.       rc = DosAllocMem((PPVOID)&retstr->strptr,
  156.                        (ULONG)args[0].strlength+1,
  157.                        AllocFlags);
  158.       if (rc != 0)
  159.          return INVALID_ROUTINE;
  160.       }
  161.  
  162.    for (i=0;i<args[0].strlength;i++)
  163.       {
  164.          retstr->strptr[i] = convert[(UCHAR)args[0].strptr[i]];
  165.       }
  166.  
  167.    retstr->strlength = args[0].strlength;
  168.  
  169.    return VALID_ROUTINE;
  170. }
  171.  
  172.