#include #include #include #include main( int argc, char *argv[] ) { char eoi=' '; struct termio tbuf, tbufsave; extern char *optarg; extern int optind,opterr,optopt; int opcion; unsigned char theError=0; while ( (opcion=getopt(argc,argv,"c:")) != EOF ) { switch(opcion) { case 'c': eoi = *optarg; break; default: theError ++; break; } } if ( theError != 0 ) { fprintf( stderr, "Usage: %s -c end_of_input\n", argv[0]); exit(-1); } /* * set raw mode */ if( ioctl(0, TCGETA, &tbuf) == -1) { perror("ioctl 1"); exit( -1); } tbufsave = tbuf; tbuf.c_iflag &= ~( INLCR | ICRNL | IUCLC | ISTRIP | IXON | BRKINT ); tbuf.c_oflag &= ~OPOST; tbuf.c_lflag &= ~( ICANON | ISIG | ECHO ); tbuf.c_cc[4] = 0; tbuf.c_cc[5] = 1000000; if ( ioctl(0,TCSETAF, &tbuf ) == -1 ) { perror("ioctl 2"); exit( -1); } /* * cat */ for( ; putchar(getchar())!=eoi; ) ; /* * restore mode */ if( ioctl( 0, TCSETAF,&tbufsave) == -1) { perror("ioctl 3"); exit( -1); } exit( 0 ); }