home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part04 / line_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  1.9 KB  |  97 lines

  1. /*
  2.  * Change the communication line settings to the new values.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <termio.h>
  7. #include "dial_dir.h"
  8. #include "param.h"
  9.  
  10. void
  11. line_set()
  12. {
  13.     extern int fd;
  14.     struct termio tbuf;
  15.  
  16.     /*
  17.      * The manual dial entry also serves to store the previous
  18.      * line settings.  How else would the manual dial entry
  19.      * know what line setting to use?
  20.      */
  21.     if (dir->d_cur != 0) {
  22.         dir->baud[0] = dir->baud[dir->d_cur];
  23.         dir->parity[0] = dir->parity[dir->d_cur];
  24.         dir->dbits[0] = dir->dbits[dir->d_cur];
  25.         dir->sbits[0] = dir->sbits[dir->d_cur];
  26.     }
  27.                     /* nothing to do! */
  28.     if (fd == -1)
  29.         return;
  30.                     /* get the current settings */
  31.     ioctl(fd, TCGETA, &tbuf);
  32.                     /* set some beginning values */
  33.     tbuf.c_cc[4] = 1;        /* VMIN */
  34.     tbuf.c_cc[5] = 0;        /* VTIME */
  35.     tbuf.c_oflag = 0;
  36.     tbuf.c_iflag = 0;
  37.     tbuf.c_cflag = (CREAD|HUPCL|CLOCAL);
  38.     tbuf.c_lflag = 0;
  39.  
  40.     if (*param->flow == 'X')
  41.         tbuf.c_iflag |= IXON|IXOFF;
  42.                     /* strip high bit? */
  43.     if (*param->strip == 'Y')
  44.         tbuf.c_iflag |= ISTRIP;
  45.                     /* the baud rate */
  46.     switch (dir->baud[dir->d_cur]) {
  47.         case 300:
  48.             tbuf.c_cflag |= B300;
  49.             break;
  50.         case 1200:
  51.             tbuf.c_cflag |= B1200;
  52.             break;
  53.         case 2400:
  54.             tbuf.c_cflag |= B2400;
  55.             break;
  56.         case 4800:
  57.             tbuf.c_cflag |= B4800;
  58.             break;
  59.         case 9600:
  60.             tbuf.c_cflag |= B9600;
  61.             break;
  62.         case 19200:
  63. #ifdef B19200
  64.             tbuf.c_cflag |= B19200;
  65. #else /* B19200 */
  66. #ifdef EXTA
  67.             tbuf.c_cflag |= EXTA;
  68. #endif /* EXTA */
  69. #endif /* B19200 */
  70.             break;
  71.     }
  72.                     /* the parity */
  73.     switch (dir->parity[dir->d_cur]) {
  74.         case 'N':
  75.             break;
  76.         case 'O':
  77.             tbuf.c_cflag |= (PARENB|PARODD);
  78.             break;
  79.         case 'E':
  80.             tbuf.c_cflag |= PARENB;
  81.             break;
  82.     }
  83.                     /* the data bits */
  84.     if (dir->dbits[dir->d_cur] == 8)
  85.         tbuf.c_cflag |= CS8;
  86.     else
  87.         tbuf.c_cflag |= CS7;
  88.                     /* the stop bits */
  89.     if (dir->sbits[dir->d_cur] == 2)
  90.         tbuf.c_cflag |= CSTOPB;
  91.  
  92.                     /* now set 'em! */
  93.     ioctl(fd, TCSETA, &tbuf);
  94.     ioctl(fd, TCFLSH, 2);
  95.     return;
  96. }
  97.