-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (66 loc) · 1.46 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Author: https://github.com/lulzc
ToDo:
- cache stdout and add progress bar
- write output to db
*/
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"time"
)
func scanDir(filePath string) {
files, err := os.ReadDir(filePath)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
compilerInfov2(filePath + file.Name())
}
}
// using bufio NewReader instead of NewScanner
// NewScanner can be problematic for large files and needs to be adapted with the buffer size
func compilerInfov2(file string) error {
// define patterns for different cases
patterns := map[string][]string{
"rust": {"RUST_BACKTRACE=1", "Option::unwrap()", "Result::unwrap()"},
"go": {"Go build ID:", "go.buildid", "runtime.gcWork"},
"zig": {"ZIG_DEBUG_COLOR", "\\\\.\\pipe\\zig-childprocess-{d}-{d}"},
"mingw": {"Mingw runtime failure:", "_Jv_RegisterClasses"},
}
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
return err
}
defer f.Close()
reader := bufio.NewReader(f)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
for key, pat := range patterns {
for _, p := range pat {
if strings.Contains(line, p) {
fmt.Printf("%s found pattern: %s\n", file, key)
}
break
}
}
}
return nil
}
func main() {
start := time.Now()
filePath := os.Args[1]
scanDir(filePath)
// run on single file
//compilerInfov2(filePath)
elapsed := time.Since(start)
fmt.Println("Execution time:", elapsed)
}