aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/main.go
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-09-08 16:54:17 +0200
committerPřemysl Janouch <p@janouch.name>2018-09-08 16:54:17 +0200
commit3173202cc1e08762c6e156a8fffd23269a5ddb2b (patch)
tree95c4a06f8384d41b15e9c22afac0a387de79dc51 /nexgb/xgbgen/main.go
parent632b3ae494d45755525644fe5d04475c95aae364 (diff)
parent3906399e7c2a40fbaf355de572cf50a314083f64 (diff)
downloadhaven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.gz
haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.xz
haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.zip
Merge aarzilli/xgb, branch xcb1.12 as nexgb
History has been linearized and rewritten to stay under the new subdirectory. I want to make changes incompatible to BurntSushi/xgb. The history begs for being thrown away entirely because of its quality and because it doesn't cover the Google period but it is still useful for copyright tracking.
Diffstat (limited to 'nexgb/xgbgen/main.go')
-rw-r--r--nexgb/xgbgen/main.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/nexgb/xgbgen/main.go b/nexgb/xgbgen/main.go
new file mode 100644
index 0000000..fd5eac7
--- /dev/null
+++ b/nexgb/xgbgen/main.go
@@ -0,0 +1,64 @@
+package main
+
+import (
+ "flag"
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+var (
+ protoPath = flag.String("proto-path",
+ "/usr/share/xcb", "path to directory of X protocol XML files")
+ gofmt = flag.Bool("gofmt", true,
+ "When disabled, gofmt will not be run before outputting Go code")
+)
+
+func usage() {
+ basename := os.Args[0]
+ if lastSlash := strings.LastIndex(basename, "/"); lastSlash > -1 {
+ basename = basename[lastSlash+1:]
+ }
+ log.Printf("Usage: %s [flags] xml-file", basename)
+ flag.PrintDefaults()
+ os.Exit(1)
+}
+
+func init() {
+ log.SetFlags(0)
+}
+
+func main() {
+ flag.Usage = usage
+ flag.Parse()
+
+ if flag.NArg() != 1 {
+ log.Printf("A single XML protocol file can be processed at once.")
+ flag.Usage()
+ }
+
+ // Read the single XML file into []byte
+ xmlBytes, err := ioutil.ReadFile(flag.Arg(0))
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // Initialize the buffer, parse it, and filter it through gofmt.
+ c := newContext()
+ c.Morph(xmlBytes)
+
+ if !*gofmt {
+ c.out.WriteTo(os.Stdout)
+ } else {
+ cmdGofmt := exec.Command("gofmt")
+ cmdGofmt.Stdin = c.out
+ cmdGofmt.Stdout = os.Stdout
+ cmdGofmt.Stderr = os.Stderr
+ err = cmdGofmt.Run()
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+}