9 echo "/***********************************************************"
11 echo " ***********************************************************/"
15 printf "\t%-30s = %s,\n" "$(upper $1)" "$2"
19 echo $1 | tr 'a-z' 'A-Z'
24 xmllint --xpath $1 wayland.xml
28 xpath $1 | sed -r 's/\w+="([^"]+)"/\1/g'
32 xpath "$1" > /dev/null 2>&1
36 exists "$1/arg[@type='string']|$1/arg[@type='array']|$1/arg[@type='fd']"
42 int) echo -e "\tint32_t $2;" ;;
43 uint) echo -e "\tuint32_t $2;" ;;
44 new_id) echo -e "\tuint32_t $2;" ;;
45 object) echo -e "\tuint32_t $2;" ;;
46 fixed) echo -e "\twl_fixed_t $2;" ;;
47 array) echo -e "\twl_array_t $2;" ;;
48 string) echo -e "\twl_string_t $2;" ;;
54 for t in $(xpathv "$1"); do
57 string) echo -n "s" ;;
65 function print_iface_vers {
68 vers=$(xpath "string(/protocol/interface[@name='$i']/@version)")
69 printf "#define %-32s %s\n" "$(upper ${i}_version)" "$vers"
73 function print_iface_enum {
77 enum "${i}" $((cnt++))
79 enum "wl_num_interfaces" $((cnt++))
82 # Enumeration functions
83 function print_enums {
85 base="/protocol/interface[@name='$i']/enum"
86 if exists "$base"; then
88 for e in $(xpathv "$base/@name"); do
90 for n in $(xpathv "$base[@name='$e']/entry/@name"); do
91 k="$base[@name='$e']/entry[@name='$n']/@value"
92 v=$(xpath "string($k)")
93 printf "\t%-40s = %s,\n" \
94 "$(upper "${i}_${e}_${n}")" "$v"
103 function print_msg_ids {
106 base="/protocol/interface[@name='$IFACE']/$2"
107 if exists "$base"; then
109 echo "typedef enum {"
110 for r in $(xpathv "$base/@name"); do
111 enum "${IFACE}_${r}" $((cnt++))
113 enum "${IFACE/wl/wl_num}_${2}s" $((cnt++))
114 echo "} ${IFACE}_${2}_t;"
119 function print_msg_defs {
120 local base msgs args k t
121 base="/protocol/interface[@name='$IFACE']/$2"
122 if exists "$base/arg"; then
124 msgs=$(xpathv "$base/@name")
126 if exists "$base[@name='$m']/arg"; then
127 echo "typedef struct {"
128 args=$(xpathv "$base[@name='$m']/arg/@name")
130 k="$base[@name='$m']/arg[@name='$a']/@type"
131 t=$(xpath "string($k)")
134 echo "} ${IFACE}_${m}_t;"
141 function print_msg_union {
143 for IFACE in $IFACES; do
144 base="/protocol/interface[@name='$IFACE']/$1"
145 if exists "$base"; then
146 for r in $(xpathv "$base/@name"); do
147 if exists "$base[@name='$r']/arg"; then
149 n="${IFACE}_${r/wl_/}"
150 printf '\t%-50s %s;\n' "$t" "$n"
157 function print_msg_table {
158 local base size idx str
159 for IFACE in $IFACES; do
160 base="/protocol/interface[@name='$IFACE']/$1"
161 size="$(upper "${IFACE/wl/wl_num}_${1}s")"
162 if isarray "$base"; then
163 echo -e "\t[$(upper $IFACE)] (const char *[$size]) {"
164 for r in $(xpathv "$base/@name"); do
165 if isarray "$base[@name='$r']"; then
166 idx="$(upper "${IFACE}_${r}")"
167 str="$(msg_array "$base[@name='$r']/arg/@type")"
168 printf '\t\t%-30s "%s",\n' "[$idx]" "$str"
177 IFACES=$(xpathv "/protocol/interface/@name")
185 $(banner "Common Types")
187 #define WL_MESSAGE_LEN 4096
210 $(banner "Interfaces")
212 /* Interface Versions */
220 $(for IFACE in $IFACES; do
221 banner "Interface $(upper $IFACE)"
223 print_msg_ids "Request IDs" request
224 print_msg_ids "Event IDs" event
225 print_enums "Enumerations"
226 print_msg_defs "Requests Messages" request
227 print_msg_defs "Events Messages" event
232 $(print_msg_union request)
236 $(print_msg_union event)
239 $(banner "Arrays and Strings")
242 #define WL_ARRAY_NONE '-'
243 #define WL_ARRAY_STRING 's'
244 #define WL_ARRAY_ARRAY 'a'
245 #define WL_ARRAY_FD 'f'
247 extern const char **wl_rarray[WL_NUM_INTERFACES];
248 extern const char **wl_earray[WL_NUM_INTERFACES];
251 #ifdef WL_DEFINE_TABLES
252 const char **wl_rarray[WL_NUM_INTERFACES] = {
253 $(print_msg_table request)
258 #ifdef WL_DEFINE_TABLES
259 const char **wl_earray[WL_NUM_INTERFACES] = {
260 $(print_msg_table event)