Path: utzoo!censor!geac!torsqnt!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!zephyr.ens.tek.com!tektronix!reed!reeder From: reeder@reed.UUCP (Doug Reeder) Newsgroups: comp.sys.apple2 Subject: pipes (implementation thereof) Message-ID: <14398@reed.UUCP> Date: 11 Mar 90 01:03:27 GMT References: <6673@hydra.gatech.EDU> <1990Mar5.234421.396@world.std.com> <2218@tellab5.tellabs.com> Reply-To: reeder@reed.UUCP (Doug Reeder) Organization: Institute of Knowledge, Jinx Lines: 43 IMHO, the best way to implement pipes is as follows: start the last program, and let it run along until it requests a character from the standard input from the OS. The OS then starts up the next to last program, and lets it run untill it sends a character to standard output (by making an OS call) The OS then switches back to the last program. If the next to last program requests a character from the standard input, the OS switches to the previous program, and runs it until it gets a character, and so on back through the chain. The advantage of this system is that you never have to interrupt a program (an important considerations on IIe's and +'s, which lack vertical blanking interrpts). The disadavantage is that you have to make a context shift for every character, unless you have multi-character reads and writes, which would be an excellent thing to have anyway. You ought to be able to make syscalls like the ProDOS READ and WRITE and NEWLINE anyway. Most often, pipes are used with filter programs, i.e. ones that take the input and transform it in some way (e.g. break lines longer than 80 characters, format it for a particular kind of printer, pass on only lines that contain a pattern). Filter programs can be written which run under present shells, by inserting themselves in the output stream, as in the following (hypothetical) example: PRINT CHR$(4);"PR#1" PRINT CHR$(4);"FORMAT,F3,A9" :REM BASIC.SYSTEM external command PRINT "Ladies and gentlemen, I stand before you to stand behind you, to tell you something I know nothing of..." ... PRINT CHR$(4);"NOFORMAT" :REM BASIC.SYSTEM external command PRINT CHR$(4);"PR#0" If your shell suppports I/O redirection in an easy-to-use fashion, you can manually pipe things: fold infile >midfile (send output to midfile) print