Change fmt to log for easier writing to STDOUT

Change-Id: Icc090d205e3c6ff123157f9d3f1408975bc65537
diff --git a/datok.go b/datok.go
index 5191877..ef3667b 100644
--- a/datok.go
+++ b/datok.go
@@ -28,7 +28,6 @@
 	"bufio"
 	"compress/gzip"
 	"encoding/binary"
-	"fmt"
 	"io"
 	"math"
 	"os"
@@ -168,7 +167,7 @@
 				}
 
 				if DEBUG {
-					fmt.Println("Translate transition",
+					log.Println("Translate transition",
 						s, "->", s1, "(", a, ")", "to", t, "->", t1)
 				}
 
@@ -176,7 +175,7 @@
 				if atrans.nontoken {
 					dat.array[t1].setNonToken(true)
 					if DEBUG {
-						fmt.Println("Set", t1, "to nontoken")
+						log.Println("Set", t1, "to nontoken")
 					}
 				}
 
@@ -184,7 +183,7 @@
 				if atrans.tokenend {
 					dat.array[t1].setTokenEnd(true)
 					if DEBUG {
-						fmt.Println("Set", t1, "to tokenend")
+						log.Println("Set", t1, "to tokenend")
 					}
 				}
 
@@ -829,7 +828,7 @@
 			char = buffer[buffc]
 
 			if DEBUG {
-				fmt.Println("Current char", string(char), int(char), showBufferNew(buffer, bufft, buffc, buffi))
+				log.Println("Current char", string(char), int(char), showBufferNew(buffer, bufft, buffc, buffi))
 			}
 
 			eot = false
@@ -863,7 +862,7 @@
 				epsilonOffset = buffc
 
 				if DEBUG {
-					fmt.Println("epsilonOffset is set to", buffc)
+					log.Println("epsilonOffset is set to", buffc)
 				}
 			}
 		}
@@ -874,9 +873,9 @@
 
 		if DEBUG {
 			// Char is only relevant if set
-			fmt.Println("Check", t0, "-", a, "(", string(char), ")", "->", t)
+			log.Println("Check", t0, "-", a, "(", string(char), ")", "->", t)
 			if false {
-				fmt.Println(dat.outgoing(t0))
+				log.Println(dat.outgoing(t0))
 			}
 		}
 
@@ -884,7 +883,7 @@
 		if t > dat.array[1].getCheck() || ta.getCheck() != t0 {
 
 			if DEBUG {
-				fmt.Println("Match is not fine!", t, "and", ta.getCheck(), "vs", t0)
+				log.Println("Match is not fine!", t, "and", ta.getCheck(), "vs", t0)
 			}
 
 			if !ok && a == dat.identity {
@@ -892,7 +891,7 @@
 				// Try again with unknown symbol, in case identity failed
 				// Char is only relevant when set
 				if DEBUG {
-					fmt.Println("UNKNOWN symbol", string(char), "->", dat.unknown)
+					log.Println("UNKNOWN symbol", string(char), "->", dat.unknown)
 				}
 				a = dat.unknown
 
@@ -905,7 +904,7 @@
 				a = dat.epsilon
 
 				if DEBUG {
-					fmt.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
+					log.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
 				}
 
 			} else {
@@ -928,7 +927,7 @@
 			// Transition does not produce a character
 			if buffc-bufft == 1 && ta.isNonToken() {
 				if DEBUG {
-					fmt.Println("Nontoken forward", showBufferNew(buffer, bufft, buffc, buffi))
+					log.Println("Nontoken forward", showBufferNew(buffer, bufft, buffc, buffi))
 				}
 				bufft++
 				// rewindBuffer = true
@@ -939,7 +938,7 @@
 			// Transition marks the end of a token - so flush the buffer
 			if buffc-bufft > 0 {
 				if DEBUG {
-					fmt.Println("-> Flush buffer: [", string(buffer[bufft:buffc]), "]", showBuffer(buffer, buffc, buffi))
+					log.Println("-> Flush buffer: [", string(buffer[bufft:buffc]), "]", showBuffer(buffer, buffc, buffi))
 				}
 				w.Token(bufft, buffer[:buffc])
 				rewindBuffer = true
@@ -956,7 +955,7 @@
 			textEnd = true
 			w.TextEnd(0)
 			if DEBUG {
-				fmt.Println("END OF TEXT")
+				log.Println("END OF TEXT")
 			}
 		}
 
@@ -964,7 +963,7 @@
 		if rewindBuffer {
 
 			if DEBUG {
-				fmt.Println("-> Rewind buffer", bufft, buffc, buffi, epsilonOffset)
+				log.Println("-> Rewind buffer", bufft, buffc, buffi, epsilonOffset)
 			}
 
 			// TODO: Better as a ring buffer
@@ -982,7 +981,7 @@
 			bufft = 0
 
 			if DEBUG {
-				fmt.Println("Remaining:", showBufferNew(buffer, bufft, buffc, buffi))
+				log.Println("Remaining:", showBufferNew(buffer, bufft, buffc, buffi))
 			}
 		}
 
@@ -992,7 +991,7 @@
 			ta = dat.array[t]
 
 			if DEBUG {
-				fmt.Println("Representative pointing to", t)
+				log.Println("Representative pointing to", t)
 			}
 		}
 
@@ -1005,13 +1004,13 @@
 	// Input reader is not yet finished
 	if !eof {
 		if DEBUG {
-			fmt.Println("Not at the end - problem", t0, ":", dat.outgoing(t0))
+			log.Println("Not at the end - problem", t0, ":", dat.outgoing(t0))
 		}
 		return false
 	}
 
 	if DEBUG {
-		fmt.Println("Entering final check")
+		log.Println("Entering final check")
 	}
 
 	/*
@@ -1026,7 +1025,7 @@
 
 				if buffi > 0 {
 					if DEBUG {
-						fmt.Println("-> Flush buffer: [", string(buffer[:buffi]), "]")
+						log.Println("-> Flush buffer: [", string(buffer[:buffi]), "]")
 					}
 					w.Token(0, buffer[:buffi])
 				}
@@ -1060,7 +1059,7 @@
 		epsilonState = 0 // reset
 		buffc = epsilonOffset
 		if DEBUG {
-			fmt.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
+			log.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
 		}
 		goto PARSECHAR
 	}
@@ -1072,7 +1071,7 @@
 		w.SentenceEnd(0)
 
 		if DEBUG {
-			fmt.Println("Sentence end")
+			log.Println("Sentence end")
 		}
 	}
 
@@ -1080,7 +1079,7 @@
 		w.TextEnd(0)
 
 		if DEBUG {
-			fmt.Println("Text end")
+			log.Println("Text end")
 		}
 	}
 
diff --git a/fomafile.go b/fomafile.go
index 33128a2..8f8f046 100644
--- a/fomafile.go
+++ b/fomafile.go
@@ -3,7 +3,6 @@
 import (
 	"bufio"
 	"compress/gzip"
-	"fmt"
 	"io"
 	"log"
 	"os"
@@ -142,19 +141,19 @@
 			{
 				elem = strings.Split(line, " ")
 				/*
-					fmt.Println("arity:            " + elem[0])
-					fmt.Println("arccount:         " + elem[1])
-					fmt.Println("statecount:       " + elem[2])
-					fmt.Println("linecount:        " + elem[3])
-					fmt.Println("finalcount:       " + elem[4])
-					fmt.Println("pathcount:        " + elem[5])
-					fmt.Println("is_deterministic: " + elem[6])
-					fmt.Println("is_pruned:        " + elem[7])
-					fmt.Println("is_minimized:     " + elem[8])
-					fmt.Println("is_epsilon_free:  " + elem[9])
-					fmt.Println("is_loop_free:     " + elem[10])
-					fmt.Println("extras:           " + elem[11])
-					fmt.Println("name:             " + elem[12])
+					log.Println("arity:            " + elem[0])
+					log.Println("arccount:         " + elem[1])
+					log.Println("statecount:       " + elem[2])
+					log.Println("linecount:        " + elem[3])
+					log.Println("finalcount:       " + elem[4])
+					log.Println("pathcount:        " + elem[5])
+					log.Println("is_deterministic: " + elem[6])
+					log.Println("is_pruned:        " + elem[7])
+					log.Println("is_minimized:     " + elem[8])
+					log.Println("is_epsilon_free:  " + elem[9])
+					log.Println("is_loop_free:     " + elem[10])
+					log.Println("extras:           " + elem[11])
+					log.Println("name:             " + elem[12])
 				*/
 				if elem[6] != "1" {
 					log.Print("The FST needs to be deterministic")
@@ -191,38 +190,38 @@
 				elem = strings.Split(line[0:len(line)-1], " ")
 				if elem[0] == "-1" {
 					if DEBUG {
-						fmt.Println("Skip", elem)
+						log.Println("Skip", elem)
 					}
 					continue
 				}
 				elemint[0], err = strconv.Atoi(elem[0])
 				if err != nil {
-					fmt.Println("Unable to translate", elem[0])
+					log.Println("Unable to translate", elem[0])
 					break
 				}
 
 				if len(elem) > 1 {
 					elemint[1], err = strconv.Atoi(elem[1])
 					if err != nil {
-						fmt.Println("Unable to translate", elem[1])
+						log.Println("Unable to translate", elem[1])
 						break
 					}
 					if len(elem) > 2 {
 						elemint[2], err = strconv.Atoi(elem[2])
 						if err != nil {
-							fmt.Println("Unable to translate", elem[2])
+							log.Println("Unable to translate", elem[2])
 							break
 						}
 						if len(elem) > 3 {
 							elemint[3], err = strconv.Atoi(elem[3])
 							if err != nil {
-								fmt.Println("Unable to translate", elem[3])
+								log.Println("Unable to translate", elem[3])
 								break
 							}
 							if len(elem) > 4 {
 								elemint[4], err = strconv.Atoi(elem[4])
 								if err != nil {
-									fmt.Println("Unable to translate", elem[4])
+									log.Println("Unable to translate", elem[4])
 									break
 								}
 							}
@@ -350,7 +349,7 @@
 				}
 
 				if DEBUG {
-					fmt.Println("Add",
+					log.Println("Add",
 						state+1, "->", end+1,
 						"(",
 						inSym,
diff --git a/matrix.go b/matrix.go
index 7141e74..44b2180 100644
--- a/matrix.go
+++ b/matrix.go
@@ -3,7 +3,6 @@
 import (
 	"bufio"
 	"compress/gzip"
-	"fmt"
 	"io"
 	"log"
 	"os"
@@ -380,7 +379,7 @@
 			char = buffer[buffc]
 
 			if DEBUG {
-				fmt.Println("Current char", string(char), int(char), showBufferNew(buffer, bufft, buffc, buffi))
+				log.Println("Current char", string(char), int(char), showBufferNew(buffer, bufft, buffc, buffi))
 			}
 
 			eot = false
@@ -420,7 +419,7 @@
 				epsilonOffset = buffc
 
 				if DEBUG {
-					fmt.Println("epsilonOffset is set to", buffc)
+					log.Println("epsilonOffset is set to", buffc)
 				}
 			}
 		}
@@ -430,14 +429,14 @@
 
 		if DEBUG {
 			// Char is only relevant if set
-			fmt.Println("Check", t0, "-", a, "(", string(char), ")", "->", t)
+			log.Println("Check", t0, "-", a, "(", string(char), ")", "->", t)
 		}
 
 		// Check if the transition is invalid according to the matrix
 		if t == 0 {
 
 			if DEBUG {
-				fmt.Println("Match is not fine!")
+				log.Println("Match is not fine!")
 			}
 
 			if !ok && a == mat.identity {
@@ -445,7 +444,7 @@
 				// Try again with unknown symbol, in case identity failed
 				// Char is only relevant when set
 				if DEBUG {
-					fmt.Println("UNKNOWN symbol", string(char), "->", mat.unknown)
+					log.Println("UNKNOWN symbol", string(char), "->", mat.unknown)
 				}
 				a = mat.unknown
 
@@ -458,7 +457,7 @@
 				a = mat.epsilon
 
 				if DEBUG {
-					fmt.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
+					log.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
 				}
 
 			} else {
@@ -481,7 +480,7 @@
 			// Transition does not produce a character
 			if buffc-bufft == 1 && (t&FIRSTBIT) != 0 {
 				if DEBUG {
-					fmt.Println("Nontoken forward", showBufferNew(buffer, bufft, buffc, buffi))
+					log.Println("Nontoken forward", showBufferNew(buffer, bufft, buffc, buffi))
 				}
 				bufft++
 				// rewindBuffer = true
@@ -491,7 +490,7 @@
 			// Transition marks the end of a token - so flush the buffer
 			if buffc-bufft > 0 {
 				if DEBUG {
-					fmt.Println("-> Flush buffer: [", string(buffer[bufft:buffc]), "]", showBufferNew(buffer, bufft, buffc, buffi))
+					log.Println("-> Flush buffer: [", string(buffer[bufft:buffc]), "]", showBufferNew(buffer, bufft, buffc, buffi))
 				}
 				w.Token(bufft, buffer[:buffc])
 				rewindBuffer = true
@@ -509,7 +508,7 @@
 			w.TextEnd(buffc)
 			rewindBuffer = true
 			if DEBUG {
-				fmt.Println("END OF TEXT")
+				log.Println("END OF TEXT")
 			}
 		}
 
@@ -517,11 +516,11 @@
 		if rewindBuffer {
 
 			if DEBUG {
-				fmt.Println("-> Rewind buffer", bufft, buffc, buffi, epsilonOffset)
+				log.Println("-> Rewind buffer", bufft, buffc, buffi, epsilonOffset)
 			}
 
 			// TODO: Better as a ring buffer
-			// buffer = buffer[buffc:]
+			// buffer = buffer[buffc:] !slower
 			for x, i := range buffer[buffc:buffi] {
 				buffer[x] = i
 			}
@@ -535,7 +534,7 @@
 			bufft = 0
 
 			if DEBUG {
-				fmt.Println("Remaining:", showBufferNew(buffer, bufft, buffc, buffi))
+				log.Println("Remaining:", showBufferNew(buffer, bufft, buffc, buffi))
 			}
 		}
 
@@ -550,13 +549,13 @@
 	// Input reader is not yet finished
 	if !eof {
 		if DEBUG {
-			fmt.Println("Not at the end")
+			log.Println("Not at the end")
 		}
 		return false
 	}
 
 	if DEBUG {
-		fmt.Println("Entering final check")
+		log.Println("Entering final check")
 	}
 
 	// Check epsilon transitions as long as possible
@@ -574,7 +573,7 @@
 		epsilonState = 0 // reset
 		buffc = epsilonOffset
 		if DEBUG {
-			fmt.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
+			log.Println("Get from epsilon stack and set buffo!", showBufferNew(buffer, bufft, buffc, buffi))
 		}
 		goto PARSECHARM
 	}
@@ -585,7 +584,7 @@
 	if !sentenceEnd {
 		w.SentenceEnd(buffc)
 		if DEBUG {
-			fmt.Println("Sentence end")
+			log.Println("Sentence end")
 		}
 	}
 
@@ -593,7 +592,7 @@
 		w.TextEnd(buffc)
 
 		if DEBUG {
-			fmt.Println("Text end")
+			log.Println("Text end")
 		}
 	}