home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / pcl4c42 / term_io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-20  |  2.8 KB  |  122 lines

  1. /*** TERM_IO.C ***/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "pcl4c.h"
  7. #include "term_io.h"
  8. #include "ascii.h"
  9. #include "dos_io.h"
  10.  
  11. /*** Display status line ***/
  12.  
  13. #define INVERSE 0x70
  14. #define NORMAL  0x07
  15. #define RIGHTMOST 40
  16.  
  17. static unsigned char Attribute = INVERSE;
  18.  
  19. void SetAttribute(unsigned char Type)
  20. {Attribute = Type;
  21. }
  22.  
  23. void DisplayLine(char *MsgPtr, char *UserPtr, int UserLength)
  24. {static int right = RIGHTMOST;
  25.  int row;
  26.  int col;
  27.  int i;
  28.  char c;
  29.  int MsgLength;
  30.  row = GetRow();
  31.  col = GetCol();
  32.  Position(24,0);
  33.  /* display message */
  34.  MsgLength = strlen(MsgPtr);
  35.  for(i=0;i<MsgLength;i++)
  36.      {AttrWrite(*MsgPtr++,Attribute);
  37.       Position(24,(unsigned char)(i+1));
  38.      }
  39.  /* blank rest of menu bar */
  40.  for(i=MsgLength;i<right;i++)
  41.      {AttrWrite(' ',Attribute);
  42.       Position(24,(unsigned char)(i+1));
  43.      }
  44.  right = MsgLength;
  45.  /* want response from user ? */
  46.  if(UserPtr!=NULL)
  47.      {right = RIGHTMOST;
  48.       /* input text from user */
  49.       i = 0;
  50.       while(1)
  51.           {Position(24,(unsigned char)(MsgLength+i));
  52.            c = SioKeyRead();
  53.            if((c==ESC)||(c==CAN))
  54.                {UserPtr[0] = '\0';
  55.                 break;
  56.                }
  57.            if((c=='\r')||(MsgLength+i==RIGHTMOST))
  58.                {UserPtr[i] = '\0';
  59.                 break;
  60.                }
  61.            if((c==BS)&&(i>0))
  62.                {i--;
  63.                 Position(24,(unsigned char)(MsgLength+i));
  64.                 AttrWrite(' ',Attribute);
  65.                }
  66.            else
  67.                {/* save character & display on status line */
  68.                 UserPtr[i++] = c;
  69.                 AttrWrite(c,Attribute);
  70.                 if(i==UserLength)
  71.                     {/* user string done */
  72.                      UserPtr[i] = '\0';
  73.                      break;
  74.                     }
  75.                }
  76.           } /* end -- while */
  77.      } /* end -- if */
  78.  Position((unsigned char)row,(unsigned char)col);
  79. }
  80.  
  81. /*** display the error text ***/
  82.  
  83. void SayError(int Port, char *ptr)
  84. {char temp[81];
  85.  sprintf(temp,"ERROR! COM%d : %s",1+Port,ptr);
  86.  DisplayLine(temp,NULL,0);
  87.  printf("\n*** %s\n",temp);
  88.  /* cancel remote */
  89.  CharPut(Port,CAN);
  90.  CharPut(Port,CAN);
  91.  CharPut(Port,CAN);
  92. } /* end SayError */
  93.  
  94.  
  95. /*** output character to serial port ***/
  96.  
  97. int CharPut(int Port, char ch)
  98. {int rc;
  99.  /* transmit character */
  100.  rc = SioPutc(Port,ch);
  101.  if(rc<0)
  102.      {printf("SioPutc Error: COM%d: ",1+Port);
  103.       SioError(rc);
  104.       SioDone(Port);
  105.       exit(1);
  106.      }
  107.  return(rc);
  108. }
  109.  
  110. /*** receive character from serial port ***/
  111.  
  112. int CharGet(int Port, int Timeout)
  113. {int rc;
  114.  rc = SioGetc(Port,Timeout);
  115.  if(rc<-1)
  116.      {printf("SioGetc Error: COM%d: ",1+Port);
  117.       SioError(rc);
  118.       exit(1);
  119.      }
  120.  return(rc);
  121. }
  122.