Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cmu-cs-k.ARPA Path: utzoo!linus!decvax!genrad!teddy!panda!talcott!harvard!seismo!rochester!cmu-cs-pt!cmu-cs-k!tim From: tim@cmu-cs-k.ARPA (Tim Maroney) Newsgroups: net.sources Subject: Re: Roff in C (blank lines & leading spaces) Message-ID: <20980045@cmu-cs-k.ARPA> Date: Mon, 31-Dec-84 17:58:16 EST Article-I.D.: cmu-cs-k.20980045 Posted: Mon Dec 31 17:58:16 1984 Date-Received: Tue, 1-Jan-85 06:25:34 EST References: <1155@ut-ngp.UUCP> Organization: Carnegie-Mellon University, CS/RI Lines: 101 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()." It is well named. Leading > spaces do not cause a line break since the logic to do this is missing. > Blank lines disappear. Doubtless there are other bugs as well. > > Pity. Would have been useful. 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. However, he was right that blank lines and lines with leading spaces do not create the desired effect. Fortunately, this is easy to fix. Here is the new version of the function readline() which provides the desired functionality. Just replace the old version of the function with this. readline() { int startline, doingword; isrequest = 0; startline = 1; doingword = 0; c=suck(); if (c == '\n') { o_sp = 1; writebreak(); goto out; } else if (isspace(c)) writebreak(); for (;;) { if (c==EOF) { if (doingword) bumpword(); break; } if (c!=o_cc && o_ig) { while (c!='\n' && c!=EOF) c=suck(); break; } if (isspace(c) && !doingword) { startline=0; switch (c) { case ' ': assyline[assylen++]=' '; break; case '\t': tabulate(); break; case '\n': goto out; } c = suck(); continue; } if (isspace(c) && doingword) { bumpword(); if (c=='\t') tabulate(); else if (assylen) assyline[assylen++]=' '; doingword=0; if (c=='\n') break; } if (!isspace(c)) { if (doingword) *holdp++ = o_ul? c|UNDERL: c; else if (startline && c==o_cc && !o_li) { isrequest=1; return readreq(); } else { doingword=1; holdp=holdword; *holdp++ = o_ul? c|UNDERL: c; } } startline=0; c = suck(); } out: if (o_ul) o_ul--; center=o_ce; if (o_ce) o_ce--; if (o_li) o_li--; return c!=EOF; } Now what roff really needs is to separate the UNIX dependencies from the rest of the code, and to add font support. I intend to use it with the smallc compiler on CP/M. When I finish converting it, I will post the smallc version here. -=- Tim Maroney, Carnegie-Mellon University Computation Center ARPA: Tim.Maroney@CMU-CS-K uucp: seismo!cmu-cs-k!tim CompuServe: 74176,1360 audio: shout "Hey, Tim!" "Remember all ye that existence is pure joy; that all the sorrows are but as shadows; they pass & are done; but there is that which remains." Liber AL, II:9.