From 3613781db22d391dcf27ac6e38bb5b9d09c17a44 Mon Sep 17 00:00:00 2001 From: Cheer Xiao Date: Sat, 28 Sep 2013 11:29:52 +0800 Subject: [PATCH] eval: Change ExecCommand to take additional cmdType arg --- eval/exec.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/eval/exec.go b/eval/exec.go index 3d5a1bab..64d73ea7 100644 --- a/eval/exec.go +++ b/eval/exec.go @@ -14,6 +14,14 @@ const ( FD_NIL uintptr = ^uintptr(0) ) +type cmdType int + +const ( + externalCmd cmdType = iota + builtinCmd + functionCmd +) + func isExecutable(path string) bool { f, err := os.Open(path) if err != nil { @@ -186,7 +194,8 @@ func ExecPipeline(pl *parse.ListNode) (pids []int, err error) { haserr := false for i, cmd := range pl.Nodes { - pid, err := ExecCommand(cmd.(*parse.CommandNode)) + cmd := cmd.(*parse.CommandNode) + pid, err := ExecCommand(externalCmd, extractTexts(&cmd.ListNode), cmd.Redirs) if err != nil { pids[i] = -1 @@ -212,11 +221,9 @@ func extractTexts(ln *parse.ListNode) (texts []string) { } // ExecCommand executes a command. -func ExecCommand(cmd *parse.CommandNode) (pid int, err error) { - args := extractTexts(&cmd.ListNode) - +func ExecCommand(ct cmdType, args []string, redirs []parse.Redir) (pid int, err error) { files := []uintptr{0, 1, 2} - for _, r := range cmd.Redirs { + for _, r := range redirs { fd := r.Fd() switch r := r.(type) {