matthewbauer avatar matthewbauer committed bdf1f5a

Fixed MAKE; Changed README; updated go source programs like ascii, basename, cleanname, ls, and uniq; and added programs such as bc, date, and sleep

Comments (0)

Files changed (14)

 #68000
 		m68k) ARCH=1;;
 #68020
-		#m68k) ARCH=2;;
+#		m68k) ARCH=2;;
 		arm|armeb|armel) ARCH=5;;
 		x86_64) ARCH=6;;
 		alpha) ARCH=7;;
 
 compile(){
 	mkdir -p "$TMP"
-	for srcfile in $@
-	do
+	srcfile="$@"
+#	for srcfile in $@
+#	do
 		filename="$(basename "$srcfile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
-		[ -f "$TMP/$filename.$ARCH" ] && return
+		[ -f "$TMP/$filename.$ARCH" ] && return 0
 		echo "compile $filename"
 		handledep "$filename"
 		$GC -o "$TMP/$filename.$ARCH" "$srcfile" || return 1
-	done
+#	done
 }
 
 link(){
 	mkdir -p "$BIN"
-	for compilefile in $@
-	do
+	compilefile="$@"
+#	for compilefile in $@
+#	do
 		filename="$(basename "$compilefile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
-		[ -f "$BIN/$filename" ] && return
+		[ -f "$BIN/$filename" ] && return 0
 		echo "link $filename"
 		$GL -o "$BIN/$filename" "$TMP/$filename.$ARCH" || return 1
-	done
+#	done
 }
 
 install(){
 	for srcfile in $@
 	do
 		filename="$(basename "$srcfile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
-		compile "$srcfile"
-		link "$TMP/$filename.$ARCH"
+		compile "$srcfile" || continue
+		link "$TMP/$filename.$ARCH" || continue
 	done
 }
 
 
 testbin(){
 	echo "Time"
-	time "$1" "`pwd`/README" > /dev/null
+	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
+		;;
+		*)
+			#time "$1" > /dev/null
+			#-e raw_syscalls:sys_enter
+			perf stat -e cycles -e instructions  -- "$1" > $TMP/$1.out
+		;;
+	esac
 	stat --format="Size: %s" "$1"
 }
 
 	rm -r _test
 }
 
+edit(){
+	$EDITOR src/cmd/*
+	#MAKE TODO README PKGBUILD LICENSE
+}
+
 usage(){
 	echo "$0 [build|compile|clean|comparebin \$bin|install|test \$source|help|\$srcfile]"
 }
 		install) install;;
 		comparebin) shift; comparebin "$1";;
 		test) shift; test $1;;
+		edit) edit;;
 		help|--help|-h) usage;;
 		'') break;;
 		*) compilelink "$1";;
 pkgver=VERSION
 pkgrel=1
 pkgdesc=""
-arch=()
+arch=('i686' 'x86_64')
 url=""
 license=('MIT')
 groups=()
 depends=()
-makedepends=()
+makedepends=('go')
 optdepends=()
 provides=()
 conflicts=()
+#!/bin/english
+
 -*- markdown -*-
-#!/bin/english
 
 Description
 ===========
 
 Based on
 ===========
-The Go developers provide example code for "echo" and "cat". This is used but some modifications may have been made.
+* 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)
 
 Commands
 ===========
--*- markdown -*-
 #!/bin/english
 
 * Change doc files to Markdown or Restructured text
 import (
 	"os"
 	"flag"
+	"fmt"
 )
 
 var str = []string{
 	" ð ",	" ñ ",	" ò ",	" ó ",	" ô ",	" õ ",	" ö ",	" ÷ ",
 	" ø ",	" ù ",	" ú ",	" û ",	" ü ",	" ý ",	" þ ",	" ÿ " }
 
+var text = 1
+
 func usage(){
 	fmt.Fprintf(os.Stderr, "usage: ./ascii [-8] [-xod | -b8] [-ncst] [--] [text]")
-	os.Exit(1)
+	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++ {
-			os.Stdout.WriteString(str[i]);
-			os.Stdout.WriteString(" ");
+			fmt.Fprintf(os.Stdout, "| %x %s", i, str[i]);
 			if (i&7)==7 {
 				os.Stdout.WriteString("|\n");
 			}
 		}
 	} else {
-		if flag.Arg()
+		if text == 1 {
+			text = strconv.Atoi()
+		}
 	}
 }

src/cmd/basename.go

 package main
 
 import (
+	"flag"
 	"fmt"
 	"os"
 	"strings"
 )
 
+const (
+	PATH_SEP = "/"
+)
+
+var get_dir_name = flag.Bool("d", false, "print name of directory")
+
+func usage(){
+	fmt.Fprintf(os.Stderr, "usage: basename [-d] string [suffix]\n")
+	flag.PrintDefaults()
+}
+
 func main(){
-	if len(os.Args) == 0 {
-		fmt.Fprintf(os.Stderr, "usage: basename [-d] string [suffix]\n");
+	flag.Parse()
+	if flag.NArg() == 0 {
+		usage()
 	} else {
-		dflag:=0
-		if os.Args[0] == "-d" {
-			dflag:=1
-		}
-		if len(os.Args) - dflag == 1 {
-			fmt.Printf("%s\n", strings.Split(os.Args[0+dflag], "/", -1)[strings.Count(os.Args[0+dflag], "/")])
+		sep_count := strings.Count(flag.Arg(0), PATH_SEP)
+		if *get_dir_name == true {
+			count := strings.Count(flag.Arg(0), PATH_SEP)
+			if count == 0 {
+				fmt.Fprintln(os.Stdout, flag.Arg(0))
+			} else {
+				split_path := strings.Split(flag.Arg(0), PATH_SEP, -1)[0:sep_count]
+				dir_name := strings.Join(split_path, PATH_SEP)
+				fmt.Fprintln(os.Stdout, dir_name)
+			}
 		} else {
-			fmt.Printf("%s\n", strings.TrimRight(strings.Split(os.Args[0+dflag], "/", -1)[strings.Count(os.Args[0+dflag], "/")], os.Args[1+dflag]))
+			base_name := strings.Split(flag.Arg(0), PATH_SEP, -1)[sep_count]
+			if flag.NArg() == 1 {
+				fmt.Fprintln(os.Stdout, base_name)
+			} else if flag.NArg() == 2 {
+				trim_base := strings.TrimRight(base_name, flag.Arg(1))
+				fmt.Fprintln(os.Stdout, trim_base)
+			} else {
+				usage()
+			}
 		}
 	}
 }
+package main
+
+import (
+	"os"
+	"flag"
+	"fmt"
+)
+
+func usage(){
+	fmt.Fprintf(os.Stderr, "Usage: bc [-l] [-c] [file ...]")
+}
+
+func bc(f os.File){
+}
+
+func main(){
+	flag.Parse()
+
+	if flag.NArg() == 0 {
+		bc(os.Stdin)
+	} else {
+		for i := 0; i < flag.NArg(); i++ {
+			f, err := os.Open(flag.Arg(i), 0, 0)
+			bc(flag.Arg(i))
+			f.Close()
+		}
+	}
+}

src/cmd/cleanname.go

 	"strings"
 )
 
+var dir = flag.String("d", nil, "pwd")
+
+func cleanname(name *string){
+}
+
 func main(){
 	flag.Parse()
 	if flag.NArg()==0 {
 		os.Stderr.write("usage: cleanname [-d pwd] name...\n")
+		flag.PrintDefaults()
 	} else {
 		for i:=0; i < flag.NArg(); i++ {
-			
+			if dir == nil || flag.Arg(i)[0] == '/' {
+				
+			} else {
+				flag.Arg(i)
+			}
 		}
 	}
 }
+package main
+
+import (
+	"os"
+	"flag"
+	"fmt"
+	"time"
+)
+
+nflg = flag.Bool("n", false)
+uflg = flag.Bool("u", false, "")
+
+func main(){
+	flag.Parse()
+	
+	if flag.NArg() == 1 {
+		now, err = time.Parse(flag.Arg(1))
+	} else {
+		now = time.LocalTime()
+	}
+}
 package main
 
 import (
-	"flag"
-	"os"
-	"fmt"
+    "bufio"
+    "flag"
+    "fmt"
+    "os"
 )
 
-const (
-	Newline = "\n"
-)
+var Stdout = bufio.NewWriter(os.Stdout)
 
-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)
-	}
-	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])
-	}
-	f.Close()
+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()
+
+    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"))
+
+    }
 }
 
-func main(){
-	flag.Parse()
-	if flag.NArg() == 0 {
-		ls(".")
-	} else {
-		for i := 0; i < flag.NArg(); i++ {
-			ls(flag.Arg(i))
-		}
-	}
+func main() {
+    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"
+)
+
+func main(){
+	if len(os.Args) > 1 {
+		secs,err := strconv.Atoi(os.Args[1])
+		if err == nil {
+			for secs>0  {
+				syscall.Sleep(1000)
+				secs--
+			}
+		} else {
+			os.Stderr.WriteString("sleep: " + os.Args[1] + ": not a number\n")
+			os.Exit(1)
+		}
+		os.Exit(0)
+	} else {
+		os.Exit(1)
+	}
+}
 package main
 
 import (
-	"flag"
-	"fmt"
 	"os"
 	"strings"
 )
 	for {
 		switch nr, er := f.Read(&buf); true {
 		case nr < 0:
-			fmt.Fprintf(os.Stderr, "uniq: error reading from %s: %s\n", f.Name(), er.String())
+			os.Stderr.WriteString("uniq: error reading from " + f.Name() + ": " + er.String() + "\n")
 			os.Exit(1)
 		case nr == 0:  // EOF
 			return
 }
 
 func main() {
-	flag.Parse()
-	if flag.NArg() == 0 {
+	if len(os.Args) <= 1 {
 		uniq(os.Stdin)
 	} else {
-		for h:=0; h < flag.NArg(); h++ {
-			f,err := os.Open(flag.Arg[h])
+		for h:=0; h < len(os.Args); h++ {
+			f,err := os.Open(os.Args[h])
 			if f == nil {
-				fmt.Fprintf(os.Stderr, "uniq: error opening %s: %s\n", flag.Arg[h], err.String())
+				os.Stderr.WriteString("uniq: error opening " + os.Args[h] + ": " + err.String() + "\n")
 				os.Exit(1)
 			}
 			uniq(f)
+package main
+
+import (
+	
+)
+package main
+
+import (
+	
+)
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.