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-04-30 08:44:31 +02:00
|
|
|
Imports XMLImports `xml:"import"`
|
|
|
|
Enums XMLEnums `xml:"enum"`
|
|
|
|
Xids XMLXids `xml:"xidtype"`
|
|
|
|
XidUnions XMLXids `xml:"xidunion"`
|
|
|
|
TypeDefs XMLTypeDefs `xml:"typedef"`
|
2012-04-30 08:40:55 +02:00
|
|
|
EventCopies XMLEventCopies `xml:"eventcopy"`
|
|
|
|
ErrorCopies XMLErrorCopies `xml:"errorcopy"`
|
2012-04-29 05:25:57 +02:00
|
|
|
|
|
|
|
// Here are the complex ones, i.e., anything with "structure contents"
|
2012-04-30 08:44:31 +02:00
|
|
|
Structs XMLStructs `xml:"struct"`
|
|
|
|
Unions XMLUnions `xml:"union"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Requests XMLRequests `xml:"request"`
|
2012-04-30 08:44:31 +02:00
|
|
|
Events XMLEvents `xml:"event"`
|
|
|
|
Errors XMLErrors `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 XMLEnums []XMLEnum
|
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 XMLXids []*XMLXid
|
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 XMLTypeDefs []*XMLTypeDef
|
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 XMLEventCopies []*XMLEventCopy
|
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 XMLErrorCopies []*XMLErrorCopy
|
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 XMLStructs []*XMLStruct
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLStruct struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Fields XMLFields `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLUnions []*XMLUnion
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLUnion struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Fields XMLFields `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLRequests []*XMLRequest
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLRequest struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Opcode int `xml:"opcode,attr"`
|
|
|
|
Combine bool `xml:"combine-adjacent,attr"`
|
|
|
|
Fields XMLFields `xml:",any"`
|
|
|
|
Reply *XMLReply `xml:"reply"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLReply struct {
|
|
|
|
Fields XMLFields `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEvents []*XMLEvent
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEvent struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
2012-05-02 07:46:30 +02:00
|
|
|
NoSequence bool `xml:"no-sequence-number,attr"`
|
2012-04-30 08:44:31 +02:00
|
|
|
Fields XMLFields `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLErrors []*XMLError
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLError struct {
|
2012-04-30 08:44:31 +02:00
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Number int `xml:"number,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
Fields XMLFields `xml:",any"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|