joystick.c: Fix trailing '\n' in trace()

Francois Gouget fgouget at free.fr
Mon Jul 11 07:05:37 CDT 2005


Robert Reif told me that the trailing '\r' in joystick.c was 
intentional: the reasoning is that this code is only executed in 
interactive mode and the idea was to return to the start of the line to 
overwrite the previous line so that the user does not get 300 lines of 
traces.

But the line length can reach up to 246 characters (without the '\r') 
which would cause a line wrap so that the '\r' would not work anyway. 
Alexandre suggests that a better solution would be to print a new trace 
only when the joystick state has changed. So here is a new patch 
doing just that.


Changelog:

  * dlls/dinput/tests/joystick.c

    Francois Gouget <fgouget at free.fr>
    Only print the joystick state when it changes so the user does not 
get 300 lines of traces.

-- 
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
         War doesn't determine who's right.  War determines who's left.
-------------- next part --------------
Index: dlls/dinput/tests/joystick.c
===================================================================
RCS file: /var/cvs/wine/dlls/dinput/tests/joystick.c,v
retrieving revision 1.5
diff -u -p -r1.5 joystick.c
--- dlls/dinput/tests/joystick.c	6 Jul 2005 15:46:47 -0000	1.5
+++ dlls/dinput/tests/joystick.c	11 Jul 2005 11:44:09 -0000
@@ -24,6 +23,7 @@
 #include <windows.h>
 
 #include <math.h>
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "wine/test.h"
@@ -139,6 +139,7 @@ static BOOL CALLBACK EnumJoysticks(
     DIDEVICEINSTANCE inst;
     DIDEVICEINSTANCE_DX3 inst3;
     HWND hWnd = get_hwnd();
+    char oldstate[248], curstate[248];
 
     ok(data->version > 0x0300, "Joysticks not supported in version 0x%04lx\n", data->version);
  
@@ -262,13 +263,14 @@ static BOOL CALLBACK EnumJoysticks(
         count = 1;
 
     trace("\n");
+    oldstate[0]='\0';
     for (i = 0; i < count; i++) {
         hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
         ok(hr==DI_OK,"IDirectInputDevice_GetDeviceState() failed: %s\n",
            DXGetErrorString8(hr));
         if (hr != DI_OK)
             break;
-        trace("X%5ld Y%5ld Z%5ld Rx%5ld Ry%5ld Rz%5ld "
+        sprintf(curstate, "X%5ld Y%5ld Z%5ld Rx%5ld Ry%5ld Rz%5ld "
               "S0%5ld S1%5ld POV0%5ld POV1%5ld POV2%5ld POV3%5ld "
               "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
               js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz,
@@ -278,6 +280,11 @@ static BOOL CALLBACK EnumJoysticks(
               js.rgbButtons[3]>>7, js.rgbButtons[4]>>7, js.rgbButtons[5]>>7,
               js.rgbButtons[6]>>7, js.rgbButtons[7]>>7, js.rgbButtons[8]>>7,
               js.rgbButtons[9]>>7, js.rgbButtons[10]>>7, js.rgbButtons[11]>>7);
+        if (strcmp(oldstate, curstate) != 0)
+        {
+            trace(curstate);
+            strcpy(oldstate, curstate);
+        }
         Sleep(100);
     }
     trace("\n");


More information about the wine-patches mailing list