/* so.c - A simple shift-in/shift-out filter. Reads from standard input, writes to standard output. Input is text encoded in an 8-bit character set. Output is 7-bit text with imbedded and sequences. F. da Cruz, Columbia University, 1991. */ #include main() { int i = 0; /* Int version of current character */ unsigned char c; /* Char version of current char */ int state = 0; /* Shift In/Out state */ char *latin1 = "\033-A"; /* ISO 2022: designate Latin1 to G1 */ /* printf("%s", latin1); */ /* Uncomment if necessary */ while ((i = getchar()) != EOF) { /* Get a character, test for end. */ c = i; /* Convert to character. */ if (c > 127) { /* If an 8-bit character */ if (state == 0) { /* and we're not shifted */ putchar('\16'); /* Output SO = Ctrl-N */ state = 1; /* Change state to shifted */ } } else if (state == 1) { /* 7-bit character and shifted */ putchar('\17'); /* Output SI = Ctrl-O */ state = 0; /* Change state to unshifted */ } putchar(c & 127); /* Now output the character itself */ } /* (low-order 7 bits only) */ }