matthewbauer avatar matthewbauer committed a9dc012

Some more changes that I can't remember

Comments (0)

Files changed (12)

 syntax: glob
 
-_test
+test
 tmp
 pkg
 bin
 	case "$(basename $1)" in
 		ls) 
 			#-e raw_syscalls:sys_enter 
-			perf stat -e cycles -e instructions  -- "$1" /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib > /dev/null
+			#perf stat -- "$1" /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib /usr/lib > /dev/null
+			perf stat -- "$1" $(seq 10 | while read line; do echo -n '/usr/lib '; done) > /dev/null
+		;;
+		sleep)
+			perf stat -- "$1" 5 > /dev/null
 		;;
 		*)
 			#time "$1" > /dev/null
 			#-e raw_syscalls:sys_enter
-			perf stat -e cycles -e instructions  -- "$1" > $TMP/$1.out
+			perf stat -- "$1" > /dev/nullz
 		;;
 	esac
 	stat --format="Size: %s" "$1"
 }
 
+elapsedtime(){
+	perf stat -- "./bin/ls" $(seq 10 | while read line; do echo -n '/usr/lib '; done) 2>&1 | sed -n 's/ *\([0-9\.]*\)  seconds time elapsed/\1/p'
+}
+
+average(){
+	cat "$@" | tr '\n' '+' | sed "s|\(.*\)+$|(\1)/$(cat "$@" | wc -l)\n|" | bc -l
+}
+
+benchmark(){
+	mkdir -p ./test
+	for a in $(seq 10)
+	do
+		elapsedtime "./bin/$1" >> ./test/$1-time-our
+		elapsedtime "/bin/$1" >> ./test/$1-time-sys
+		elapsedtime "/opt/plan9/bin/$1" >> ./test/$1-time-plan9
+	done
+
+	echo Average
+	echo Our binary: $(average "./test/$1-time-our")
+	echo System binary: $(average "./test/$1-time-sys")
+	echo Plan9 binary: $(average "./test/$1-time-plan9")
+}
+
 comparebin(){
 	echo "$1 binary"
 	echo
 	echo "Our implementation:"
+	[ ! -f "./bin/$1" ] && compilelink "src/cmd/$1.go"
 	testbin "./bin/$1"
 	echo
 	echo "System binary:"
 		install) install;;
 		comparebin) shift; comparebin "$1";;
 		test) shift; test $1;;
+		benchmark) benchmark ls;;
 		edit) edit;;
 		help|--help|-h) usage;;
 		'') break;;
-#!/bin/english
-
 -*- markdown -*-
 
 Description
 
 Requirements: Good C/Unix and Go knowledge is essential.
 
-http://suckless.org/project_ideas section goblin
+See: [http://suckless.org/project_ideas](http://suckless.org/project_ideas) section goblin
 
 Documentation
 ===========
-Should work the same as the original unix ones.
+Should work the same as the original Unix ones.
 
 Based on
 ===========
-* The Go developers provide example code for "echo" and "cat". This is used but some modifications may have been made.
-* [9base](http://tools.suckless.org/9base) [hg](http://hg.suckless.org/9base)
-* [plan9port](http://swtch.com/plan9port/) [hg](http://code.swtch.com/plan9port)
+* The Go developers provide example code for _echo_ and _cat_. This is used but some modifications may have been made.
+* 9base [[main page](http://tools.suckless.org/9base)] [[code](http://hg.suckless.org/9base)]
+* plan9port [[main page](http://swtch.com/plan9port/)] [[code](http://code.swtch.com/plan9port)]
 
 Commands
 ===========
+_Many of these aren't finished_
+
 * ascii
 * awk
 * basename
 Contact
 ===========
 Matthew Bauer <mjbauer95@gmail.com>
+
 var text = 1
 
 func usage(){
-	fmt.Fprintf(os.Stderr, "usage: ./ascii [-8] [-xod | -b8] [-ncst] [--] [text]")
+	fmt.Fprintln(os.Stderr, "usage: ascii [-8] [-xod | -b8] [-ncst] [--] [text]")
 	flag.PrintDefaults()
 }
 
 func main(){
 	flag.Parse()
-
 	if flag.Bool("n", false, "") == true {
 		text := 0
 	} else if flag.Bool("c", false, "") == true {
 		text := 2
 	}
-
 	if flag.NArg() == 0 {
 		for i:=0; i<len(str); i++ {
 			fmt.Fprintf(os.Stdout, "| %x %s", i, str[i]);

src/cmd/basename.go

 var get_dir_name = flag.Bool("d", false, "print name of directory")
 
 func usage(){
-	fmt.Fprintf(os.Stderr, "usage: basename [-d] string [suffix]\n")
+	fmt.Fprintln(os.Stderr, "usage: basename [-d] string [suffix]")
 	flag.PrintDefaults()
 }
 
 )
 
 func usage(){
-	fmt.Fprintf(os.Stderr, "Usage: bc [-l] [-c] [file ...]")
+	fmt.Fprintln(os.Stderr, "usage: bc [-l] [-c] [file ...]")
+	flag.PrintDefaults()
 }
 
 func bc(f os.File){
 
 func main(){
 	flag.Parse()
-
 	if flag.NArg() == 0 {
 		bc(os.Stdin)
 	} else {
 	"os"
 )
 
+func usage() {
+	fmt.Fprintln(os.Stderr, "usage: cat [ file ... ]")
+	flag.PrintDefaults()
+}
+
 func cat(f *os.File) {
 	const NBUF = 512
 	var buf [NBUF]byte

src/cmd/cleanname.go

 
 var dir = flag.String("d", nil, "pwd")
 
+func usage(){
+	fmt.Fprintln(os.Stderr, "usage: cleanname [-d pwd] name...")
+	flag.PrintDefaults()
+}
+
 func cleanname(name *string){
 }
 
 func main(){
 	flag.Parse()
-	if flag.NArg()==0 {
-		os.Stderr.write("usage: cleanname [-d pwd] name...\n")
-		flag.PrintDefaults()
+	if flag.NArg() == 0 {
+		usage()
 	} else {
 		for i:=0; i < flag.NArg(); i++ {
 			if dir == nil || flag.Arg(i)[0] == '/' {
 nflg = flag.Bool("n", false)
 uflg = flag.Bool("u", false, "")
 
+func usage(){
+	fmt.Fprintln(os.Stderr, "usage: date [-un] [seconds]")
+	flag.PrintDefaults()
+}
+
 func main(){
 	flag.Parse()
-	
-	if flag.NArg() == 1 {
+	if flag.NArg() == 0 {
 		now, err = time.Parse(flag.Arg(1))
 	} else {
 		now = time.LocalTime()
 	Newline = "\n"
 )
 
+func usage() {
+	fmt.Fprintln(os.Stderr, "echo [ -n ] [ arg ...  ]")
+	flag.PrintDefaults()
+}
+
 func main() {
 	flag.Parse()   // Scans the arg list and sets up flags
 	var s string = ""
 package main
 
 import (
-    "bufio"
-    "flag"
-    "fmt"
-    "os"
+	"bufio"
+	"flag"
+	"fmt"
+	"os"
+)
+
+const (
+	Newline = 0x0a
 )
 
 var Stdout = bufio.NewWriter(os.Stdout)
 
+var dflag = flag.Bool("d", false, "If argument is a directory, list it, not its contents")
+var lflag = flag.Bool("l", false, "List in long format")
+var mflag = flag.Bool("m", false, "List the name of the user who most recently modified the file")
+var nflag = flag.Bool("n", true, "Don't sort the listing")
+var pflag = flag.Bool("p", false, "Print only the final path element of each file name")
+var qflag = flag.Bool("q", false, "List the qid (see stat(3)) of each file; the printed fields are in the order path, version, and type")
+var rflag = flag.Bool("r", false, "Reverse the order of sort")
+var sflag = flag.Bool("s", false, "Give size in Kbytes for each entry")
+var tflag = flag.Bool("t", false, "Sort by time modified (latest first) instead of by name")
+var uflag = flag.Bool("u", false, "Under -t sort by time of last access; under -l print time of last access")
+var Fflag = flag.Bool("F", false, "Add the character / after all directory names and the character * after all executable files")
+var Lflag = flag.Bool("L", false, "Print the character t before each file if it has the temporary flag set, and - otherwise.")
+var Qflag = flag.Bool("Q", false, "By default, printed file names are quoted if they contain characters special to rc(1).  The -Q flag disables this behavior.")
+
+func usage() {
+	fmt.Fprintf(os.Stderr, "usage: ls [ -dlmnpqrstuFQ ] name ...")
+	flag.PrintDefaults()
+}
+
 func ls(filename string) {
-    f, err := os.Open(filename, os.O_RDONLY, 0)
-    if f == nil {
-        fmt.Fprintf(os.Stderr, "ls: cannot access %s: %s\n", filename,
-            err.String())
-        os.Exit(1)
-    }
-    defer f.Close()
+	f, err := os.Open(filename, os.O_RDONLY, 0)
+	if f == nil {
+		fmt.Fprintf(os.Stderr, "ls: cannot access %s: %s\n", filename,
+			err.String())
+		os.Exit(1)
+	}
+	defer f.Close()
 
-    files, err := f.Readdirnames(-1)
-    if files == nil {
-        fmt.Fprintf(os.Stderr, "ls: could not get files in %s: %s\n",
-            filename, err.String())
-        os.Exit(1)
-    }
-    for j := 0; j < len(files); j++ {
-        //fmt.Printf("%s\n", files[j])
-        //fmt.Println(files[j])
-        Stdout.Write([]byte(files[j]))
-        Stdout.Write([]byte("\n"))
-
-    }
+	files, err := f.Readdirnames(-1)
+	if files == nil {
+		fmt.Fprintf(os.Stderr, "ls: could not get files in %s: %s\n",
+			filename, err.String())
+		os.Exit(1)
+	}
+	for j := 0; j < len(files); j++ {
+		Stdout.WriteString(files[j])
+		Stdout.WriteByte(Newline)
+	}
 }
 
 func main() {
-    flag.Parse()
-    if flag.NArg() == 0 {
-        ls(".")
-    } else {
-        for i := 0; i < flag.NArg(); i++ {
-            ls(flag.Arg(i))
-        }
-    }
-
-    Stdout.Flush()
+	flag.Parse()
+	if flag.NArg() == 0 {
+		ls(".")
+	} else {
+		for i := 0; i < flag.NArg(); i++ {
+			ls(flag.Arg(i))
+		}
+	}
+	Stdout.Flush()
 }
 package main
 
 import (
-    "os"
-    "syscall"
-    "strconv"
+	"os"
+	"time"
+	"fmt"
+	"strconv"
 )
 
-func main(){
+func usage() {
+	fmt.Fprintln(os.Stderr, "usage: sleep time")
+}
+
+func main() {
 	if len(os.Args) > 1 {
-		secs,err := strconv.Atoi(os.Args[1])
-		if err == nil {
-			for secs>0  {
-				syscall.Sleep(1000)
-				secs--
+		secs, err := strconv.Atoi(os.Args[1])
+		if secs >= 0 {
+			fmt.Fprintf(os.Stderr, "%i\n", secs)
+			//time.Sleep(int64(secs * 1000000000))
+			for t < end {
+				errno := syscall.Sleep(end - t)
+				if errno != 0 && errno != syscall.EINTR {
+					return os.NewSyscallError("sleep", errno)
+				}
+				t--
 			}
 		} else {
-			os.Stderr.WriteString("sleep: " + os.Args[1] + ": not a number\n")
+			fmt.Fprintf(os.Stderr, "sleep: %s: not a positive number: %s\n", os.Args[1], err.String())
 			os.Exit(1)
 		}
 		os.Exit(0)
 	} else {
+		usage()
 		os.Exit(1)
 	}
 }
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.