home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / XBBS7200.ZIP / XBBS7200.TAR / chatbbs / chat.h next >
Encoding:
C/C++ Source or Header  |  1987-09-20  |  1.0 KB  |  57 lines

  1. #include <termio.h>
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #define lowbyte(w) ((w) & 0377)
  6. #define highbyte(w) lowbyte((w)>>8)
  7. #define EMPTY '\0'
  8. typedef enum {
  9.     FALSE, TRUE
  10. }               BOOLEAN;
  11. static char     cbuf = EMPTY;
  12. static struct termio tbufsave;
  13.  
  14. syserr(msg)
  15.     char           *msg;
  16. {
  17.     extern int      errno, sys_nerr;
  18.     extern char    *sys_errlist[];
  19.  
  20.     fprintf(stderr, "ERROR:%s (%d", msg, errno);
  21.     if (errno > 0 && errno < sys_nerr)
  22.         fprintf(stderr, ";%s)\n", sys_errlist[errno]);
  23.     else
  24.         fprintf(stderr, ")\n");
  25.     exit(1);
  26. }
  27. fatal(msg)
  28.     char           *msg;
  29. {
  30.     fprintf(stderr, "ERROR:%s\n", msg);
  31.     exit(1);
  32. }
  33.  
  34. setraw()
  35. {
  36.     struct termio   tbuf;
  37.     if (ioctl(0, TCGETA, &tbuf) == -1)
  38.         syserr("ioctl");
  39.     tbufsave = tbuf;
  40.     tbuf.c_iflag = 0;
  41.     tbuf.c_iflag |= IXON;
  42.     tbuf.c_iflag |= IXANY;
  43.  
  44.     tbuf.c_oflag &= ~OPOST;
  45.     tbuf.c_lflag &= ~(ICANON | ISIG | ECHO);
  46.     tbuf.c_cc[4] = 1;
  47.     tbuf.c_cc[5] = 0;
  48.     if (ioctl(0, TCSETAF, &tbuf) == -1)
  49.         syserr("ioctl2");
  50. }
  51.  
  52. restore()
  53. {
  54.     if (ioctl(0, TCSETAF, &tbufsave) == -1)
  55.         syserr("ioctl3");
  56. }
  57.