[Xcb] implemented support for switch-case

Christian Linhart chris at DemoRecorder.com
Tue Aug 19 06:51:29 PDT 2014


Hi,

I have implemented support for switch-case in the generator,
and have verified this with one example in xinput.xml.

In the next four posts, I'll send the patches.

The implementation does not change the output of the generator
unless <case> is used.

In the one example, the output changes as shown in the 
P.S. of this email.

The implementation is rather simple: 
When a <case> is used instead of a <bitcase>
then operator "==" is used instead of "&" in the if-condition.

So it creates a series of "if" statements
(instead of a switch-case statement in C )

In practice this does not matter because a good 
optimizing compiler will create the same code
as for a switch-case.

With this simple implementation we get additional
flexibility in the following forms:
* a case value may appear in multiple case branches.
  for example:
	case C1 will be selected by values 1, 4, or 5
	case C2 will be selected by values 3, 4, or 7
	
* mixing of bitcase and case is possible
	(this will usually make no sense but there may
	be protocol specs where this is needed)


Chris


P.S.: Below is the change of the output when the bitcases 
in ChangeDeviceProperty are made cases ( as they should ):

Please note: This is not a patch, but the effect on the generated output.

--- oldsrc/xinput.c	2014-08-19 13:58:37.612523122 +0200
+++ xinput.c	2014-08-19 14:10:52.632520523 +0200
@@ -5223,7 +5223,7 @@
     unsigned int i;
     char *xcb_tmp;
 
-    if(format & XCB_INPUT_PROPERTY_FORMAT_8_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_8_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;
@@ -5252,7 +5252,7 @@
         }
         xcb_block_len = 0;
     }
-    if(format & XCB_INPUT_PROPERTY_FORMAT_16_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_16_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;
@@ -5281,7 +5281,7 @@
         }
         xcb_block_len = 0;
     }
-    if(format & XCB_INPUT_PROPERTY_FORMAT_32_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_32_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;
@@ -5340,7 +5340,7 @@
     unsigned int xcb_align_to = 0;
 
 
-    if(format & XCB_INPUT_PROPERTY_FORMAT_8_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_8_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;
@@ -5364,7 +5364,7 @@
         }
         xcb_block_len = 0;
     }
-    if(format & XCB_INPUT_PROPERTY_FORMAT_16_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_16_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;
@@ -5388,7 +5388,7 @@
         }
         xcb_block_len = 0;
     }
-    if(format & XCB_INPUT_PROPERTY_FORMAT_32_BITS) {
+    if(format == XCB_INPUT_PROPERTY_FORMAT_32_BITS) {
         /* insert padding */
         xcb_pad = -xcb_block_len & (xcb_align_to - 1);
         xcb_buffer_len += xcb_block_len + xcb_pad;


More information about the Xcb mailing list