aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/xml.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/xml.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/xml.go')
-rw-r--r--nexgb/xgbgen/xml.go138
1 files changed, 138 insertions, 0 deletions
diff --git a/nexgb/xgbgen/xml.go b/nexgb/xgbgen/xml.go
new file mode 100644
index 0000000..440d0a8
--- /dev/null
+++ b/nexgb/xgbgen/xml.go
@@ -0,0 +1,138 @@
+package main
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "log"
+)
+
+type XML struct {
+ // Root 'xcb' element properties.
+ XMLName xml.Name `xml:"xcb"`
+ Header string `xml:"header,attr"`
+ ExtensionXName string `xml:"extension-xname,attr"`
+ ExtensionName string `xml:"extension-name,attr"`
+ MajorVersion string `xml:"major-version,attr"`
+ MinorVersion string `xml:"minor-version,attr"`
+
+ // Types for all top-level elements.
+ // First are the simple ones.
+ Imports XMLImports `xml:"import"`
+ Enums []*XMLEnum `xml:"enum"`
+ Xids []*XMLXid `xml:"xidtype"`
+ XidUnions []*XMLXid `xml:"xidunion"`
+ TypeDefs []*XMLTypeDef `xml:"typedef"`
+ EventCopies []*XMLEventCopy `xml:"eventcopy"`
+ ErrorCopies []*XMLErrorCopy `xml:"errorcopy"`
+
+ // Here are the complex ones, i.e., anything with "structure contents"
+ Structs []*XMLStruct `xml:"struct"`
+ Unions []*XMLUnion `xml:"union"`
+ Requests []*XMLRequest `xml:"request"`
+ Events []*XMLEvent `xml:"event"`
+ Errors []*XMLError `xml:"error"`
+}
+
+type XMLImports []*XMLImport
+
+func (imports XMLImports) Eval() {
+ for _, imp := range imports {
+ xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml")
+ if err != nil {
+ log.Fatalf("Could not read X protocol description for import "+
+ "'%s' because: %s", imp.Name, err)
+ }
+
+ imp.xml = &XML{}
+ err = xml.Unmarshal(xmlBytes, imp.xml)
+ if err != nil {
+ log.Fatal("Could not parse X protocol description for import "+
+ "'%s' because: %s", imp.Name, err)
+ }
+
+ // recursive imports...
+ imp.xml.Imports.Eval()
+ }
+}
+
+type XMLImport struct {
+ Name string `xml:",chardata"`
+ xml *XML `xml:"-"`
+}
+
+type XMLEnum struct {
+ Name string `xml:"name,attr"`
+ Items []*XMLEnumItem `xml:"item"`
+}
+
+type XMLEnumItem struct {
+ Name string `xml:"name,attr"`
+ Expr *XMLExpression `xml:",any"`
+}
+
+type XMLXid struct {
+ XMLName xml.Name
+ Name string `xml:"name,attr"`
+}
+
+type XMLTypeDef struct {
+ Old string `xml:"oldname,attr"`
+ New string `xml:"newname,attr"`
+}
+
+type XMLEventCopy struct {
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ Ref string `xml:"ref,attr"`
+}
+
+type XMLErrorCopy struct {
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ Ref string `xml:"ref,attr"`
+}
+
+type XMLStruct struct {
+ Name string `xml:"name,attr"`
+ Fields []*XMLField `xml:",any"`
+}
+
+type XMLUnion struct {
+ Name string `xml:"name,attr"`
+ Fields []*XMLField `xml:",any"`
+}
+
+type XMLRequest struct {
+ Name string `xml:"name,attr"`
+ Opcode int `xml:"opcode,attr"`
+ Combine bool `xml:"combine-adjacent,attr"`
+ Fields []*XMLField `xml:",any"`
+ Reply *XMLReply `xml:"reply"`
+}
+
+type XMLReply struct {
+ Fields []*XMLField `xml:",any"`
+}
+
+type XMLEvent struct {
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ NoSequence bool `xml:"no-sequence-number,attr"`
+ Fields []*XMLField `xml:",any"`
+}
+
+type XMLError struct {
+ Name string `xml:"name,attr"`
+ Number int `xml:"number,attr"`
+ Fields []*XMLField `xml:",any"`
+}
+
+type XMLExpression struct {
+ XMLName xml.Name
+
+ Exprs []*XMLExpression `xml:",any"`
+
+ Data string `xml:",chardata"`
+ Op string `xml:"op,attr"`
+ Ref string `xml:"ref,attr"`
+}