home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / mselat.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  1KB  |  43 lines

  1. /* File msdlat.c */
  2.  
  3. /*
  4.   stdin/stdout filter for displaying 8-bit Latin Alphabet 1 files from UNIX
  5.   in the 7-bit environment on a DEC VT320 or compatible terminal, or with
  6.   PC software (such as MS-DOS Kermit 3.0) that emulates one, by (a) sending
  7.   the escape sequence that assigns the Latin-1 character set to G1, and
  8.   (b) sends Shift-In/Shift-Out codes around sequences of GR (8-bit) characters.
  9.  
  10.   Usage:  msdlat < file
  11.      Or:  command | msdlat
  12.  
  13.   Author: F. da Cruz, Columbia University, 1990
  14. */
  15. #include <stdio.h>
  16.  
  17. main() {
  18.     int i = 0;                /* Working variable */
  19.     int state = 0;            /* Current state: 7- or 8-bit output */
  20.     unsigned char c;            /* Character holder */
  21.     char *latin1 = "\033-A";        /* ISO Latin-1 designating sequence */
  22.  
  23.     printf("%s", latin1);        /* Assign Latin-1 to G1 */
  24.  
  25.     while (1) {                /* Loop per character. */
  26.     i = getchar();            /* Get a character. */
  27.     if (i == EOF) exit(0);        /* If no more, done. */
  28.     c = i;                /* Convert to character form. */
  29.     if (c > 127) {            /* If it's an 8-bit character */
  30.         if (state == 0) {        /* and we were doing 7-bit chars, */
  31.         state = 1;        /* Change state, */
  32.         putchar('\16');        /* and send a Shift-Out code. */
  33.         }
  34.     } else {            /* Otherwise it's 7-bit character */
  35.         if (state == 1) {        /* If we were in 8-bit state */
  36.         putchar('\17');        /* Send a Shift-In */
  37.         state = 0;        /* and change to 7-bit state. */
  38.         }
  39.     }
  40.     putchar(c & 127);        /* Send the character's low 7 bits */
  41.     }
  42. }
  43.