#include #include #include int main() { struct termio old, new; fputs("secho v1.1\n",stderr); fputs("Type INTR (usually DEL) to exit this program\n",stderr); /* save current terminal settings */ if (ioctl(0,TCGETA,&old) == -1) { perror("ioctl"); return 1; } /* turn off all system character processing */ new = old; new.c_iflag &= ~(INLCR | IGNCR | ICRNL); new.c_lflag &= ~(ICANON | ECHO | ISIG); new.c_cc[VMIN] = 1; new.c_cc[VTIME] = 0; /* tell system about new settings */ if (ioctl(0,TCSETAW,&new) == -1) { perror("ioctl"); return 1; } /* read incoming characters and write printable versions */ for (;;) { int i = getchar(); if (i == old.c_cc[VINTR]) break; if (isascii(i) && isprint(i)) putchar(i); else if (i < 32) printf("^%c",i + '@'); else if (i == 127) printf("^?"); else printf("\\%o",i); if (i == '\n') putchar(i); } /* restore terminal settings and exit */ ioctl(0,TCSETAW,&old); return 0; }