Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* callsites: generate_stream_from_list, run_and_free_list, pseudo_exec, run_pipe */
2008-07-14
Command parsing
Command parsing results in a list of "pipe" structures.
This list correspond not only to usual "pipe1 || pipe2 && pipe3"
lists, but it also controls execution of if, while, etc statements.
Every such statement is a list for hush. List consists of pipes.
struct pipe fields:
smallint res_word - "none" for normal commands,
"if" for if condition etc
struct child_prog progs[] - array of commands in pipe
smallint followup - how this pipe is related to next: is it
"pipe; pipe", "pipe & pipe" "pipe && pipe",
"pipe || pipe"?
Blocks of commands { pipe; pipe; } and (pipe; pipe) are represented
as one pipe struct with one progs[0] element which is a "group" -
struct child_prog can contain a list of pipes. Sometimes these
"groups" are created implicitly, e.g. every control
statement (if, while, etc) sits inside its own group.
res_word controls statement execution. Examples:
"echo Hello" -
pipe 0 res_word=NONE followup=SEQ prog[0] 'echo' 'Hello'
pipe 1 res_word=NONE followup=SEQ
"echo foo || echo bar" -
pipe 0 res_word=NONE followup=OR prog[0] 'echo' 'foo'
pipe 1 res_word=NONE followup=SEQ prog[0] 'echo' 'bar'
pipe 2 res_word=NONE followup=SEQ
"if true; then echo Hello; true; fi" -
res_word=NONE followup=SEQ
prog 0 group {}:
pipe 0 res_word=IF followup=SEQ prog[0] 'true'
pipe 1 res_word=THEN followup=SEQ prog[0] 'echo' 'Hello'
pipe 2 res_word=THEN followup=SEQ prog[0] 'true'
pipe 3 res_word=FI followup=SEQ
pipe 4 res_word=NONE followup=(null)
pipe 1 res_word=NONE followup=SEQ
Above you see that if is a list, and it sits in a {} group
implicitly created by hush. Also note two THEN res_word's -
it is explained below.
"if true; then { echo Hello; true; }; fi" -
pipe 0 res_word=NONE followup=SEQ
prog 0 group {}:
pipe 0 res_word=IF followup=SEQ prog[0] 'true'
pipe 1 res_word=THEN followup=SEQ
prog 0 group {}:
pipe 0 res_word=NONE followup=SEQ prog[0] 'echo' 'Hello'
pipe 1 res_word=NONE followup=SEQ prog[0] 'true'
pipe 2 res_word=NONE followup=SEQ
pipe 2 res_word=NONE followup=(null)
pipe 1 res_word=NONE followup=SEQ
"for v in a b; do echo $v; true; done" -
pipe 0 res_word=NONE followup=SEQ
prog 0 group {}: