Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ut-ngp.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxj!mhuxr!ulysses!allegra!mit-eddie!genrad!teddy!panda!talcott!harvard!seismo!ut-sally!ut-ngp!bph From: bph@ut-ngp.UUCP (hine, butler) Newsgroups: net.lang.c Subject: Re: Roff in C (moved from net.sources) Message-ID: <1158@ut-ngp.UUCP> Date: Tue, 1-Jan-85 15:40:02 EST Article-I.D.: ut-ngp.1158 Posted: Tue Jan 1 15:40:02 1985 Date-Received: Thu, 3-Jan-85 03:48:21 EST Organization: U.Texas Computation Center, Austin, Texas Lines: 47 [] >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."