|
|
|
package main
|
|
|
|
|
|
|
|
// results.go: saves good results to a file or console
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerParam("out-file", "good.txt", "results will be saved in this file")
|
|
|
|
registerAlias("o", "out-file")
|
|
|
|
}
|
|
|
|
|
|
|
|
var outFile *os.File
|
|
|
|
var resultChannel chan *Task
|
|
|
|
|
|
|
|
func ResultService() {
|
|
|
|
openResultFile()
|
|
|
|
defer closeResultFile()
|
|
|
|
|
|
|
|
resultChannel = make(chan *Task, 128)
|
|
|
|
|
|
|
|
for task := range resultChannel {
|
|
|
|
if outFile != nil {
|
|
|
|
fmt.Fprintf(outFile, "%v\n", task.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func RegisterResult(task *Task, good bool) {
|
|
|
|
if !good {
|
|
|
|
log("res", 1, "bad: %v", task.String())
|
|
|
|
} else {
|
|
|
|
log("res", 0, "good: %v", task.String())
|
|
|
|
if outFile != nil {
|
|
|
|
resultChannel <- task
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func EndResults() {
|
|
|
|
close(resultChannel)
|
|
|
|
}
|
|
|
|
|
|
|
|
func openResultFile() {
|
|
|
|
fileName := getParamString("out-file")
|
|
|
|
if fileName == "" {
|
|
|
|
log("out", 0, "WARNING: out-file is not specified, results will only be logged in console")
|
|
|
|
outFile = nil
|
|
|
|
} else {
|
|
|
|
var err error
|
|
|
|
outFile, err = os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fail("error opening result file \"%v\": %v", fileName, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
log("out", 2, "opened result file \"%v\"", fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeResultFile() {
|
|
|
|
if outFile != nil {
|
|
|
|
outFile.Close()
|
|
|
|
outFile = nil
|
|
|
|
log("out", 2, "closed result file")
|
|
|
|
}
|
|
|
|
}
|