-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
message2array.go
52 lines (46 loc) · 906 Bytes
/
message2array.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
package main
import (
"bufio"
"fmt"
"log"
"os"
"regexp"
)
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer file.Close()
seenHeader := false
scanner := bufio.NewScanner(file)
rh, err := regexp.Compile("Channel symbols")
if err != nil {
log.Fatal(err)
}
rt, err := regexp.Compile("^[ \t\n]*$") // empty line
if err != nil {
log.Fatal(err)
}
output := ""
for scanner.Scan() {
if rh.MatchString(scanner.Text()) {
seenHeader = true
} else if seenHeader == true {
if seenHeader == true && rt.MatchString(scanner.Text()) {
break
} else {
output = output + scanner.Text()
}
}
}
fmt.Print("const uint8_t FST4Wsymbols[FST4W_SYMBOL_COUNT] = { ")
fmt.Printf("%c", output[0])
for _, char := range output[1:] {
fmt.Printf(", %c ", char)
}
fmt.Println("};")
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}