home *** CD-ROM | disk | FTP | other *** search
/ What PC? 1996 April / WHAT_PC_APR_96.ISO / internet / twinsock / src / pterm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  1.3 KB  |  55 lines

  1. /*Portable POSIX replacement for term.c*/
  2.  
  3. #include <termios.h>
  4. #include <stdio.h>
  5.  
  6. static struct   termios Old;
  7. static struct   termios New;
  8.  
  9. void InitTerm(void)
  10. {
  11.     if(tcgetattr(0, &Old)<0)                /*get current term attributes*/
  12.     {
  13.         perror("tcgetattr");
  14.         exit(1);
  15.     }
  16.  
  17.     New=Old;                                /*in case nonstandard fields*/
  18.  
  19.     /* This did have XON/XOFF flow control set.
  20.      * This is genrally a bad idea when using a complex protocol - a character
  21.      * might get corrupted to XOFF, at which point you must reset the application,
  22.      * because the host hend won't respond until it gets an XON.
  23.      */
  24.     New.c_iflag = 0;
  25.  
  26.     New.c_oflag = 0;
  27.     New.c_cflag = CREAD|CS8|HUPCL;
  28.     New.c_lflag = 0;
  29.  
  30.     New.c_cc[VSTOP] = '\023';               /*XOFF*/
  31.     New.c_cc[VSTART] = '\021';              /*XON*/
  32.     New.c_cc[VMIN]= 255;                    /*max*/
  33.     New.c_cc[VTIME]= 1;                     /*0.1 second*/
  34.  
  35.     cfsetispeed(&New, cfgetispeed(&Old));   /*preserve old baud rate*/
  36.     cfsetospeed(&New, cfgetospeed(&Old));
  37.  
  38.     if(tcsetattr(0, TCSAFLUSH, &New)<0)     /*set new attributes*/
  39.     {
  40.         perror("tcsetattr");
  41.         exit(1);
  42.     }
  43. }
  44.  
  45. void UnInitTerm(void)
  46. {
  47.     if(tcsetattr(0, TCSAFLUSH, &Old)<0)     /*restore old attributes*/
  48.     {
  49.         perror("tcsetattr");
  50.         exit(1);
  51.     }
  52. }
  53.  
  54.  
  55.