matthewbauer avatar matthewbauer committed b384f48

Added MAKE, some other all caps files
Added src/cmd files (basename, cat, dirname, echo, ls, uniq)

Comments (0)

Files changed (14)

+syntax: glob
+
+tmp
+pkg
+bin
+ascii
+awk
+basename
+bc
+cal
+cat
+cleanname
+cmp
+date
+dc
+du
+dd
+diff
+echo
+ed
+factor
+fortune
+fmt
+freq
+getflags
+grep
+hoc
+join
+look
+ls
+mk
+mkdir
+mtime
+pbd
+primes
+rc
+read
+sam
+sha1sum
+sed
+seq
+sleep
+sort
+split
+strings
+tail
+tee
+test
+touch
+tr
+troff
+unicode
+uniq
+unutf
 #!/bin/sh
 
-if [ -z "$ARCH" ]
-then
-	case $(uname -m) in
-		sparc) ARCH=k;;
-		powerpc|ppc64) ARCH=c;;
-		mips|mipsel) ARCH=v;;
-#68000
-		m68k) ARCH=1;;
-#68020
-#		m68k) ARCH=2;;
-		arm|armeb|armel) ARCH=5;;
-		x86_64) ARCH=6;;
-		alpha) ARCH=7;;
-		i386|i486|i586|i686) ARCH=8;;
-		#29k) ARCH=9;;
-	esac
-fi
-
-[ -z "$GC" ] && GC=${ARCH}g
-#[ -z "$GC" ] && GC=gccgo
-[ -z "$GL" ] && GL=${ARCH}l
-
-[ -z "$BIN" ] && BIN=bin
-[ -z "$SRC" ] && SRC=src
-[ -z "$TMP" ] && TMP=tmp
-
-[ -z "$SRCEXT" ] && SRCEXT='.go'
-
-clean(){
-	rm -r tmp
-}
-
-compile(){ # and link
-	mkdir -p "$BIN" "$SRC" "$TMP"
-	for srcfile in $@
-	do
-		filename="$(basename "$srcfile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
-		echo $filename
-		$GC -o "$TMP/$filename" "$srcfile"
-		$GL -o "$BIN/$filename" "$TMP/$filename"
-	done
-}
-
-install(){
-	cp -r ./bin /bin
-}
-
-usage(){
-	echo "$0 [compile|clean|help|install]"
-}
-
-default(){
-	compile src/*
-}
-
-[ $# == 0 ] && default
-
-while true
-do
-	case "$1" in
-		compile) compile;;
-		clean) clean;;
-		help|--help|-h) usage;;
-		install) install;;
-		'') break;;
-		*) compile "$1";;
-	esac
-	shift
-done
+./MAKE install
+#!/bin/sh
+
+if [ -z "$ARCH" ]
+then
+	case $(uname -m) in
+		sparc) ARCH=k;;
+		powerpc|ppc64) ARCH=c;;
+		mips|mipsel) ARCH=v;;
+#68000
+		m68k) ARCH=1;;
+#68020
+		#m68k) ARCH=2;;
+		arm|armeb|armel) ARCH=5;;
+		x86_64) ARCH=6;;
+		alpha) ARCH=7;;
+		i386|i486|i586|i686) ARCH=8;;
+		#29k) ARCH=9;;
+	esac
+fi
+
+[ -z "$GC" ] && GC=${ARCH}g
+#[ -z "$GC" ] && GC=gccgo
+[ -z "$GL" ] && GL=${ARCH}l
+
+[ -z "$BIN" ] && BIN=bin
+[ -z "$DEP" ] && DEP=dep
+[ -z "$SRC" ] && SRC=src
+[ -z "$TMP" ] && TMP=tmp
+
+[ -z "$SRCEXT" ] && SRCEXT='.go'
+
+clean(){
+	rm -r bin tmp
+}
+
+compile(){
+	mkdir -p "$TMP"
+	for srcfile in $@
+	do
+		filename="$(basename "$srcfile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
+		[ -f "$TMP/$filename.$ARCH" ] && return
+		echo "compile $filename"
+		handledep "$filename"
+		$GC -o "$TMP/$filename.$ARCH" "$srcfile" || return 1
+	done
+}
+
+link(){
+	mkdir -p "$BIN"
+	for compilefile in $@
+	do
+		filename="$(basename "$compilefile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
+		[ -f "$BIN/$filename" ] && return
+		echo "link $filename"
+		$GL -o "$BIN/$filename" "$TMP/$filename.$ARCH" || return 1
+	done
+}
+
+install(){
+	cp -r ./bin $PREFIX/bin
+}
+
+compilelink(){
+	for srcfile in $@
+	do
+		filename="$(basename "$srcfile" | sed 's/^\(.*\)\.[^\.]*$/\1/')"
+		compile "$srcfile"
+		link "$TMP/$filename.$ARCH"
+	done
+}
+
+build(){
+	compilelink $SRC/cmd/*
+}
+
+handledep(){
+	for program in $@
+	do
+		case "$program" in
+			#ls) compilelink "$SRC/dep/file.go";;
+		esac
+	done
+}
+
+testbin(){
+	echo "Time"
+	time "$1" "`pwd`/README" > /dev/null
+	stat --format="Size: %s" "$1"
+}
+
+comparebin(){
+	echo "$1 binary"
+	echo
+	echo "Our implementation:"
+	testbin "./bin/$1"
+	echo
+	echo "System binary:"
+	testbin "/bin/$1"
+	if [ -f /opt/plan9/bin/$1 ]
+	then
+		echo
+		echo "Plan9 binary:"
+		testbin "/opt/plan9/bin/$1"
+	fi
+}
+
+usage(){
+	echo "$0 [build|compile|clean|install|test \$bin|help|\$srcfile]"
+}
+
+default(){
+	clean
+	build
+}
+
+[ $# == 0 ] && default
+
+while true
+do
+	case "$1" in
+		build) build;;
+		compile) compile;;
+		clean) clean;;
+		install) install;;
+		test) shift; comparebin "$1";;
+		help|--help|-h) usage;;
+		'') break;;
+		*) compilelink "$1";;
+	esac
+	shift
+done
+* Binary Naming
+
+The naming for some of these binaries has always seemed 
 pkgdesc=""
 arch=()
 url=""
-license=('GPL')
+license=('MIT')
 groups=()
 depends=()
 makedepends=()
 #!/bin/english
 
+* Description
+
 Rewrite the most useful unix userland commands in the new Go language created by Google to form a robust base for future Unix-like userlands that do not suffer from the vulnerabilities that are common in C or C++ code.
 The minimum of commands that need to be implemented in Go are those found in 9base.
+
+* Installation
+
+Just run:
+./INSTALL
+
+* Documentation
+
+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.
+
+* Contact
+
+Matthew Bauer <mjbauer95@gmail.com>

src/cmd/basename.go

+package main
+
+import (
+	"fmt"
+	"os"
+	"strings"
+)
+
+func main(){
+	if len(os.Args) == 0 {
+		fmt.Fprintf(os.Stderr, "usage: basename [-d] string [suffix]\n");
+	} 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], "/")])
+		} else {
+			fmt.Printf("%s\n", strings.TrimRight(strings.Split(os.Args[0+dflag], "/", -1)[strings.Count(os.Args[0+dflag], "/")], os.Args[1+dflag]))
+		}
+	}
+}
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"flag"
+	"fmt"
+	"os"
+)
+
+func cat(f *os.File) {
+	const NBUF = 512
+	var buf [NBUF]byte
+	for {
+		switch nr, er := f.Read(&buf); true {
+		case nr < 0:
+			fmt.Fprintf(os.Stderr, "cat: error reading from %s: %s\n", f.Name(), er.String())
+			os.Exit(1)
+		case nr == 0:  // EOF
+			return
+		case nr > 0:
+			if nw, ew := os.Stdout.Write(buf[0:nr]); nw != nr {
+				fmt.Fprintf(os.Stderr, "cat: error writing from %s: %s\n", f.Name(), ew.String())
+			}
+		}
+	}
+}
+
+func main() {
+	flag.Parse()   // Scans the arg list and sets up flags
+	if flag.NArg() == 0 {
+		cat(os.Stdin)
+	}
+	for i := 0; i < flag.NArg(); i++ {
+		f, err := os.Open(flag.Arg(i), 0, 0)
+		if f == nil {
+			fmt.Fprintf(os.Stderr, "cat: can't open %s: error %s\n", flag.Arg(i), err)
+			os.Exit(1)
+		}
+		cat(f)
+		f.Close()
+	}
+}

src/cmd/dirname.go

+package main
+
+import (
+	"flag"
+	"os"
+)
+
+func main(){
+	
+}
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+	"os"
+	"flag"  // command line option parser
+)
+
+var omitNewline = flag.Bool("n", false, "don't print final newline")
+
+const (
+	Space = " "
+	Newline = "\n"
+)
+
+func main() {
+	flag.Parse()   // Scans the arg list and sets up flags
+	var s string = ""
+	for i := 0; i < flag.NArg(); i++ {
+		if i > 0 {
+			s += Space
+		}
+		s += flag.Arg(i)
+	}
+	if !*omitNewline {
+		s += Newline
+	}
+	os.Stdout.WriteString(s)
+}
+package main
+
+import (
+	"flag"
+	"os"
+	"fmt"
+)
+
+const (
+	Newline = "\n"
+)
+
+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 main(){
+	flag.Parse()
+	if flag.NArg() == 0 {
+		ls(".")
+	}
+	for i := 0; i < flag.NArg(); i++ {
+		ls(flag.Arg(i))
+	}
+}
+package main
+
+import (
+	"flag"
+	"fmt"
+	"os"
+	"strings"
+)
+
+const (
+	Newline = "\n"
+	NBUF = 512
+)
+
+func uniq(f *os.File) {
+	data := ""
+	var buf [NBUF]byte
+	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.Exit(1)
+		case nr == 0:  // EOF
+			return
+		case nr > 0:
+			data += buf
+		}
+	}
+
+	lines := strings.Split(data, "\n", -1)
+	for i:=0; i < len(lines); i++ {
+		ununiq := 0
+		for j:=0; j < len(wrotelines); j++ {
+			if lines[i] == wrotelines[j] {
+				ununiq := 1
+			}
+		}
+		if ununiq == 0 {
+			returndata += lines[i]
+			returndata += Newline
+		}
+	}
+	
+	os.Stdout.WriteString(returndata)
+}
+
+func main() {
+	flag.Parse()
+	if flag.NArg() == 0 {
+		uniq(os.Stdin)
+	} else {
+		for h:=0; h < flag.NArg(); h++ {
+			f,err := os.Open(flag.Arg[h])
+			if f == nil {
+				fmt.Fprintf(os.Stderr, "uniq: error opening %s: %s\n", flag.Arg[h], err.String())
+				os.Exit(1)
+			}
+			uniq(f)
+			f.Close(flag.Arg[h])
+		}
+	}
+}
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.