2012-04-29 05:25:57 +02:00
|
|
|
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.
|
2012-04-30 08:40:55 +02:00
|
|
|
Imports XMLImports `xml:"import"`
|
|
|
|
Enums XMLEnums `xml:"enum"`
|
|
|
|
Xids XMLXids `xml:"xidtype"`
|
|
|
|
XidUnions XMLXids `xml:"xidunion"`
|
|
|
|
TypeDefs XMLTypeDefs `xml:"typedef"`
|
|
|
|
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:40:55 +02:00
|
|
|
Structs XMLStructs `xml:"struct"`
|
|
|
|
Unions XMLUnions `xml:"union"`
|
|
|
|
Requests XMLRequests `xml:"request"`
|
|
|
|
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 {
|
|
|
|
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)
|
|
|
|
}
|
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"`
|
|
|
|
xml *XML `xml:"-"`
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
Items []*XMLEnumItem `xml:"item"`
|
2012-04-29 05:25:57 +02:00
|
|
|
}
|
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLEnumItem struct {
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
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:40:55 +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 {
|
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 09:38:29 +02:00
|
|
|
Number int `xml:"number,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 09:38:29 +02:00
|
|
|
Number int `xml:"number,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
Opcode int `xml:"opcode,attr"`
|
|
|
|
Combine bool `xml:"combine-adjacent,attr"`
|
2012-04-30 08:40:55 +02:00
|
|
|
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 {
|
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
Number int `xml:"number,attr"`
|
|
|
|
NoSequence bool `xml:"no-sequence-number,true"`
|
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 XMLErrors []*XMLError
|
2012-04-29 05:25:57 +02:00
|
|
|
|
2012-04-30 08:40:55 +02:00
|
|
|
type XMLError struct {
|
|
|
|
Name string `xml:"name,attr"`
|
2012-04-29 05:25:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|