Source file
src/syscall/mkpost.go
1
2
3
4
5
6
7
8
9
10
11
12 package main
13
14 import (
15 "fmt"
16 "go/format"
17 "io"
18 "log"
19 "os"
20 "regexp"
21 "strings"
22 )
23
24 func main() {
25 b, err := io.ReadAll(os.Stdin)
26 if err != nil {
27 log.Fatal(err)
28 }
29 s := string(b)
30
31 goarch := os.Getenv("GOARCH")
32 goos := os.Getenv("GOOS")
33 switch {
34 case goarch == "s390x" && goos == "linux":
35
36 re := regexp.MustCompile("ptrace(Psw|Fpregs|Per)")
37 s = re.ReplaceAllString(s, "Ptrace$1")
38
39
40 re = regexp.MustCompile("Pad_cgo[A-Za-z0-9_]*")
41 s = re.ReplaceAllString(s, "_")
42
43
44 s = strings.Replace(s, "X__val", "MKPOSTFSIDVAL", 1)
45
46
47 re = regexp.MustCompile("X_[A-Za-z0-9_]*")
48 s = re.ReplaceAllString(s, "_")
49
50
51 s = strings.Replace(s, "MKPOSTFSIDVAL", "X__val", 1)
52
53
54
55 re = regexp.MustCompile("(Data\\s+\\[14\\])uint8")
56 s = re.ReplaceAllString(s, "${1}int8")
57
58 case goos == "freebsd":
59
60 re := regexp.MustCompile("(A|M|C|Birth)tim\\s+Timespec")
61 s = re.ReplaceAllString(s, "${1}timespec Timespec")
62 }
63
64
65 b, err = format.Source([]byte(s))
66 if err != nil {
67 log.Fatal(err)
68 }
69
70
71
72 re := regexp.MustCompile("(cgo -godefs [a-zA-Z0-9_]+\\.go.*)")
73 s = re.ReplaceAllString(string(b), "$1 | go run mkpost.go")
74
75 fmt.Print(s)
76 }
77
View as plain text