Anonymous avatar Anonymous committed 08102ca

Win cmd now with a forkexec, and added Xplor cmd as well. plumbing rules not needed anymore.

Comments (0)

Files changed (2)

plumbing

-# Add this rule to your plumbing rules, for example on top, 
-# right after the declarations of ports without rules. ymmv.
-#
-# start rc in a win at the specified path from xplor
-type is text
-src is xplor
-dst is win
-plumb start win rc -c '@{cd '$data'; exec rc -l}'
-
 	"strings"
 	"sort"
 	"flag"
+	"exec"
 	//	"bytes"
 
 	"goplan9.googlecode.com/hg/plan9"
 			doDotDot()
 			continue
 		}
+		if len(word) >= 3 && word[0:3] == "Win" {
+			if PLAN9 != "" {
+				cmd := path.Join(PLAN9, "bin/win")
+				doExec(word[3:len(word)], cmd)
+			}
+			continue
+		}
+// yes, this does not cover all possible cases. I'll do better if anyone needs it.
+		if len(word) >= 5 && word[0:5] == "Xplor" {
+			cmd, err := exec.LookPath("xplor")
+			if err != nil {
+				fmt.Fprintf(os.Stderr, err.String())
+				continue
+			}
+			doExec(word[5:len(word)], cmd)
+			continue
+		}
 		if word[0] == 'X' {
 			onExec(word[1:len(word)])
 			continue
 		}
-		if len(word) >= 3 {
-			if word[0:3] == "Win" {
-				doWin(word[3:len(word)])
-				continue
-			}
-		}
 		onLook(word)
 	}
 }
 
 	title := "xplor-" + root
 	w.Name(title)
-	tag := "DotDot Win"
+	tag := "DotDot Win Xplor"
 	w.Write("tag", []byte(tag))
 	_, err = printDirContents(root, 0)
 //	initCharToLine(len(newlines))
 	}
 }
 
+/*
+//TODO: read about defer
 // For this function to work as intended, it needs to be coupled with a
 // plumbing rule, such as:
 // # start rc from xplor in an acme win at the specified path 
 // src is xplor
 // dst is win
 // plumb start win rc -c '@{cd '$data'; exec rc -l}'
-func doWin(loc string) {
+func doPlumb(loc string, dst string) {
 	var fullpath string
 	if loc == "" {
 		fullpath = root
 		fmt.Fprintf(os.Stderr, err.String())
 		return
 	}
-	defer port.Close()
-	port.Send(&plumb.Msg{
+//	defer port.Close()
+	err = port.Send(&plumb.Msg{
 		Src:  "xplor",
-		Dst:  "win",
+		Dst:  dst,
 		WDir: "/",
 		Kind: "text",
 		Attr: map[string]string{},
 		Data: []byte(fullpath),
 	})
+	if err != nil {
+		fmt.Fprintf(os.Stderr, err.String())
+	}
+	port.Close()
+	return
+}
+*/
+
+func doExec(loc string, cmd string) {
+	var fullpath string
+	if loc == "" {
+		fullpath = root
+	} else {
+		var err os.Error
+		charaddr := strings.SplitAfter(loc, ",#", 2) 
+		fullpath, err = getFullPath(charaddr[1])
+		if err != nil {
+			fmt.Fprintf(os.Stderr, err.String())
+			return
+		}
+		fi, err := os.Lstat(fullpath)
+		if err != nil {
+			fmt.Fprintf(os.Stderr, err.String())
+			return
+		}
+		if !fi.IsDirectory() {
+			fullpath, _ = path.Split(fullpath)
+		}
+	}
+	var args []string = make([]string, 1)
+	args[0] = cmd
+	fds := []*os.File{os.Stdin, os.Stdout, os.Stderr}
+	_, err := os.ForkExec(args[0], args, os.Environ(), fullpath, fds)
+	if err != nil {
+		fmt.Fprintf(os.Stderr, err.String())
+		return 
+	}
 	return
 }
 
 						tmp = string(e.Loc)
 					}
 					c <- ("Win" + tmp)
+				case "Xplor":
+					tmp := ""
+					if e.Flag != 0 {
+						tmp = string(e.Loc)
+					}
+					c <- ("Xplor" + tmp)			
 				default:
 					w.WriteEvent(e)
 				}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.