home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xaio1.exe / XAIOC.C < prev    next >
Text File  |  1994-09-07  |  22KB  |  797 lines

  1. /****************************************************************************
  2. **    File:    XAIOC.C
  3. **
  4. **    Desc: Sample AIO ANSI terminal emulator for NetWare NLM platform.
  5. **
  6. **    Disclaimer:
  7. **
  8. **        Novell, Inc. makes no representations or warranties with respect to
  9. **        any NetWare software, and specifically disclaims any express or
  10. **        implied warranties of merchantability, title, or fitness for a
  11. **        particular purpose.  
  12. **
  13. **        Distribution of any NetWare software is forbidden without the
  14. **        express written consent of Novell, Inc.  Further, Novell reserves
  15. **        the right to discontinue distribution of any NetWare software.
  16. **
  17. **        Novell is not responsible for lost profits or revenue, loss of use
  18. **        of the software, loss of data, costs of re-creating lost data, the
  19. **        cost of any substitute equipment or program, or claims by any party
  20. **        other than you.  Novell strongly recommends a backup be made before
  21. **        any software is installed.   Technical support for this software
  22. **        may be provided at the discretion of Novell.
  23. **
  24. **    QMK386 options used:
  25. **
  26. **        /ia - AIO support
  27. **
  28. **    Programmers:
  29. **
  30. **        Ini    Who                    Firm
  31. **        -----------------------------------------------------------------------
  32. **        ABJ    Adam B. Jerome        Novell Developer Support.
  33. **
  34. **    History:
  35. **
  36. **        When        Who    What
  37. **        -----------------------------------------------------------------------
  38. **        08-04-94    ABJ    First code.
  39. */
  40.  
  41. /****************************************************************************
  42. **    Include headers, function prototypes, macros, etc.
  43. */
  44.     /*------------------------------------------------------------------------
  45.     **    ANSI
  46.     */
  47.     #include <stdio.h>
  48.     #include <stdlib.h>
  49.     #include <process.h>
  50.     #include <string.h>
  51.     #include <ctype.h>
  52.  
  53.     /*------------------------------------------------------------------------
  54.     **    Platform specific
  55.     */
  56.     #include <conio.h>
  57.  
  58.     /*------------------------------------------------------------------------
  59.     **    NetWare NLM
  60.     */
  61.     #include <aio.h>
  62.  
  63.     /*------------------------------------------------------------------------
  64.     **    This module.
  65.     */
  66.     #define BUFFER_SIZE     128
  67.     #define KEY_F1                315
  68.     #define KEY_F2                316
  69.  
  70. /****************************************************************************
  71. **    Global storage.
  72. */
  73. int    NLM_ansiMode=(-1L);        /*    Enable ANSI mode (-1=YES, 0=NO).    */
  74.  
  75. /****************************************************************************
  76. **    Get the curser position.
  77. **
  78. **    Generally returns row range 0:24 and column range 0:79; but can return
  79. ** row 25 and column 0, which indicates that the next character sent to the
  80. **    screen will cause a horizonal scroll.
  81. */
  82. void GetCursorPosition(WORD *row, WORD *col)
  83.     {
  84.     GetPositionOfOutputCursor(row, col);
  85.  
  86.     return;
  87.     }
  88.  
  89. /****************************************************************************
  90. **    Set the curser position.
  91. */
  92. void SetCursorPosition(WORD row, WORD col)
  93.     {
  94.  
  95.     /*------------------------------------------------------------------------
  96.     **    Bounds checking.
  97.     **
  98.     **    [Row 25 : Col 0] causes ABEND under NW3.12, while under other nw
  99.     ** versions, it just means to scroll when next char is printed.
  100.     **
  101.     **    If [Row 25] and [Col != 0], it will abend most nw versions.
  102.     */
  103.     if(row > 24)
  104.         {
  105.         if(col != 0)
  106.             {
  107.             row=24; col=79;
  108.             getch();
  109.             }
  110.         else
  111.             {
  112.             printf(" \b");    /* Cause a scroll to happen */
  113.             row = 24;
  114.             }
  115.         }
  116.  
  117.     SetPositionOfInputCursor(row, col);
  118.     }
  119.  
  120. /****************************************************************************
  121. **    Update help line.
  122. */
  123. void UpdateHelp(void)
  124.     {
  125.     WORD sRow, sCol;
  126.     char szTemp[80+1];
  127.  
  128.     GetCursorPosition(&sRow, &sCol);
  129.     SetCursorPosition(0,0);
  130.  
  131.     sprintf(szTemp, "F1:Exit   F2:%s",
  132.         NLM_ansiMode ? "Turn off ANSI translation" : "Turn on ANSI translation"
  133.         );
  134.  
  135.     printf("%80s", szTemp);
  136.  
  137.     SetCursorPosition(sRow, sCol);
  138.     
  139.     return;
  140.     }
  141.  
  142. /****************************************************************************
  143. **    Put a character on the screen, ANSI style.
  144. */
  145. int ANSI_PutCh(char ch)
  146.     {
  147.     static int     escMode=0;        /* Flag that remembers if we are in an esc seq */
  148.     static char    escStr[128+1];    /* Escape string.    */
  149.     static char *escEnd;
  150.       static WORD sRow = 1;
  151.     static WORD sCol = 0;
  152.     static int    autoLF=0;        /* Flag indicates that the previous character caused an auto-Line feed */
  153.     short cRow;
  154.     short    cCol;
  155.     short tRow;
  156.     short tCol;
  157.     char  *cp;
  158.     int    x;
  159.  
  160.     /*------------------------------------------------------------------------
  161.     **    Activate ESC mode?
  162.     */
  163.     if((!escMode) && (ch == 27) && (NLM_ansiMode))
  164.         {
  165.         memset(escStr, 0x00, sizeof(escStr));
  166.         escEnd=NULL;
  167.         ++escMode;
  168.         return(0);
  169.         }
  170.  
  171.     /*------------------------------------------------------------------------
  172.     **    If we are not in ESC mode, print directly.
  173.     */
  174.     if(!escMode)
  175.         {
  176.  
  177.         /*---------------------------------------------------------------------
  178.         ** Weed-patch fix for unwanted cursor bluping.
  179.         */
  180.         if((autoLF) && (ch == '\n'))
  181.             {
  182.             autoLF = 0;
  183.             return(0);
  184.             }
  185.  
  186.         GetCursorPosition((WORD *)&cRow, (WORD *)&cCol);
  187.         
  188.         printf("%c", ch);
  189.  
  190.         /*---------------------------------------------------------------------
  191.         **    cRow = 25 means we just scrolled.
  192.         */
  193.         if(cRow == 25) UpdateHelp();
  194.  
  195.  
  196.         /*---------------------------------------------------------------------
  197.         **    More weed-patch.
  198.         */
  199.         GetCursorPosition((WORD *)&tRow, (WORD *)&tCol);
  200.         if((tRow != cRow) && (ch != '\n')) autoLF=1;
  201.  
  202.         return(0);
  203.         }
  204.  
  205.     /*------------------------------------------------------------------------
  206.     **    Second char of esc sequence is always a open bracket.
  207.     */
  208.     if(escMode == 1)
  209.         {
  210.         ++escMode;
  211.         if(ch != '[')
  212.             {
  213.             printf("[ANSI BRACKET ERROR]");
  214.             goto CLR_ESC_MODE;
  215.             }
  216.  
  217.         return(0);
  218.         }
  219.  
  220.     /*------------------------------------------------------------------------
  221.     **    If we have overflowed the ESC buffer, pewk and terminate esc mode.
  222.     */
  223.     if(strlen(escStr) > sizeof(escStr) - 2)
  224.         {
  225.         printf("[%s]", escStr);
  226.         goto CLR_ESC_MODE;
  227.         }
  228.  
  229.     /*------------------------------------------------------------------------
  230.     **    Build the esc buffer.
  231.     */
  232.     if(escEnd == NULL) escEnd = escStr;
  233.         else ++escEnd;
  234.  
  235.     *escEnd = ch;
  236.     ++escMode;
  237.  
  238.     /*------------------------------------------------------------------------
  239.     **    Check the last char of string.
  240.     */
  241.     switch(*escEnd)
  242.         {
  243.         /*---------------------------------------------------------------------
  244.         **    Moves the cursor up specifed rows (1-24, default=1).  Has no effect
  245.         ** if cursor is on the top row.
  246.         */
  247.         case 'A':                             /* 0 - 24       0 - 79 */
  248.             GetCursorPosition((WORD *)&cRow, (WORD *)&cCol);
  249.             x = atoi(escStr);
  250.             if(!x) x=1;
  251.             cRow += x;
  252.             if(cRow > 24) cRow=24;
  253.             SetCursorPosition((WORD)cRow, (WORD)cCol);
  254.             goto CLR_ESC_MODE;
  255.  
  256.         /*---------------------------------------------------------------------
  257.         **    Move the cursor down specified rows (1-24, default=1). Has no effect
  258.         **    if cursor is on the bottom row. 
  259.         */
  260.         case 'B':                             /* 0 - 24       0 - 79 */
  261.             GetCursorPosition((WORD *)&cRow, (WORD *)&cCol);
  262.             x = atoi(escStr);
  263.             if(!x) x=1;
  264.             cRow -= x;
  265.             if(cRow < 0) cRow=0;
  266.             SetCursorPosition((WORD)cRow, (WORD)cCol);
  267.             goto CLR_ESC_MODE;
  268.  
  269.         /*---------------------------------------------------------------------
  270.         **    Move the cursor right specified number of rows. (1-79, default = 1).
  271.         **    Has no effect if cursor is in the far right column.
  272.         */
  273.         case 'C':                             /* 0 - 24       0 - 79 */
  274.             GetCursorPosition((WORD *)&cRow, (WORD *)&cCol);
  275.             x = atoi(escStr);
  276.             if(!x) x=1;
  277.             cCol += x;
  278.             if(cCol > 79) cCol=79;
  279.  
  280. if((cRow == 25) && (cCol != 0))
  281.     {
  282.     printf("\n[ESC-C R:%hd,C:%hd]\n", cRow, cCol);
  283.     getch();
  284.     }
  285.             SetCursorPosition((WORD)cRow, (WORD)cCol);
  286.             goto CLR_ESC_MODE;
  287.  
  288.         /*---------------------------------------------------------------------
  289.         **    Move the cursor left specified rows (1-79, default=1).  Has no
  290.         **    effect if cursor is in the far left column.
  291.         */
  292.         case 'D':                             /* 0 - 24       0 - 79 */
  293.             GetCursorPosition((WORD *)&cRow, (WORD *)&cCol);
  294.             x = atoi(escStr);
  295.             if(!x) x=1;
  296.             cCol -= x;
  297.             if(cCol < 0) cCol=0;
  298.             SetCursorPosition((WORD)cRow, (WORD)cCol);
  299.             goto CLR_ESC_MODE;
  300.  
  301.         /*---------------------------------------------------------------------
  302.         **    Moves the cursor to the specified row (1-25, default=1) and column
  303.         **    (1-80, default=1).  If row is omitted, the semicolon before column
  304.         ** must be specified.
  305.         */
  306.         case 'H':
  307.         case 'f':
  308.             cRow = atoi(escStr);
  309.             if(!cRow) cRow=1;
  310.             if(cRow > 25) cRow=25;
  311.             if(cRow < 1)  cRow=1;
  312.             /* Do not zero index the row, being that ANSI is only 24 rows.*/
  313.  
  314.             cp=strchr(escStr, ';');
  315.             if(cp == NULL)    cCol=1;
  316.             else
  317.                 {
  318.                 ++cp;
  319.                 cCol=atoi(cp);
  320.                 if(cCol > 80) cCol=80;
  321.                 if(cCol < 1)  cCol=1;
  322.                 }
  323.             --cCol; /* zero index */
  324.                                                /* 0 - 24       0 - 79 */
  325.             SetCursorPosition((WORD)cRow, (WORD)cCol);
  326.             goto CLR_ESC_MODE;
  327.  
  328.         /*---------------------------------------------------------------------
  329.         **    Store the current row and column position of the cursor.  Cursor can
  330.         ** be restored to this position later with a Restore Cursor Position
  331.         **    escape sequence.
  332.         */
  333.         case 's':
  334.             GetCursorPosition(&sRow, &sCol);
  335.             goto CLR_ESC_MODE;
  336.  
  337.         /*---------------------------------------------------------------------
  338.         **    Moves the cursor to the position of the most recent Save Cursor
  339.         ** Position escape sequences.
  340.         **    
  341.         */
  342.         case 'u':
  343.             SetCursorPosition(sRow, sCol);
  344.             goto CLR_ESC_MODE;
  345.  
  346.         /*---------------------------------------------------------------------
  347.         **    Clear the screen and place cursor at the home position.
  348.         */
  349.         case 'J':
  350.             clrscr();
  351.             SetCursorPosition(1,0);
  352.             UpdateHelp();
  353.             goto CLR_ESC_MODE;
  354.  
  355.         /*---------------------------------------------------------------------
  356.         **    Erases from cursor position to the end of the same row.
  357.         */
  358.         case 'K':
  359.             goto CLR_ESC_MODE;
  360.  
  361.         /*---------------------------------------------------------------------
  362.         **    Controls specific graphics attributes such as intensity, blinking,
  363.         **    superscript, and sub script, as well as the foreground and
  364.         ** background colors. May contain multiple fields separated by
  365.         **    semicolons.
  366.         **
  367.         **    Being that color and attributes are a bit difficult to handle in the
  368.         ** NetWare 3.x environment, this section will do little more than
  369.         **    acknoledge the operations.
  370.         */
  371.         case 'm':
  372.             cp=escStr;
  373.             while(cp < escEnd)
  374.                 {
  375.                 switch(*cp)
  376.                     {
  377.                     case ';':    /* Ignore the field separator.    */
  378.  
  379.                     case 0:        /*    All attributes off.                */
  380.                     case 1:        /* High intensity (bold).            */
  381.                     case 2:        /* Normal intensity.                    */
  382.                     case 4:        /* Undrline.                            */
  383.                     case 5:        /* Blink.                                */
  384.                     case 7:        /* Reverse video.                        */
  385.                     case 8:        /* Concealed (invisible).            */
  386.  
  387.                     case 30:        /* Black foreground.                    */
  388.                     case 31:        /* Red foreground.                    */
  389.                     case 32:        /* Green foreground.                    */
  390.                     case 33:        /* Yellow foreground.                */
  391.                     case 34:        /* Blue foreground.                    */
  392.                     case 35:        /* Magenta foreground.                */
  393.                     case 36:        /* Cyan foreground.                    */
  394.                     case 37:        /* White foreground.                    */
  395.  
  396.                     case 40:        /* Black background.                    */
  397.                     case 41:        /* Red background.                    */
  398.                     case 42:        /* Green background.                    */
  399.                     case 43:        /* Yellow background.                */
  400.                     case 44:        /* Blue background.                    */
  401.                     case 45:        /* Magenta background.                */
  402.                     case 46:        /* Cyan background.                    */
  403.                     case 47:        /* White background.                    */
  404.                         break;
  405.  
  406.                     default:
  407.                         break;
  408.                     }
  409.                 ++cp;
  410.                 }
  411.             goto CLR_ESC_MODE;
  412.  
  413.         /*---------------------------------------------------------------------
  414.         **    I don't know what this does.
  415.         */
  416.         default:
  417.             if(isalpha(ch))
  418.                 {
  419.                 printf("[Unresolved escape code: {%s} %02X %02X %02X]",
  420.                     escStr,
  421.                     0x000000FF & escStr[0],
  422.                     0x000000FF & escStr[1],
  423.                     0x000000FF & escStr[2]
  424.                     );
  425.  
  426.                 getch();
  427.                 goto CLR_ESC_MODE;
  428.                 }
  429.  
  430.             break;
  431.         }
  432.  
  433.     return(0);
  434.  
  435. CLR_ESC_MODE:
  436.     escMode=0;
  437.     return(0);
  438.     }
  439.  
  440.  
  441.  
  442. /****************************************************************************
  443. **    Program start.
  444. */
  445. void main(void)
  446.     {
  447.    int                 portHandle = -1;
  448.  
  449.     int                      ch;
  450.     int                      x;
  451.    int                 cCode;
  452.    LONG                count;
  453.    WORD                state;
  454.    char                buffer[BUFFER_SIZE];
  455.    AIOPORTCAPABILITIES portCaps;
  456.    int                 hardwareType;
  457.    int                 boardNumber;
  458.    int                 portNumber;
  459.  
  460.    /*------------------------------------------------------------------------
  461.     **    Acquire any available port.
  462.     */
  463.    hardwareType  = AIO_HARDWARE_TYPE_WILDCARD /* AIO_COMX_TYPE */;
  464.    boardNumber   = AIO_BOARD_NUMBER_WILDCARD;
  465.    portNumber    = AIO_PORT_NUMBER_WILDCARD;
  466.  
  467.    cCode=AIOAcquirePort(
  468.         /* IO    hardwareType    */    &hardwareType,
  469.         /*    IO    boardNumber        */    &boardNumber,
  470.         /*    IO    portNumber        */    &portNumber,
  471.         /*    -O    portHandle        */    &portHandle
  472.         );
  473.     switch(cCode)
  474.         {
  475.         case AIO_SUCCESS:
  476.             break;
  477.  
  478.         case AIO_FAILURE:
  479.           printf("ERROR:  AIOAcquirePort() failed.\n");
  480.             break;
  481.  
  482.         case AIO_PORT_NOT_AVAILABLE:
  483.           printf("ERROR:  AIOAcquirePort() reported: No ports available.\n");
  484.           goto END;
  485.     
  486.         case AIO_TYPE_NUMBER_INVALID:
  487.           printf("ERROR:  AIOAcquirePort() reported: Invalid hardware type specified.\n");
  488.           goto END;
  489.  
  490.         case AIO_BOARD_NUMBER_INVALID:
  491.           printf("ERROR:  AIOAcquirePort() reported: Invalid board number specified.\n");
  492.           goto END;
  493.  
  494.         case AIO_PORT_NUMBER_INVALID:
  495.           printf("ERROR:  AIOAcquirePort() reported: Invalid port number specified.\n");
  496.           goto END;
  497.  
  498.         default:
  499.           printf("ERROR:  AIOAcquirePort() reported unknown error: %d.\n", cCode);
  500.           goto END;
  501.         }
  502.  
  503.    printf("Acquired port for driver %d, board %d, port %d.\n",
  504.         hardwareType, boardNumber, portNumber);
  505.  
  506.    /*------------------------------------------------------------------------
  507.     ** Get the high-level capabilities of the acquired port.
  508.     */
  509.    cCode=AIOGetPortCapability(
  510.         /* I- portHandle        */    portHandle,
  511.         /*    IO    capabilities    */    &portCaps,
  512.         /*    IO    dvrCapabilities*/    NULL             /* NULL means we don't need this. */
  513.         );
  514.     switch(cCode)
  515.         {
  516.         case AIO_SUCCESS:
  517.             break;
  518.  
  519.         case AIO_BAD_HANDLE:
  520.           printf("ERROR:  AIOGetPortCapability() reported: Bad handle specified.\n");
  521.             break;
  522.  
  523.         case AIO_FAILURE:
  524.           printf("ERROR:  AIOGetPortCapability() failed.\n");
  525.             break;
  526.  
  527.         case AIO_PORT_GONE:
  528.           printf("ERROR:  AIOGetPortCapability() reported: Port is gone.\n");
  529.           goto END;
  530.     
  531.         default:
  532.           printf("ERROR:  AIOGetPortCapability() reported unknown error: %d.\n", cCode);
  533.           goto END;
  534.         }
  535.  
  536.    /*------------------------------------------------------------------------
  537.     **    Verify that the structures are current or newer
  538.     */
  539.    if(portCaps.returnLength < sizeof(portCaps))
  540.       printf("WARNING:  Obsolete structures in use!\n");
  541.       else
  542.         {
  543.        /*---------------------------------------------------------------------
  544.         **    Verify that the port can handle 2400 baud
  545.         */
  546.        if((portCaps.minBitRate > AIO_BAUD_2400) || (portCaps.maxBitRate < AIO_BAUD_2400))
  547.           printf("WARNING:  Port cannot be configured for 2400bps rate requirement.\n");
  548.         }
  549.  
  550.    /*------------------------------------------------------------------------
  551.     **    Configure the port for use
  552.     */
  553.    cCode=AIOConfigurePort(
  554.         /*    I-    portHandle        */    portHandle,
  555.         /*    I-    bitRate            */    AIO_BAUD_2400,
  556.         /*    I- dataBits            */    AIO_DATA_BITS_8,
  557.       /*    I- stopBits            */    AIO_STOP_BITS_1,
  558.         /*    I- parityMode        */    AIO_PARITY_NONE,
  559.         /*    I- flowCtrlMode    */    AIO_SOFTWARE_FLOW_CONTROL_ON
  560.         );
  561.     switch(cCode)
  562.         {
  563.         case AIO_SUCCESS:
  564.             break;
  565.  
  566.         case AIO_BAD_HANDLE:
  567.           printf("ERROR:  AIOConfigurePort() reported: Bad handle specified.\n");
  568.             break;
  569.  
  570.         case AIO_FAILURE:
  571.           printf("ERROR:  AIOConfigurePort() failed.\n");
  572.             break;
  573.  
  574.         case AIO_QUALIFIED_SUCCESS:
  575.           printf("ERROR:  AIOConfigurePort() reported: Couldn't configure port exactly as requested.\n");
  576.           break;
  577.     
  578.         case AIO_PORT_GONE:
  579.           printf("ERROR:  AIOConfigurePort() reported: Port is gone.\n");
  580.           goto END;
  581.     
  582.         default:
  583.           printf("ERROR:  AIOConfigurePort() reported unknown error: %d.\n", cCode);
  584.           goto END;
  585.         }
  586.  
  587.    /*------------------------------------------------------------------------
  588.     **    Set DTR and RTS on
  589.     */
  590.    cCode=AIOSetExternalControl(
  591.         /*    I-    portHandle        */    portHandle,
  592.         /* I-    requestType        */    AIO_EXTERNAL_CONTROL,
  593.       /*    I- requestValue    */    AIO_EXTCTRL_DTR|AIO_EXTCTRL_RTS
  594.         );
  595.     switch(cCode)
  596.         {
  597.         case AIO_SUCCESS:
  598.             break;
  599.  
  600.         case AIO_BAD_HANDLE:
  601.           printf("ERROR:  AIOSetExternalControl() reported: Bad handle specified.\n");
  602.             break;
  603.  
  604.         case AIO_FAILURE:
  605.           printf("ERROR:  AIOSetExternalControl() failed.\n");
  606.             break;
  607.  
  608.         case AIO_FUNC_NOT_SUPPORTED:
  609.           printf("ERROR:  AIOSetExternalControl() reported: Function not supported.\n");
  610.           break;
  611.     
  612.         case AIO_INVALID_PARAMETER:
  613.           printf("ERROR:  AIOSetExternalControl() reported: Invalid parameter.\n");
  614.           break;
  615.     
  616.         case AIO_BAD_REQUEST_TYPE:
  617.           printf("ERROR:  AIOSetExternalControl() reported: Bad request type.\n");
  618.           break;
  619.     
  620.         case AIO_PORT_GONE:
  621.           printf("ERROR:  AIOSetExternalControl() reported: Port is gone.\n");
  622.           goto END;
  623.     
  624.         default:
  625.           printf("ERROR:  AIOSetExternalControl() reported unknown error: %d.\n", cCode);
  626.           goto END;
  627.         }
  628.  
  629.     /*------------------------------------------------------------------------
  630.     **    Set-up screen.
  631.     */
  632.     SetCursorCouplingMode(TRUE);
  633.     clrscr();
  634.     UpdateHelp();
  635.     SetCursorPosition(1,0);
  636.  
  637.     /*------------------------------------------------------------------------
  638.     **    Terminal operations loop.
  639.     */
  640.     while(1)
  641.         {
  642.         /*---------------------------------------------------------------------
  643.         **    Keyboard handler.
  644.         */
  645.         if(kbhit())
  646.             {
  647.             ch=getch();                            /* Get regular keystroke.    */
  648.             if(!ch) ch=getch() + 0x0100;    /* Get special keystroke.    */
  649.             if(ch == KEY_F1) break;              /* Exit terminal emulator.    */
  650.             if(ch == KEY_F2)                       /* Toggle ANSI emulation.    */
  651.                 {
  652.                 NLM_ansiMode = !NLM_ansiMode;
  653.                 UpdateHelp();
  654.                 continue;
  655.                 }
  656.  
  657.             ch &= 0x00FF;
  658.            cCode=AIOWriteData(
  659.                 /*    I-    portHandle                */    portHandle,
  660.                 /* I-    buffer                    */    (char *)&ch,
  661.                 /*    I-    lengthOfBuffer            */    1,
  662.                 /*    -O    numberOfBytesWritten    */    &count
  663.                 );
  664.             switch(cCode)
  665.                 {
  666.                 case AIO_SUCCESS:
  667.                     break;
  668.  
  669.                 case AIO_BAD_HANDLE:
  670.                   printf("ERROR:  AIOWriteData() reported: Bad handle specified.\n");
  671.                     break;
  672.  
  673.                 case AIO_FAILURE:
  674.                   printf("ERROR:  AIOWriteData() failed.\n");
  675.                     break;
  676.  
  677.                 case AIO_PORT_GONE:
  678.                   printf("ERROR:  AIOWriteData() reported: Port is gone.\n");
  679.                   goto END;
  680.  
  681.                 default:
  682.                   printf("ERROR:  AIOWriteData() reported unknown error: %d.\n", cCode);
  683.                   goto END;
  684.                 }
  685.  
  686.            /*------------------------------------------------------------------------
  687.             **    Make sure that everything was sent.
  688.             */
  689.            if(count < 1)
  690.                 {
  691.               printf("ERROR:  AIOWriteData() reported incomplete write. (0 bytes written)\n");
  692.                 goto END;
  693.                 }
  694.             }
  695.  
  696.         /*---------------------------------------------------------------------
  697.         **    AIO handler.
  698.         */
  699.       cCode=AIOReadStatus(
  700.             /* I-    portHandle    */    portHandle,
  701.             /*    I-    count            */    &count,
  702.             /*    -O    state            */    &state
  703.             );
  704.         switch(cCode)
  705.             {
  706.             case AIO_SUCCESS:
  707.                 break;
  708.  
  709.             case AIO_BAD_HANDLE:
  710.               printf("ERROR:  AIOReadStatus() reported: Bad handle specified.\n");
  711.                 break;
  712.  
  713.             case AIO_FAILURE:
  714.               printf("ERROR:  AIOReadStatus() failed.\n");
  715.                 break;
  716.  
  717.             case AIO_PORT_GONE:
  718.               printf("ERROR:  AIOReadStatus() reported: Port is gone.\n");
  719.               goto END;
  720.     
  721.             default:
  722.               printf("ERROR:  AIOReadStatus() reported unknown error: %d.\n", cCode);
  723.               goto END;
  724.             }
  725.  
  726.        if(count)
  727.             {
  728.            memset(buffer, 0x00, BUFFER_SIZE);
  729.            cCode=AIOReadData(
  730.                 /*    I-    portHandle            */    portHandle,
  731.                 /*    I-    buffer                */    buffer,
  732.                 /*    I-    lengthOfBuffer        */    BUFFER_SIZE,
  733.                 /*    -O    numberOfBytesRead    */    &count
  734.                 );
  735.             switch(cCode)
  736.                 {
  737.                 case AIO_SUCCESS:
  738.                     break;
  739.  
  740.                 case AIO_BAD_HANDLE:
  741.                   printf("ERROR:  AIOReadData() reported: Bad handle specified.\n");
  742.                     break;
  743.  
  744.                 case AIO_FAILURE:
  745.                   printf("ERROR:  AIOReadData() failed.\n");
  746.                     break;
  747.  
  748.                 case AIO_PORT_GONE:
  749.                   printf("ERROR:  AIOReadData() reported: Port is gone.\n");
  750.                   goto END;
  751.  
  752.                 default:
  753.                   printf("ERROR:  AIOReadData() reported unknown error: %d.\n", cCode);
  754.                   goto END;
  755.                 }
  756.         
  757.             for(x=0; x < count; ++x) ANSI_PutCh(buffer[x]);
  758.             }
  759.  
  760.         /*---------------------------------------------------------------------
  761.         **    Give someone else a turn to play in the sandbox.
  762.         */
  763.       ThreadSwitch();
  764.         }
  765.  
  766. END:
  767.  
  768.    /*------------------------------------------------------------------------
  769.     **    Release the port
  770.     */
  771.     if(portHandle != (-1))
  772.         {
  773.        cCode=AIOReleasePort(portHandle);
  774.         switch(cCode)
  775.             {
  776.             case AIO_SUCCESS:
  777.                 break;
  778.  
  779.             case AIO_BAD_HANDLE:
  780.               printf("ERROR:  AIOReleasePort() reported: Bad handle specified.\n");
  781.                 break;
  782.  
  783.             case AIO_FAILURE:
  784.               printf("ERROR:  AIOReleasePort() failed.\n");
  785.                 break;
  786.  
  787.             default:
  788.               printf("ERROR:  AIOReleasePort() reported unknown error: %d.\n", cCode);
  789.               goto END;
  790.             }
  791.         }
  792.  
  793.    return;
  794.     }
  795.  
  796.  
  797.