2012-04-29 05:25:57 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type XML struct {
|
|
|
|
// Root 'xcb' element properties.
|
2012-04-30 08:44:31 +02:00
|
|
|
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"`
|
2012-04-29 05:25:57 +02:00
|
|
|
|
|
|
|
// Types for all top-level elements.
|
|
|
|
// First are the simple ones.
|
2012-05-07 10:09:19 +02:00
|
|
|
Imports XMLImports `xml:"import"`
|
|
|
|
Enums []*XMLEnum `xml:"enum"`
|
|
|
|
Xids []*XMLXid `xml:"xidtype"`
|
|
|
|
XidUnions []*XMLXid `xml:"xidunion"`
|
|
|
|
TypeDefs []*XMLTypeDef `xml:"typedef"`
|
2012-05-06 08:21:31 +02:00
|
|
|
EventCopies []*XMLEventCopy `xml:"eventcopy"`
|
|
|
|
ErrorCopies []*XMLErrorCopy `xml:"errorcopy"`
|
2012-04-29 05:25:57 +02:00
|
|
|
|
|
|
|
// Here are the complex ones, i.e., anything with "structure contents"
|
2012-05-06 08:21:31 +02:00
|
|
|
Structs []*XMLStruct `xml:"struct"`
|
|
|
|
Unions []*XMLUnion `xml:"union"`
|
|
|
|
Requests []*XMLRequest `xml:"request"`
|
|
|
|
Events []*XMLEvent `xml:"event"`
|
|
|
|
Errors []*XMLError `xml:"error"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLImports []*XMLImport
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
func (imports XMLImports) Eval() {
|
2012-04-29 05:25:57 +02:00
|
|
|
for _, imp := range imports {
|
|
|
|
xmlBytes, err := ioutil.ReadFile(*protoPath + "/" + imp.Name + ".xml")
|
|
|
|
if err != nil {
|
2012-04-30 08:44:31 +02:00
|
|
|
log.Fatalf("Could not read X protocol description for import "+
|
2012-04-29 05:25:57 +02:00
|
|
|
"'%s' because: %s", imp.Name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
imp.xml = &XML{}
|
|
|
|
err = xml.Unmarshal(xmlBytes, imp.xml)
|
|
|
|
if err != nil {
|
2012-04-30 08:44:31 +02:00
|
|
|
log.Fatal("Could not parse X protocol description for import "+
|
2012-04-29 05:25:57 +02:00
|
|
|
"'%s' because: %s", imp.Name, err)
|
|
|
|
}
|
2012-04-30 08:40:55 +02:00
|
|
|
|
|
|
|
// recursive imports...
|
|
|
|
imp.xml.Imports.Eval()
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLImport struct {
|
2012-04-29 05:25:57 +02:00
|
|
|
Name string `xml:",chardata"`
|
2012-04-30 08:44:31 +02:00
|
|
|
xml *XML `xml:"-"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEnum struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Items []*XMLEnumItem `xml:"item"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEnumItem struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Expr *XMLExpression `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLXid struct {
|
2012-04-29 05:25:57 +02:00
|
|
|
XMLName xml.Name
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLTypeDef struct {
|
|
|
|
Old string `xml:"oldname,attr"`
|
|
|
|
New string `xml:"newname,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEventCopy struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
|
|
|
Ref string `xml:"ref,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLErrorCopy struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
|
|
|
Ref string `xml:"ref,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLStruct struct {
|
2012-05-07 10:09:19 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-05-06 08:21:31 +02:00
|
|
|
Fields []*XMLField `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLUnion struct {
|
2012-05-07 10:09:19 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-05-06 08:21:31 +02:00
|
|
|
Fields []*XMLField `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLRequest struct {
|
2012-05-07 10:09:19 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Opcode int `xml:"opcode,attr"`
|
|
|
|
Combine bool `xml:"combine-adjacent,attr"`
|
2012-05-06 08:21:31 +02:00
|
|
|
Fields []*XMLField `xml:",any"`
|
2012-05-07 10:09:19 +02:00
|
|
|
Reply *XMLReply `xml:"reply"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLReply struct {
|
2012-05-06 08:21:31 +02:00
|
|
|
Fields []*XMLField `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEvent struct {
|
2012-05-07 10:09:19 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
|
|
|
NoSequence bool `xml:"no-sequence-number,attr"`
|
2012-05-06 08:21:31 +02:00
|
|
|
Fields []*XMLField `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLError struct {
|
2012-05-07 10:09:19 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
2012-05-06 08:21:31 +02:00
|
|
|
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"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|