#include /** * CTLSEQ -- control sequence cat-like program * Copyright (C) 2007 Matous Jan Fialka * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see * . */ void eot(void) { exit(0); } /** * CHAR ASCII HEX MEANING * * [@] NUL 00 * [A] SOH 01 * [B] STX 02 * [C] ETX 03 * [D] EOT 04 end of transmission (passive) * [E] ENQ 05 * [F] ACK 06 * [G] BEL 07 * [H] BS 08 back space * [I] HT 09 * [J] LF 0a * [K] VT 0b * [L] FF 0c * [M] CR 0d * [N] SO 0e * [O] SI 0f * [P] DLE 10 * [Q] DC1 11 * [R] DC2 12 * [S] DC3 13 * [T] DC4 14 * [U] NAK 15 * [V] SYN 16 * [W] ETB 17 * [X] CAN 18 * [Y] EM 19 * [Z] SUB 1a * [\[] ESC 1b * [\\] FS 1c * [\]] GS 1d * [\^] RS 1e * [\_] US 1f * [\?] DEL 7f delete */ int mk_cs(int c) { if (c >= 0x40 && c <= 0x5f) return (c - 0x40); if (c == 0x3f) return (0x7f); return (c); } /** * CHAR ASCII HEX MEANING * * [0] NUL 00 * [q] EOT 04 end of transmission (active) * [a] BEL 07 * [b] BS 08 back space * [t] HT 09 * [n] LF 0a * [v] VT 0b * [f] FF 0c * [r] CR 0d * [e] ESC 1b * [d] DEL 7f delete */ int mk_ic(int c) { if (c == 0x30) return (0x00); if (c == 0x71) eot(); if (c == 0x61) return (0x07); if (c == 0x62) return (0x08); if (c == 0x74) return (0x09); if (c == 0x6e) return (0x0a); if (c == 0x76) return (0x0b); if (c == 0x66) return (0x0c); if (c == 0x72) return (0x0d); if (c == 0x65) return (0x1b); if (c == 0x64) return (0x1f); return (c); } int is_qc(int c) { return (c == 0x5c); } int is_csc(int c) { return (c == 0x5e); } int main(void) { int c; while ((c = fgetc(stdin)) != EOF) { if (is_csc(c)) { if ((c = fgetc(stdin)) != EOF) { fputc(mk_cs(c), stdout); continue; } break; } if (is_qc(c)) { if ((c = fgetc(stdin)) != EOF) { fputc(mk_ic(c), stdout); continue; } break; } fputc(c, stdout); } eot(); }