new 3plumb | 2012-09-07 |
---|
new - create a new subscript with process interface
[new VARNAME key1=val1 key2=val2 ...]
+-------+ X0 ---->| |----> Y0 X1 ---->| new |----> Y1 X2 ---->| |----> Y2 +-------+
New takes a plumb script described in variable VARNAME, parses it in a new transaction (with implicit flush at the end) and creates each process of the script prefixed with its own name (subscript prefix).Optionally a bunch of transaction-local variables (that will never end up in the global namespace) can be set up with extra key=val arguments to new. These can be used as parameters to the subscript.
After all the processes and internal piping are created, "env" fd references of the subscript are rebound to the pipes of the [new], leaveing [new] without any pipes. It is required that the all the env references of the subscript are bound - which means by the time start stage of the [new] is executed, it should have all the fds bound that is referenced from the subscript. Because of this requirement, it is usually not practical to use the env:* notation in subscripts.
Internal fd references of the subscript will be resolved with subscript prefix. In some situations the subscript needs to reference to fds in the global namespace. In this case the reference should start with a period, i.e. ".stderr:*" means stderr:* of the global namespace (the one usually provided by stdio(3plumb)), while "stderr:*" means the next free fd of process stderr defined within the subscript, which will be replaced by "PREFIX.stderr:*", where PREFIX is the subscript prefix. All fd references must be valid by the time the subscript is parsed.
There is no limitation on how many real or virtual processes, pipes, pipelines or even pipegraphs may be created by a subscript.
eof handling
N/A: depends on the subscript.blocking/flow control
N/A: depends on the subscript.buffering
N/A: depends on the subscript.
A generic singlechar split implementation:tokenize='env:0 | sp=[split sep= + $char] | af=[affix suffix= + $char] | env:1 ;' env:0 | colon=[new tokenize char=":"] | script={awk -f foo.awk} | env:1$tokenize contains the subscript that splits the input stream in records by $char and suffixes each record with $char. The subscript is reading its stdin (env:0) and is writing its stdout (env:1). The instantiation will create colon.sp and colon.af in the global namespace (as a separate transaction) and binds plumb's env:0 to colon.sp:0 and colon.af:1 to script:0. $char will be ":" while parsing the subscript.
new 3plumb | 2012-09-07 |
---|