summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-01-22 16:16:52 +0000
committerNick White <git@njw.name>2020-01-22 16:16:52 +0000
commit3e137cf7a2e163b25b2109a4182a453a38f3a4de (patch)
treeaa7636aba41fc34998b42e9cbddc204918ab8a9d
parent61cb51730c2e3dbbea544a0ff5bc6628be76a54d (diff)
Add simple boxtotxt tool
-rw-r--r--boxtotxt/main.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/boxtotxt/main.go b/boxtotxt/main.go
new file mode 100644
index 0000000..d313aa0
--- /dev/null
+++ b/boxtotxt/main.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "bufio"
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "strings"
+)
+
+func main() {
+ flag.Usage = func() {
+ fmt.Fprintf(os.Stderr, "Usage: boxtotxt in.box\n")
+ flag.PrintDefaults()
+ }
+ flag.Parse()
+ if flag.NArg() != 1 {
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ f, err := os.Open(flag.Arg(0))
+ defer f.Close()
+ if err != nil {
+ log.Fatalf("Could not open file %s: %v\n", flag.Arg(0), err)
+ }
+
+ scanner := bufio.NewScanner(f)
+
+ for scanner.Scan() {
+ t := scanner.Text()
+ s := strings.Split(t, "")
+ if len(s) < 1 {
+ continue
+ }
+ fmt.Printf("%s", s[0])
+ }
+
+ fmt.Printf("\n")
+}