home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / TERM_IO.C < prev    next >
Text File  |  1992-01-04  |  2KB  |  113 lines

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