home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part04 / line_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.1 KB  |  100 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. #include "status.h"
  10.  
  11. void
  12. line_set()
  13. {
  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 (status->fd == -1)
  29.         return;
  30.                     /* get the current settings */
  31.     ioctl(status->fd, TCGETA, &tbuf);
  32.                     /* set some beginning values */
  33.     tbuf.c_cc[4] = 1;
  34.     tbuf.c_cc[5] = 0;
  35.     tbuf.c_oflag = 0;
  36.     tbuf.c_iflag = 0;
  37.     tbuf.c_cflag = (CREAD|HUPCL);
  38.     tbuf.c_lflag = 0;
  39.  
  40.     /*
  41.      * I don't think there's any need for output flow control... (I don't
  42.      * know about you guys, but I can't type faster than the host can
  43.      * receive!)  Besides, the file transfers reset this anyway.
  44.      */
  45.     if (*param->flow == 'X')
  46.         tbuf.c_iflag |= IXOFF;
  47.                     /* strip high bit ? */
  48.     if (*param->strip == 'Y')
  49.         tbuf.c_iflag |= ISTRIP;
  50.                     /* the baud rate */
  51.     switch (dir->baud[dir->d_cur]) {
  52.         case 300:
  53.             tbuf.c_cflag |= B300;
  54.             break;
  55.         case 1200:
  56.             tbuf.c_cflag |= B1200;
  57.             break;
  58.         case 2400:
  59.             tbuf.c_cflag |= B2400;
  60.             break;
  61.         case 4800:
  62.             tbuf.c_cflag |= B4800;
  63.             break;
  64.         case 9600:
  65.             tbuf.c_cflag |= B9600;
  66.             break;
  67.         case 19200:
  68.             /*
  69.              * Be careful here... some systems use EXTA in lieu
  70.              * of B19200.
  71.              */
  72.             tbuf.c_cflag |= B19200;
  73.             break;
  74.     }
  75.                     /* the parity */
  76.     switch (dir->parity[dir->d_cur]) {
  77.         case 'N':
  78.             break;
  79.         case 'O':
  80.             tbuf.c_cflag |= (PARENB|PARODD);
  81.             break;
  82.         case 'E':
  83.             tbuf.c_cflag |= PARENB;
  84.             break;
  85.     }
  86.                     /* the data bits */
  87.     if (dir->dbits[dir->d_cur] == 8)
  88.         tbuf.c_cflag |= CS8;
  89.     else
  90.         tbuf.c_cflag |= CS7;
  91.                     /* the stop bits */
  92.     if (dir->sbits[dir->d_cur] == 2)
  93.         tbuf.c_cflag |= CSTOPB;
  94.  
  95.                     /* now set 'em! */
  96.     ioctl(status->fd, TCSETA, &tbuf);
  97.     ioctl(status->fd, TCFLSH, 2);
  98.     return;
  99. }
  100.