Roff in C (moved from net.sources)

hine, butler bph at ut-ngp.UUCP
Wed Jan 2 06:40:02 AEST 1985


[]
>The posting of the C version of roff created the following comment:

>> The posted version of this program does not work and was apparently
>> never tested.  As posted, any request at the beginning of a text file
>> causes the whole file to be skipped because of a logic error in the
>> basic input routine, called "suck()." ...

>The statement about an initial request gobbling the whole file is just plain
>false.  I have tested it with a few different requests as the first line of
>the text file, without any problems.  It would have been nice if the person
>had told us what request caused this error.

>Tim Maroney, Carnegie-Mellon University Computation Center

This difference of opinion points up a very interesting problem: in testing
the original "roff.c" I was not using the PCC compiler, but used two others
instead -- DeSmet's C88 and CI-C86 on an IBM PC.  Both behaved exactly the
same way -- *any* request (dot command) caused the input text to be discarded.
However, it does *not* have this effect under PCC, as Tim points out.  I found
out why:

Here's the offending code:
_____________________________________________________________________________
int
suck()
{
	for (;;) {
		c=getc(File);
		if (!iscntrl(c) && c!='\013' && c!='\f' && c!='\r') return c;
	}
}
____________________________________________________________________________

and here's how the manual defines "iscntrl()":

iscntrl             c is a delete character (0177) or ordinary
                    control character (less than 040).

BOTH of the stated compilers failed to interpret "ordinary" in the same way
as the PCC routine of the same name -- they return TRUE if the code is less
than octal 040.  As written, then, with this interpretation, newlines are
never returned, and the text is lost.  PCC, however, excludes newlines,
backspace codes, carriage return codes and a few others, presumably because
they are not "ordinary."  

This says something fairly awful about "portability."



More information about the Comp.lang.c mailing list