/*
*
* [jmason note: from the
[email protected] list]
* a simple filter
* to convert linefeed end-of-line characters (the UNIX default)
* to carriage-return/linefeed sequences (the MS-DOS default).
*
* Programm zum Anh"angen von CR+LF an Zeilenende
* Geschrieben: 20.07.1992
* Autor: Stefano Ianigro <
[email protected]>
*
* Patrick Powell Wed Aug 16 08:19:41 PDT 1995
* Compile with -DOF_FILTER to use as an OF as well as IF filter.
* or invoke with -Fo
*/
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
char filter_stop[] = "\031\001"; /* sent to cause filter to suspend */
int state;
int OF_filter;
int main(int argc, char **argv)
{
int c, flag;
char *arg, *parm;
/* run through the options, looking for -Fo' */
for( c = 1; c < argc; ++c ){
arg = argv[c];
if( arg[0] == '-' ){
flag = arg[1];
parm = arg+2;
if( flag == 'c' ) continue;
if( parm[0] == 0 ){
++c;
parm = argv[c];
}
switch( flag ){
case 'F': OF_filter = (parm[0] == 'o');
printf( "OF found %d", OF_filter );
}
}
}
while ( ( c = getchar() ) != EOF ){
if( OF_filter ){
if( state ){
if( c == filter_stop[1] ){
fflush(stdout);
kill(getpid(), SIGSTOP);
continue;
} else {
putchar( filter_stop[0] );
}
state = 0;
} else if( c == filter_stop[0] ){
state = 1;
continue;
}
}
if( c == '\n' || c == '\014' ) {
putchar ( '\r' );
}
putchar( c );
}
return(0);
}