execline
Software
www.skarnet.org
The runblock program
runblock's purpose is to help you write execline commands
in the execline language. It can only be used inside an execline
script. If the script has been given blocks as arguments, runblock
allows you to execute one of the blocks individually.
It also allows you to give those blocks as a set of arguments to
another command.
Interface
runblock [ -P ] [ -n argshift ] [ -r ] n cmd...
- runblock skips the first argshift positional
parameters. It does that to allow you to design commands that take simple
arguments and blocks.
- Then runblock looks for and parses
blocks in the positional parameters.
- If the -r option is present: runblock skips
n blocks and execs into the remaining arguments.
- Else it skips n-1 blocks and execs into the nth
one.
- If cmd... is not empty, then instead of directly executing the
block or the remainder, runblock appends the selected
set of arguments to the cmd... command line.
- Normally runblock pops
its environment frame before executing. If the -P option has
been given, it does not pop.
- Of course, if the block structure doesn't match, runblock
exits 100 with an error message.
Example: implementing the ifelse command
Suppose that we want to implement the ifelse command as
an execline script, using the ifte command.
runblock allows us to do it in a simple way:
#!/command/execlineb
ifte { runblock 2 } { runblock -r 2 } runblock 1
That's it.
Credits
The runblock idea, as well as the ifelse idea, comes
from Paul Jarc.