Article View: comp.protocols.appletalk
Article #6044Re: papif won't eat pipes
From: Jeff Stearns
Date: Wed, 03 Jan 1990 23:04
Date: Wed, 03 Jan 1990 23:04
70 lines
2504 bytes
2504 bytes
In article <1990Jan2.200830.22744@athena.mit.edu> kenton@space.mit.edu (Kenton C. Phillips) writes:
> I have CAP 5.0 running on a Sun (OS 3.5). I have found that papif works
> fine in the context
>
> papif <file
>
> but only gets the first several bytes when fed through a pipe...
--- I remember this bug; here's an excerpt from the RCS log of papif.c:
* Version 1.4 89/04/07 16:16:27 jeff
* Fix two major bugs, both in the passalong() function.
* Worst: it didn't work. It read from stdin but, due to missing braces
* around a while() loop, it never called write(). This prevented papif
* from working when its input was taken from a non-seekable device.
*
* Second bug, discovered while inspecting code: the "dangerous" loop
* which maps CR to LF doesn't increment all its pointers. Fixed that,
* but didn't test it.
--- My updated passalong() routine extracted from papif.c:
/*
* duplicate stdin with prefixed buffer
*
*/
passalong(prebuf, precnt, wantcnt)
char *prebuf;
int precnt;
int wantcnt;
{
register int cnt;
register char *p;
register int i;
char buf[BUFSIZ];
if (precnt < 0)
exit(lpd_ERRORS);
if (map_crtolf) {
for (i = 0; i < precnt; i++)
if (prebuf[i] == '\r')
prebuf[i] = '\n';
}
if (write(fileno(stdout), prebuf, precnt) < 0)
exit(lpd_ERRORS);
if (precnt < wantcnt)
exit(lpd_OK);
/*
* The distributed code contained TWO separate bugs in this while loop.
* Check carefully; there might be more! jeff@tc.fluke.com 7-Apr-89.
*/
while ((cnt = read(fileno(stdin), buf, sizeof(buf))) > 0) {
/* dangerous */
if (map_crtolf) {
for (i = 0, p = buf; i < cnt; i++, p++) {
if (*p == '\r')
*p = '\n';
}
}
if (write(fileno(stdout), buf, cnt) < 0)
exit(lpd_ERRORS);
}
exit(cnt < 0 ? lpd_ERRORS : lpd_OK);
}
--
Jeff Stearns John Fluke Mfg. Co, Inc. (206) 356-5064
jeff@tc.fluke.COM {uw-beaver,microsoft,sun}!fluke!jeff
Technical Details
Message-ID:
<13607@fluke.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!fluke!jeffReferences:
<1990Jan2.200830.22744@athena.mit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!fluke!jeff From: jeff@tc.fluke.COM (Jeff Stearns) Newsgroups: comp.protocols.appletalk Subject: Re: papif won't eat pipes Keywords: cap, papif Message-ID: <13607@fluke.COM> Date: 3 Jan 90 23:04:35 GMT References: <1990Jan2.200830.22744@athena.mit.edu> Sender: news@tc.fluke.COM Distribution: na Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 70