Esempio n. 1
0
// Runs the commands given by the command string on the file and
// returns the error if one is found
func (s *Stream) Run(cmd string) error {
	// First parse the entire command string
	cm, er := parser.ParseString(cmd)
	if er != nil {
		return er
	}
	//spew.Dump(cm)
	// So now we run these commands on the file
	fi, er := interpreter.New(s.file)
	if er != nil {
		return er
	}
	return fi.Run(cm)
}
Esempio n. 2
0
func bench(b *testing.B, f func(*File), cmds string, size int, bytes int) {
	// Create a file to operate on
	fi := createFile(1024 * size)
	if bytes > 0 {
		b.SetBytes(int64(1024 * size))
	}
	// Create the command we should run
	cmd, err := parser.ParseString(cmds)
	if err != nil {
		panic(err)
	}
	//bg, _ := fi.f.Get(0, fi.f.Length())
	//println(string(bg))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		if f != nil {
			f(fi)
		} else {
			fi.dot = Adr{0, fi.f.Length()}
		}
		fi.Run(cmd)
	}
}