CR defeat

gwyn%brl-vld at sri-unix.UUCP gwyn%brl-vld at sri-unix.UUCP
Fri Nov 18 09:37:20 AEST 1983


From:      Doug Gwyn (VLD/VMB) <gwyn at brl-vld>

You have not described the system behavior correctly.  The only time
a CR is supplied before a newline (LF) is when the output is via the
terminal driver and the appropriate ioctl bit is on.  On older UNIXes,
this was coupled to the input mapping of CR to newline, using the
CRMOD bit in the sg_flags member of the sgttyb struct; on newer UNIXes,
input and output CR,LF handling are separately available by flag bits
in the termio struct.

For example, on UNIX System V (or, in your case, the BRL emulation
thereof) the following C routine will turn off the CR before LF, and
a similar routine would turn it on.  You can also do this with the
"stty" command if you need it in a shell script.

#include	<stdio.h>
#include	<termio.h>

NoCR()				/* disables CR before LF on stdout */
	{
	struct termio	tbuf;

	if ( ioctl( fileno( stdout ), TCGETA, (int)&tbuf ) == 0 )
		{
		tbuf.c_oflag &= ~ONLCR;
		(void)ioctl( fileno( stdout ), TCSETAW, (int)&tbuf );
		}
	}



More information about the Comp.unix mailing list