-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fmtabc.go
56 lines (52 loc) · 1.14 KB
/
fmtabc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bufio"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
)
var timeRe = regexp.MustCompile(`Time\s+=\s+(\d+\.\d+)`)
func getTime(line string) (float64, error) {
matches := timeRe.FindStringSubmatch(line)
if len(matches) == 0 {
return 0.0, fmt.Errorf("didn't match: %s\n", line)
}
secString := matches[1]
return strconv.ParseFloat(secString, 64)
}
func main() {
for _, fn := range os.Args[1:] {
f, e := os.Open(fn)
if e != nil {
log.Fatalf("error opening %s: %s\n", fn, e.Error())
}
scanner := bufio.NewScanner(f)
result := 2
var endLine string
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "of miter") {
result = 1
endLine = line
} else if strings.Contains(line, "UNDECIDED") {
result = 0
endLine = line
} else if strings.Contains(line, "proved") {
result = -1
endLine = line
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("error scanning: %s\n", err)
}
f.Close()
t, e := getTime(endLine)
if e != nil {
log.Fatalf("couldn't get time from '%s': %s\n", endLine, e.Error())
}
fmt.Printf("%s %d %f\n", fn, result, t)
}
}