[comp.unix.wizards] Icons, pipes, etc.

throopw@xyzzy.UUCP (Wayne A. Throop) (07/29/87)

(This is being cross-posted to comp.unix.wizards, for the more wizardly
 denizens of that group to check my "solution" and acompanying assertion,
 but followups have been directed back to comp.windows.misc only.)

> peter@sugar.UUCP (Peter da Silva)
> [...] you can describe some pipelines graphically that you would have a great
> deal of trouble expressing on a command line.
>
> (awk)_______                                 _(one set of lines)
>             \__(sort both together)|(grep2)_/
> (sort|grep)_/                               \_(another set of lines)
> 
> Every now and then I come across something wierd like this I want to do.
> I usually end up making temp files. Wasn't that the whole point of pipes
> in the first place?

I disagree that it is all that hard.  Assuming that you have a sort
program that reads from descriptors 3 and 4 for the "sort both
together", and that you have a grep that writes on descriptors 3 and 4
to generate multiple outputs, it is rendered:

        (awk)|3<&0((sort|grep)|4<&0 sort2)|grep2 3>one 4>another

This doesn't seem all that arcane to me.  Further, it can even be done
with the standard unix tools, without the sort2 and grep2 processes,
assuming that we have a "tee" that writes to descriptor 2 when given no
arguments.  (I have such a modified tee, since I find this convenient
behavior for debugging simple pipelines.)  Here it is:

        ((awk);(sort|grep))|sort|(tee|grep x >one&)2<&1|grep y >another

Again, though this *is* arcane, it is not all *that* arcane, though in
this case we have forced the awk and the sort|grep to be sequential,
though this is not necessary.  To get the awk and the sort|grep up front
to run concurrently needs the special sort2 process or some general
purpose line-oriented wye fitting, but this is perfectly straightforward.

Assuming that the programs in the system co-operate by writing to as
many output descriptors as necessary for tee junctions, and reading from
as many as necessary for wye junctions, I think any directed acyclic
graph of dataflow can be constructed out of unix pipes and such
processes (subject only to the number of available file descriptors).  I
haven't rigorously proven this, but I'd be mildly surprised to be wrong.

Further, sysV named pipes can easily be used to solve cases with less
tractable programs (which want to be fed filenames instead of
descriptors, such as the real tee).  Using named pipes and an unmodified
tee, the example might be

        p=/tmp/pipe$$.1
        /etc/mknod $p p
        ((awk);sort|grep))|sort|(tee $p|grep x >one)&grep y $p >another
        rm $p

> You would end up with an extremely powerful dataflow programming
> system.

Shell-ese already seems pretty powerful to me.  Of course, it may not be
as conveniant or user-friendly as it might be, but it *is* powerful, and
it doesn't seem all *that* arcane.

--
"You have 15 seconds to comply."
                        --- out-of-control robot from RoboCop
-- 
Wayne Throop      <the-known-world>!mcnc!rti!xyzzy!throopw