\\ *** Pipes as In and Output *** 01mar92py Pipes sind ein typisches Kommunikationsmittel in Unix. Sie werden als sequenzielles Terminal betrachtet. \ Pipes 02mar93py Module Pipes Memory also pipes \ { writer | reader | low | high | wsb | rsb | delim.w | Data } 1 5 +thru toss pipes export Pipes peot? pdelim! Pipe Pipe| |Pipe ; Module; \ pipe 19apr95pyUser pipe> off | $1000 Constant b/pipe \ 4 KByte Pipes langen aus... | : pipemod [ b/pipe 1- ] Literal and ; hmacro | : pipe@ ( pipe -- low high ) @ 8 + 2@ ; hmacro | : pipe' ( pipe -- addr ) @ $14 + ; hmacro | : piper@ ( -- addr len ) IF under - >r exit THEN nip >r - ; | : writerwake r @ + pipemod r> ! THEN ; | : rstop -1 r dup BEGIN BEGIN piper@ r@ min r 2dup r> scan nip ?dup IF rdrop - dup >r 1 piper+ THEN THEN >r over r@ move r@ piper+ r> r> swap /string dup WHILE pkey? 0= IF peot? ?LEAVE rstop THEN >r REPEAT DONE drop - negate ; Input: pipein pkey pkey? noop paccept peot? [ \ pipe output 02mar92py | : pipew@ ( -- addr len ) pipe> @ pipe@ 2dup < IF over >r - invert pipe> @ pipe' r> + swap exit THEN drop >r pipe> @ pipe' r@ + b/pipe r> - pipe> @ @ 8 + @ 0= + ; | : readerwake pipe> @ @ $11 + c@ IF 0 pipe> @ @ $11 + c! pipe> @ @ cell + @ wake THEN ; | : pipew+ ( len -- ) ?dup IF readerwake pipe> @ @ $C + dup >r @ + pipemod r> ! THEN ; | : wstop -1 pipe> @ @ $10 + c! stop ; \ pipe output 19apr95py : pemit? ( -- flag ) pipew@ nip 0<> ; : pemit ( key -- ) BEGIN pipew@ 0= WHILE drop wstop REPEAT c! 1 pipew+ ; : ptype ( addr len -- ) >r BEGIN dup pipew@ r@ min dup pipew+ dup >r move r> r> swap /string dup WHILE >r pipew@ nip 0= IF wstop THEN REPEAT 2drop ; : pcr pipe> @ @ $12 + wx@ dup 0< IF drop ELSE pemit THEN ; : peot pipe> @ @ off readerwake pipe> off input @ standardi/o input ! ; Output: pipeop pemit pemit? pcr ptype noop pcr 2drop 0. PCform noop peot noop noop noop noop noop noop noop [ \ Create pipe 02mar93py : pdelim! ( delim -- ) pipe> @ @ $12 + w! ; : pipe>! ( pipe -- ) dup >r pipe> ! up@ r> @ ! pipeop ; : r @ cell+ ! pipein ; : Pipe ( -- pipe ) [ b/pipe $14 + ] Literal dup NewHandle dup >r @ swap erase #lf r@ @ $12 + w! r> ; : Pipe| ( parm parm# xt task -- ) >r Pipe dup pipe>! rot 2+ r> pass r Pipe dup pass pipe>! execute eot ;