summaryrefslogtreecommitdiff
path: root/shell/hush_doc.txt
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-14 06:29:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-14 06:29:38 +0000
commit395ae452165a607c6b5bc4623225516044619616 (patch)
tree00ceff4dcd3fc4604d9252003cf45dfb6cfbedc1 /shell/hush_doc.txt
parent17f02e79f407ff2311255981c191a1bf8b3a7ae0 (diff)
downloadbusybox-w32-395ae452165a607c6b5bc4623225516044619616.tar.gz
busybox-w32-395ae452165a607c6b5bc4623225516044619616.tar.bz2
busybox-w32-395ae452165a607c6b5bc4623225516044619616.zip
hush: delete unused field in struct child.
reinstate needed check for invalid syntax. document command parsing in hush_doc.txt.
Diffstat (limited to 'shell/hush_doc.txt')
-rw-r--r--shell/hush_doc.txt77
1 files changed, 77 insertions, 0 deletions
diff --git a/shell/hush_doc.txt b/shell/hush_doc.txt
index 973fe44c5..ec5dd00f2 100644
--- a/shell/hush_doc.txt
+++ b/shell/hush_doc.txt
@@ -1,3 +1,80 @@
12008-07-14
2
3 Command parsing
4
5Command parsing results in "pipe" structures. "Pipe" structure
6does not always correspond to what sh language calls "pipe",
7it also controls execution of if, while, etc statements.
8
9struct pipe fields:
10 smallint res_word - "none" for normal commands,
11 "if" for if condition etc
12 struct child_prog progs[] - array of commands in pipe
13 smallint followup - how this pipe is related to next: is it
14 "pipe; pipe", "pipe & pipe" "pipe && pipe",
15 "pipe || pipe"?
16
17Blocks of commands { pipe; pipe; } and (pipe; pipe) are represented
18as one pipe struct with one progs[0] element which is a "group" -
19struct child_prog can contain a list of pipes. Sometimes these
20"groups" are created implicitly, e.g. every control
21statement (if, while, etc) sits inside its own "pipe" struct).
22
23res_word controls statement execution. Examples:
24
25"echo Hello" -
26pipe 0 res_word=NONE followup=SEQ prog[0] 'echo' 'Hello'
27pipe 1 res_word=NONE followup=1 SEQ
28
29"echo foo || echo bar" -
30pipe 0 res_word=NONE followup=OR prog[0] 'echo' 'foo'
31pipe 1 res_word=NONE followup=SEQ prog[0] 'echo' 'bar'
32pipe 2 res_word=NONE followup=SEQ
33
34"if true; then echo Hello; true; fi" -
35res_word=NONE followup=SEQ
36 prog 0 group {}:
37 pipe 0 res_word=IF followup=SEQ prog[0] 'true'
38 pipe 1 res_word=THEN followup=SEQ prog[0] 'echo' 'Hello'
39 pipe 2 res_word=THEN followup=SEQ prog[0] 'true'
40 pipe 3 res_word=FI followup=SEQ
41 pipe 4 res_word=NONE followup=(null)
42pipe 1 res_word=NONE followup=SEQ
43
44"if true; then { echo Hello; true; }; fi" -
45pipe 0 res_word=NONE followup=SEQ
46 prog 0 group {}:
47 pipe 0 res_word=IF followup=SEQ prog[0] 'true'
48 pipe 1 res_word=THEN followup=SEQ
49 prog 0 group {}:
50 pipe 0 res_word=NONE followup=SEQ prog[0] 'echo' 'Hello'
51 pipe 1 res_word=NONE followup=SEQ prog[0] 'true'
52 pipe 2 res_word=NONE followup=SEQ
53 pipe 2 res_word=NONE followup=(null)
54pipe 1 res_word=NONE followup=1 SEQ
55
56"for v in a b; do echo $v; true; done" -
57pipe 0 res_word=NONE followup=SEQ
58 prog 0 group {}:
59 pipe 0 res_word=FOR followup=SEQ prog[0] 'v'
60 pipe 1 res_word=IN followup=SEQ prog[0] 'a' 'b'
61 pipe 2 res_word=DO followup=SEQ prog[0] 'echo' '$v'
62 pipe 3 res_word=DO followup=SEQ prog[0] 'true'
63 pipe 4 res_word=DONE followup=SEQ
64 pipe 5 res_word=NONE followup=(null)
65pipe 1 res_word=NONE followup=SEQ
66
67Note how "THEN" and "DO" does not just mark the first pipe,
68it "sticks" to all pipes in the body. This is used when
69hush executes parsed pipes.
70
71Dummy trailing pipes with no commands are artifacts of imperfect
72parsing algorithm - done_pipe() appends new pipe struct beforehand
73and last one ends up empty and unused.
74
75
762008-01
77
1 This is how hush runs commands: 78 This is how hush runs commands:
2 79
3/* callsite: process_command_subs */ 80/* callsite: process_command_subs */