Cleaned up some coding style to match my current mood. :)
authorRyan C. Gordon <icculus@icculus.org>
Tue, 26 Apr 2011 17:57:29 -0400
changeset 103 924a3c5880ce
parent 102 4c6216abf84e
child 104 778820172c16
Cleaned up some coding style to match my current mood. :)
example/detect_mice.c
example/manymousepong.c
example/mmpong.c
example/test_manymouse_stdio.c
linux_evdev.c
macosx_hidutilities.c
manymouse.c
windows_wminput.c
x11_xinput2.c
--- a/example/detect_mice.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/example/detect_mice.c	Tue Apr 26 17:57:29 2011 -0400
@@ -18,7 +18,7 @@
     if (available_mice <= 0)
     {
         printf("No mice detected!\n");
-        return(1);
+        return 1;
     }
     else
     {
@@ -28,8 +28,8 @@
             printf("#%d: %s\n", i, ManyMouse_DeviceName(i));
     }
     ManyMouse_Quit();
-    return(0);
-}
+    return 0;
+} /* main */
 
 /* end of detect_mice.c ... */
 
--- a/example/manymousepong.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/example/manymousepong.c	Tue Apr 26 17:57:29 2011 -0400
@@ -103,7 +103,7 @@
     if (!SDL_WasInit(SDL_INIT_VIDEO))
     {
         if (SDL_Init(SDL_INIT_VIDEO) == -1)
-            return(0);
+            return 0;
     } /* if */
 
     SDL_WM_GrabInput(sdlgrab ? SDL_GRAB_ON : SDL_GRAB_OFF);
@@ -114,7 +114,7 @@
     if (screen == NULL)
     {
         SDL_Quit();
-        return(0);
+        return 0;
     } /* if */
 
     /*
@@ -139,13 +139,13 @@
     for (i = 0; i < MAX_BALLS; i++)
         balls[i].blanked = 1;
     
-    return(1);  /* we're good to go. */
+    return 1;  /* we're good to go. */
 } /* initVideo */
 
 
 static inline PaddleSide getPaddleSide(int paddleidx)
 {
-    return((PaddleSide) (paddleidx % 4));
+    return (PaddleSide) (paddleidx % 4);
 } /* getPaddleSide */
 
 
@@ -189,7 +189,7 @@
 
     setSidesExists();
 
-    return(1);
+    return 1;
 } /* initMice */
 
 
@@ -227,7 +227,7 @@
     static int nextcolor = 0;
     const RGB *color = &colorArray[nextcolor++];
     nextcolor %= (sizeof (colorArray) / sizeof (colorArray[0]));
-    return(SDL_MapRGB(screen->format, color->r, color->g, color->b));
+    return SDL_MapRGB(screen->format, color->r, color->g, color->b);
 } /* standardizedColor */
 
 
@@ -237,7 +237,7 @@
     Uint8 r = (Uint8) (255.0f*rand()/(RAND_MAX+1.0f));
     Uint8 g = (Uint8) (255.0f*rand()/(RAND_MAX+1.0f));
     Uint8 b = (Uint8) (255.0f*rand()/(RAND_MAX+1.0f));
-    return(SDL_MapRGB(screen->format, r, g, b));
+    return SDL_MapRGB(screen->format, r, g, b);
 } /* randomizedColor */
 #endif
 
@@ -405,11 +405,11 @@
         switch (event.type)
         {
             case SDL_QUIT:  /* window was closed, etc. */
-                return(0);
+                return 0;
 
             case SDL_KEYDOWN:
                 if (event.key.keysym.sym == SDLK_ESCAPE)
-                    return(0);  /* quit. */
+                    return 0;  /* quit. */
 
 
                 else if (event.key.keysym.sym == SDLK_KP_PLUS)
@@ -474,7 +474,7 @@
                         if (!initVideo())
                         {
                             printf("window/fullscreen toggle failed!\n");
-                            return(0);  /* quit */
+                            return 0;  /* quit */
                         } /* if */
 
                         /*
@@ -496,7 +496,7 @@
         } /* switch */
     } /* while */
 
-    return(1);  /* no quit events this time. */
+    return 1;  /* no quit events this time. */
 } /* updateInput */
 
 
@@ -632,12 +632,12 @@
     /* bounding box must be normalized. */
 
     if ((x < bx1) || (x > bx2))
-        return(0);
+        return 0;
 
     if ((y < by1) || (y > by2))
-        return(0);
+        return 0;
 
-    return(1);
+    return 1;
 } /* inRect */
 
 
@@ -645,14 +645,14 @@
                                int bx1, int by1, int bx2, int by2)
 {
     /* if any corner of a rect is in the other, it's a collision. */
-    return((inRect(px1, py1, bx1, by1, bx2, by2)) ||
-           (inRect(px2, py1, bx1, by1, bx2, by2)) ||
-           (inRect(px1, py2, bx1, by1, bx2, by2)) ||
-           (inRect(px2, py2, bx1, by1, bx2, by2)) ||
-           (inRect(bx1, by1, px1, py1, px2, py2)) ||
-           (inRect(bx2, by1, px1, py1, px2, py2)) ||
-           (inRect(bx1, by2, px1, py1, px2, py2)) ||
-           (inRect(bx2, by2, px1, py1, px2, py2)));
+    return ( (inRect(px1, py1, bx1, by1, bx2, by2)) ||
+             (inRect(px2, py1, bx1, by1, bx2, by2)) ||
+             (inRect(px1, py2, bx1, by1, bx2, by2)) ||
+             (inRect(px2, py2, bx1, by1, bx2, by2)) ||
+             (inRect(bx1, by1, px1, py1, px2, py2)) ||
+             (inRect(bx2, by1, px1, py1, px2, py2)) ||
+             (inRect(bx1, by2, px1, py1, px2, py2)) ||
+             (inRect(bx2, by2, px1, py1, px2, py2)) );
 } /* intersection */
 
 
@@ -662,10 +662,10 @@
     if (sideExists[side])
     {
         triggerScore(ball, side);
-        return(0);
+        return 0;
     } /* if */
 
-    return(1);
+    return 1;
 } /* scoreOrBounce */
 
 
@@ -914,11 +914,11 @@
         else
         {
             printf("Unknown command line '%s'\n", arg);
-            return(0);
+            return 0;
         } /* else */
     } /* for */
 
-    return(1);
+    return 1;
 } /* processCmdLines */
 
 
@@ -950,17 +950,17 @@
 int main(int argc, char **argv)
 {
     if (!processCmdLines(argc, argv))
-        return(42);
+        return 42;
 
     if (!initVideo())
-        return(42);
+        return 42;
 
     initThings();
 
     if (!initMice())
     {
         SDL_Quit();
-        return(42);
+        return 42;
     } /* if */
 
     updateFPS(1);
@@ -973,7 +973,7 @@
 
     ManyMouse_Quit();
     SDL_Quit();  /* clean up video mode, etc. */
-    return(0);
+    return 0;
 } /* main */
 
 /* end of manymousepong.c ... */
--- a/example/mmpong.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/example/mmpong.c	Tue Apr 26 17:57:29 2011 -0400
@@ -311,5 +311,5 @@
 	/* Clean up the SDL library */
 	ManyMouse_Quit();
 	SDL_Quit();
-	return(0);
+	return 0;
 }
--- a/example/test_manymouse_stdio.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/example/test_manymouse_stdio.c	Tue Apr 26 17:57:29 2011 -0400
@@ -19,12 +19,12 @@
     if (available_mice < 0)
     {
         printf("Error initializing ManyMouse!\n");
-        return(2);
+        return 2;
     }
     else if (available_mice == 0)
     {
         printf("No mice detected!\n");
-        return(1);
+        return 1;
     }
     else
     {
@@ -88,7 +88,7 @@
     }
 
     ManyMouse_Quit();
-    return(0);
+    return 0;
 }
 
 /* end of test_manymouse_stdio.c ... */
--- a/linux_evdev.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/linux_evdev.c	Tue Apr 26 17:57:29 2011 -0400
@@ -51,17 +51,17 @@
         if (br == -1)
         {
             if (errno == EAGAIN)
-                return(0);  /* just no new data at the moment. */
+                return 0;  /* just no new data at the moment. */
 
             /* mouse was unplugged? */
             close(mouse->fd);  /* stop reading from this mouse. */
             mouse->fd = -1;
             outevent->type = MANYMOUSE_EVENT_DISCONNECT;
-            return(1);
+            return 1;
         } /* if */
 
         if (br != sizeof (event))
-            return(0);  /* oh well. */
+            return 0;  /* oh well. */
 
         unhandled = 0;  /* will reset if necessary. */
         outevent->value = event.value;
@@ -141,7 +141,7 @@
         } /* else */
     } /* while */
 
-    return(1);  /* got a valid event */
+    return 1;  /* got a valid event */
 } /* poll_mouse */
 
 
@@ -285,9 +285,7 @@
 
 static const char *linux_evdev_name(unsigned int index)
 {
-    if (index < available_mice)
-        return(mice[index].name);
-    return(NULL);
+    return (index < available_mice) ? mice[index].name : NULL;
 } /* linux_evdev_name */
 
 
@@ -312,14 +310,14 @@
                 if (poll_mouse(mouse, event))
                 {
                     event->device = i;
-                    return(1);
+                    return 1;
                 } /* if */
             } /* if */
             i++;
         } /* while */
     } /* if */
 
-    return(0);  /* no new events */
+    return 0;  /* no new events */
 } /* linux_evdev_poll */
 
 static const ManyMouseDriver ManyMouseDriver_interface =
--- a/macosx_hidutilities.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/macosx_hidutilities.c	Tue Apr 26 17:57:29 2011 -0400
@@ -1486,7 +1486,7 @@
         IOHIDEventStruct event;
 
         if (!HIDGetEvent(mouse, &event))
-            return(0);  /* no new event. */
+            return 0;  /* no new event. */
 
         unhandled = 0;  /* will reset if necessary. */
         recelem = HIDGetFirstDeviceElement(mouse, kHIDElementTypeInput);
@@ -1553,7 +1553,7 @@
         } /* else */
     } /* while */
 
-    return(1);  /* got a valid event */
+    return 1;  /* got a valid event */
 } /* poll_mouse */
 
 
@@ -1572,7 +1572,7 @@
     macosx_hidutilities_quit();  /* just in case... */
 
     if (!HIDBuildDeviceList(kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
-        return(-1);
+        return -1;
 
     available_mice = HIDCountDevices();
     if (available_mice > 0)
@@ -1585,7 +1585,7 @@
         if ((devices == NULL) || (dev == NULL))
         {
             macosx_hidutilities_quit();
-            return(-1);
+            return -1;
         } /* if */
 
         for (i = 0; i < available_mice; i++)
@@ -1605,16 +1605,13 @@
         } /* for */
     } /* if */
 
-    return(available_mice);
+    return available_mice;
 } /* macosx_hidutilities_init */
 
 
 static const char *macosx_hidutilities_name(unsigned int index)
 {
-    if (index >= available_mice)
-        return(NULL);
-
-    return((const char *) devices[index]->product);
+    return (index >= available_mice) ? devices[index]->product : NULL;
 } /* macosx_hidutilities_name */
 
 
@@ -1643,17 +1640,17 @@
                 {
                     dev->disconnect = DISCONNECT_COMPLETE;
                     event->type = MANYMOUSE_EVENT_DISCONNECT;
-                    return(1);
+                    return 1;
                 } /* if */
 
                 if (poll_mouse(dev, event))
-                    return(1);
+                    return 1;
             } /* if */
             i++;
         } /* while */
     } /* if */
 
-    return(0);  /* no new events */
+    return 0;  /* no new events */
 } /* macosx_hidutilities_poll */
 
 static const ManyMouseDriver ManyMouseDriver_interface =
--- a/manymouse.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/manymouse.c	Tue Apr 26 17:57:29 2011 -0400
@@ -49,10 +49,10 @@
 
     /* impossible test to keep manymouse_copyright linked into the binary. */
     if (manymouse_copyright == NULL)
-        return(-1);
+        return -1;
 
     if (driver != NULL)
-        return(-1);
+        return -1;
 
     for (i = 0; (i < upper) && (driver == NULL); i++)
     {
@@ -68,35 +68,32 @@
         } /* if */
     } /* for */
 
-    return(retval);
+    return retval;
 } /* ManyMouse_Init */
 
 
 void ManyMouse_Quit(void)
 {
     if (driver != NULL)
+    {
         driver->quit();
-    driver = NULL;
+        driver = NULL;
+    } /* if */
 } /* ManyMouse_Quit */
 
 const char *ManyMouse_DriverName(void)
 {
-    return ((driver) ? driver->driver_name : NULL);
+    return (driver) ? driver->driver_name : NULL;
 } /* ManyMouse_DriverName */
 
 const char *ManyMouse_DeviceName(unsigned int index)
 {
-    if (driver != NULL)
-        return(driver->name(index));
-    return(NULL);
-} /* ManyMouse_PollEvent */
-
+    return (driver) ? driver->name(index) : NULL;
+} /* ManyMouse_DeviceName */
 
 int ManyMouse_PollEvent(ManyMouseEvent *event)
 {
-    if (driver != NULL)
-        return(driver->poll(event));
-    return(0);
+    return (driver) ? driver->poll(event) : 0;
 } /* ManyMouse_PollEvent */
 
 /* end of manymouse.c ... */
--- a/windows_wminput.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/windows_wminput.c	Tue Apr 26 17:57:29 2011 -0400
@@ -98,10 +98,10 @@
     if (*addr == NULL)
     {
         FreeLibrary(dll);
-        return(0);
+        return 0;
     } /* if */
 
-    return(1);
+    return 1;
 } /* symlookup */
 
 static int find_api_symbols(void)
@@ -109,12 +109,12 @@
     HMODULE dll;
 
     if (did_api_lookup)
-        return(1);
+        return 1;
 
-    #define LOOKUP(x) { if (!symlookup(dll, (void **) &p##x, #x)) return(0); }
+    #define LOOKUP(x) { if (!symlookup(dll, (void **) &p##x, #x)) return 0; }
     dll = LoadLibrary("user32.dll");
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(GetRawInputDeviceInfoA);
     LOOKUP(RegisterRawInputDevices);
@@ -133,7 +133,7 @@
 
     dll = LoadLibrary("kernel32.dll");
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(GetModuleHandleA);
     LOOKUP(GetLastError);
@@ -144,7 +144,7 @@
 
     dll = LoadLibrary("setupapi.dll");
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(SetupDiGetClassDevsA);
     LOOKUP(SetupDiEnumDeviceInfo);
@@ -155,7 +155,7 @@
     #undef LOOKUP
 
     did_api_lookup = 1;
-    return(1);
+    return 1;
 } /* find_api_symbols */
 
 
@@ -340,7 +340,7 @@
         wminput_handler(wParam, lParam);
 
     else if (Msg == WM_DESTROY)
-        return(0);
+        return 0;
 
     return pDefWindowProcA(hWnd, Msg, wParam, lParam);
 } /* RawWndProc */
@@ -362,14 +362,14 @@
     wce.hInstance = hInstance;
     class_atom = pRegisterClassExA(&wce);
     if (class_atom == 0)
-        return(0);
+        return 0;
 
     raw_hwnd = pCreateWindowExA(0, class_name, win_name, WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                         CW_USEDEFAULT, HWND_MESSAGE, NULL, hInstance, NULL);
 
     if (raw_hwnd == NULL)
-        return(0);
+        return 0;
 
     pInitializeCriticalSection(&mutex);
 
@@ -381,10 +381,10 @@
     if (!pRegisterRawInputDevices(&rid, 1, sizeof (rid)))
     {
         pDeleteCriticalSection(&mutex);
-        return(0);
+        return 0;
     } /* if */
 
-    return(1);
+    return 1;
 } /* init_event_queue */
 
 
@@ -568,11 +568,11 @@
     available_mice = 0;
 
     if (!find_api_symbols())  /* only supported on WinXP and later. */
-        return(-1);
+        return -1;
 
     pGetRawInputDeviceList(NULL, &ct, sizeof (RAWINPUTDEVICELIST));
     if (ct == 0)  /* no devices. */
-        return(0);
+        return 0;
 
     devlist = (PRAWINPUTDEVICELIST) alloca(sizeof (RAWINPUTDEVICELIST) * ct);
     pGetRawInputDeviceList(devlist, &ct, sizeof (RAWINPUTDEVICELIST));
@@ -585,7 +585,7 @@
         available_mice = 0;
     } /* if */
 
-    return(available_mice);
+    return available_mice;
 } /* windows_wminput_init */
 
 
@@ -606,9 +606,7 @@
 
 static const char *windows_wminput_name(unsigned int index)
 {
-    if (index < available_mice)
-        return(mice[index].name);
-    return(NULL);
+    return (index < available_mice) ? mice[index].name : NULL;
 } /* windows_wminput_name */
 
 
@@ -641,11 +639,11 @@
             mouse->handle = NULL;
             ev->type = MANYMOUSE_EVENT_DISCONNECT;
             ev->device = i;
-            return(1);
+            return 1;
         } /* if */
     } /* if */
 
-    return(0);  /* no disconnect event this time. */
+    return 0;  /* no disconnect event this time. */
 } /* check_for_disconnects */
 
 
@@ -693,7 +691,7 @@
     if (!found)
         found = check_for_disconnects(ev);
 
-    return(found);
+    return found;
 } /* windows_wminput_poll */
 
 static const ManyMouseDriver ManyMouseDriver_interface =
--- a/x11_xinput2.c	Tue Apr 26 17:48:22 2011 -0400
+++ b/x11_xinput2.c	Tue Apr 26 17:57:29 2011 -0400
@@ -128,19 +128,19 @@
 {
     *addr = dlsym(dll, sym);
     if (*addr == NULL)
-        return(0);
+        return 0;
 
-    return(1);
+    return 1;
 } /* symlookup */
 
 static int find_api_symbols(void)
 {
     void *dll = NULL;
 
-    #define LOOKUP(x) { if (!symlookup(dll, (void **) &p##x, #x)) return(0); }
+    #define LOOKUP(x) { if (!symlookup(dll, (void **) &p##x, #x)) return 0; }
     dll = libx11 = dlopen("libX11.so.6", RTLD_GLOBAL | RTLD_LAZY);
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(XOpenDisplay);
     LOOKUP(XCloseDisplay);
@@ -154,13 +154,13 @@
 
     dll = libxext = dlopen("libXext.so.6", RTLD_GLOBAL | RTLD_LAZY);
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(XSetExtensionErrorHandler);
 
     dll = libxi = dlopen("libXi.so.6", RTLD_GLOBAL | RTLD_LAZY);
     if (dll == NULL)
-        return(0);
+        return 0;
 
     LOOKUP(XISelectEvents);
     LOOKUP(XIQueryVersion);
@@ -169,7 +169,7 @@
 
     #undef LOOKUP
 
-    return(1);
+    return 1;
 } /* find_api_symbols */
 
 
@@ -208,9 +208,9 @@
      */
 
     if ((devinfo->use != XISlavePointer) && (devinfo->use != XIFloatingSlave))
-        return(0);  /* not a device we care about. */
+        return 0;  /* not a device we care about. */
     else if (strstr(devinfo->name, "XTEST pointer") != NULL)
-        return(0);  /* skip this nonsense. It's for the XTEST extension. */
+        return 0;  /* skip this nonsense. It's for the XTEST extension. */
 
     mouse->device_id = devinfo->deviceid;
     mouse->connected = 1;
@@ -229,7 +229,7 @@
 
     strncpy(mouse->name, devinfo->name, sizeof (mouse->name));
     mouse->name[sizeof (mouse->name) - 1] = '\0';
-    return(1);
+    return 1;
 } /* init_mouse */
 
 
@@ -276,14 +276,14 @@
     xinput2_cleanup();  /* just in case... */
 
     if (getenv("MANYMOUSE_NO_XINPUT2") != NULL)
-        return(-1);
+        return -1;
 
     if (!find_api_symbols())
-        return(-1);  /* couldn't find all needed symbols. */
+        return -1;  /* couldn't find all needed symbols. */
 
     display = pXOpenDisplay(NULL);
     if (display == NULL)
-        return(-1);  /* no X server at all */
+        return -1;  /* no X server at all */
 
     Xext_handler = pXSetExtensionErrorHandler(xext_errhandler);
     available = (pXQueryExtension(display, ext, &xi2_opcode, &event, &error) &&
@@ -292,7 +292,7 @@
     Xext_handler = NULL;
 
     if (!available)
-        return(-1);  /* no XInput2 support. */
+        return -1;  /* no XInput2 support. */
 
     /*
      * Register for events first, to prevent a race where we unplug a
@@ -300,7 +300,7 @@
      *  listening for changes.
      */
     if (!register_for_events(display))
-        return(-1);
+        return -1;
 
     device_list = pXIQueryDevice(display, XIAllDevices, &device_count);
     for (i = 0; i < device_count; i++)
@@ -311,7 +311,7 @@
     } /* for */
     pXIFreeDeviceInfo(device_list);
 
-    return(available_mice);
+    return available_mice;
 } /* x11_xinput2_init_internal */
 
 
@@ -320,7 +320,7 @@
     int retval = x11_xinput2_init_internal();
     if (retval < 0)
         xinput2_cleanup();
-    return(retval);
+    return retval;
 } /* x11_xinput2_init */
 
 
@@ -332,9 +332,7 @@
 
 static const char *x11_xinput2_name(unsigned int index)
 {
-    if (index < available_mice)
-        return(mice[index].name);
-    return(NULL);
+    return (index < available_mice) ? mice[index].name : NULL;
 } /* x11_xinput2_name */