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

  1. /*
  2.   so.c - A simple shift-in/shift-out filter.
  3.  
  4.   Reads from standard input, writes to standard output.
  5.   Input is text encoded in an 8-bit character set.
  6.   Output is 7-bit text with imbedded <SO> and <SI> sequences.
  7.  
  8.   F. da Cruz, Columbia University, 1991.
  9. */
  10. #include <stdio.h>
  11.  
  12. main() {
  13.     int i = 0;                /* Int version of current character */
  14.     unsigned char c;            /* Char version of current char */
  15.     int state = 0;            /* Shift In/Out state */
  16.  
  17.     char *latin1 = "\033-A";        /* ISO 2022: designate Latin1 to G1 */
  18. /*  printf("%s", latin1); */            /* Uncomment if necessary */
  19.  
  20.     while ((i = getchar()) != EOF) {    /* Get a character, test for end. */
  21.     c = i;                /* Convert to character. */
  22.     if (c > 127) {            /* If an 8-bit character */
  23.         if (state == 0) {        /* and we're not shifted */
  24.         putchar('\16');        /* Output SO = Ctrl-N */
  25.         state = 1;        /* Change state to shifted */
  26.         }
  27.     } else if (state == 1) {    /* 7-bit character and shifted */
  28.         putchar('\17');        /* Output SI = Ctrl-O */
  29.         state = 0;            /* Change state to unshifted */
  30.     }
  31.     putchar(c & 127);        /* Now output the character itself */
  32.     }                    /* (low-order 7 bits only) */
  33. }
  34.