CFLAGS=-Wall -O2
-all: errno_speak show_default_sockopts simple_time vimstart
+all: bytor errno_speak show_default_sockopts simple_time vimstart
+
+bytor:
+ go build bytor.go
errno_speak: errno_speak.o
--- /dev/null
+package main
+
+import "fmt"
+import "os"
+import "strconv"
+
+func usage(retval int) {
+ fmt.Printf("bytor: converts bytes between hex and decimal.\n" +
+ "\n" +
+ "usage: bytor [flags] [number-to-convert]\n" +
+ "\n" +
+ "Numbers with the prefix '0x' will be interpreted as \n" +
+ "hexadecimal; others will be interpreted as decimal.\n" +
+ "\n" +
+ "Flags:\n" +
+ "-d: Decimal output (default is hex.)\n" +
+ "-h/--help: This help message\n")
+ os.Exit(retval)
+}
+
+func main() {
+ formatStr := "0x%02x\n"
+ i := 1
+ if (len(os.Args) < 2) {
+ usage(1)
+ }
+ if ((os.Args[i] == "-h") || (os.Args[i] == "--help")) {
+ usage(0)
+ }
+ if (os.Args[i] == "-d") {
+ formatStr = "%d\n"
+ i++
+ }
+ if (i >= len(os.Args)) {
+ usage(1)
+ }
+ val, err := strconv.ParseInt(os.Args[i], 0, 8)
+ if (err != nil) {
+ fmt.Printf("Error parsing input: %v\n", err)
+ os.Exit(1)
+ }
+ if (val < 0) {
+ val = 0x100 + val;
+ }
+ fmt.Printf(formatStr, val)
+}