From ef80e91b8f7d3eb77242a325d2e14dafa25e977a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 26 Apr 2011 17:57:29 -0400 Subject: [PATCH] Cleaned up some coding style to match my current mood. :) --- example/detect_mice.c | 6 ++-- example/manymousepong.c | 60 +++++++++++++++++----------------- example/mmpong.c | 2 +- example/test_manymouse_stdio.c | 6 ++-- linux_evdev.c | 16 ++++----- macosx_hidutilities.c | 21 +++++------- manymouse.c | 23 ++++++------- windows_wminput.c | 42 ++++++++++++------------ x11_xinput2.c | 38 ++++++++++----------- 9 files changed, 101 insertions(+), 113 deletions(-) diff --git a/example/detect_mice.c b/example/detect_mice.c index cdcd755..55b82f2 100644 --- a/example/detect_mice.c +++ b/example/detect_mice.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) if (available_mice <= 0) { printf("No mice detected!\n"); - return(1); + return 1; } else { @@ -28,8 +28,8 @@ int main(int argc, char **argv) printf("#%d: %s\n", i, ManyMouse_DeviceName(i)); } ManyMouse_Quit(); - return(0); -} + return 0; +} /* main */ /* end of detect_mice.c ... */ diff --git a/example/manymousepong.c b/example/manymousepong.c index add9a0f..fc072dc 100644 --- a/example/manymousepong.c +++ b/example/manymousepong.c @@ -103,7 +103,7 @@ static int initVideo(void) 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 @@ static int initVideo(void) if (screen == NULL) { SDL_Quit(); - return(0); + return 0; } /* if */ /* @@ -139,13 +139,13 @@ static int initVideo(void) 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 @@ static int initMice(void) setSidesExists(); - return(1); + return 1; } /* initMice */ @@ -227,7 +227,7 @@ static Uint32 standardizedColor(void) 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 @@ static inline Uint32 randomizedColor(void) 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 @@ static int updateInput(void) 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 @@ static int updateInput(void) if (!initVideo()) { printf("window/fullscreen toggle failed!\n"); - return(0); /* quit */ + return 0; /* quit */ } /* if */ /* @@ -496,7 +496,7 @@ static int updateInput(void) } /* switch */ } /* while */ - return(1); /* no quit events this time. */ + return 1; /* no quit events this time. */ } /* updateInput */ @@ -632,12 +632,12 @@ static inline int inRect(int x, int y, int bx1, int by1, int bx2, int by2) /* 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 @@ static inline int intersection(int px1, int py1, int px2, int py2, 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 @@ static inline int scoreOrBounce(PongThing *ball, PaddleSide side) if (sideExists[side]) { triggerScore(ball, side); - return(0); + return 0; } /* if */ - return(1); + return 1; } /* scoreOrBounce */ @@ -914,11 +914,11 @@ static int processCmdLines(int argc, char **argv) else { printf("Unknown command line '%s'\n", arg); - return(0); + return 0; } /* else */ } /* for */ - return(1); + return 1; } /* processCmdLines */ @@ -950,17 +950,17 @@ static void updateFPS(int reinit) 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 @@ int main(int argc, char **argv) ManyMouse_Quit(); SDL_Quit(); /* clean up video mode, etc. */ - return(0); + return 0; } /* main */ /* end of manymousepong.c ... */ diff --git a/example/mmpong.c b/example/mmpong.c index 7fd3ff6..c582bef 100644 --- a/example/mmpong.c +++ b/example/mmpong.c @@ -311,5 +311,5 @@ int main(int argc, char *argv[]) /* Clean up the SDL library */ ManyMouse_Quit(); SDL_Quit(); - return(0); + return 0; } diff --git a/example/test_manymouse_stdio.c b/example/test_manymouse_stdio.c index c81b32e..2f2428a 100644 --- a/example/test_manymouse_stdio.c +++ b/example/test_manymouse_stdio.c @@ -19,12 +19,12 @@ int main(int argc, char **argv) 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 @@ int main(int argc, char **argv) } ManyMouse_Quit(); - return(0); + return 0; } /* end of test_manymouse_stdio.c ... */ diff --git a/linux_evdev.c b/linux_evdev.c index a2fb7a6..0db138c 100644 --- a/linux_evdev.c +++ b/linux_evdev.c @@ -51,17 +51,17 @@ static int poll_mouse(MouseStruct *mouse, ManyMouseEvent *outevent) 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 @@ static int poll_mouse(MouseStruct *mouse, ManyMouseEvent *outevent) } /* else */ } /* while */ - return(1); /* got a valid event */ + return 1; /* got a valid event */ } /* poll_mouse */ @@ -285,9 +285,7 @@ static void linux_evdev_quit(void) 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 @@ static int linux_evdev_poll(ManyMouseEvent *event) 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 = diff --git a/macosx_hidutilities.c b/macosx_hidutilities.c index f6618f2..8ee3dea 100644 --- a/macosx_hidutilities.c +++ b/macosx_hidutilities.c @@ -1486,7 +1486,7 @@ static int poll_mouse(pRecDevice mouse, ManyMouseEvent *outevent) 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 @@ static int poll_mouse(pRecDevice mouse, ManyMouseEvent *outevent) } /* else */ } /* while */ - return(1); /* got a valid event */ + return 1; /* got a valid event */ } /* poll_mouse */ @@ -1572,7 +1572,7 @@ static int macosx_hidutilities_init(void) 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 @@ static int macosx_hidutilities_init(void) if ((devices == NULL) || (dev == NULL)) { macosx_hidutilities_quit(); - return(-1); + return -1; } /* if */ for (i = 0; i < available_mice; i++) @@ -1605,16 +1605,13 @@ static int macosx_hidutilities_init(void) } /* 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 @@ static int macosx_hidutilities_poll(ManyMouseEvent *event) { 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 = diff --git a/manymouse.c b/manymouse.c index 9ca20ca..5285489 100644 --- a/manymouse.c +++ b/manymouse.c @@ -49,10 +49,10 @@ int ManyMouse_Init(void) /* 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 @@ int ManyMouse_Init(void) } /* 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 ... */ diff --git a/windows_wminput.c b/windows_wminput.c index 9a8e744..8d20eb1 100644 --- a/windows_wminput.c +++ b/windows_wminput.c @@ -98,10 +98,10 @@ static int symlookup(HMODULE dll, void **addr, const char *sym) 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 @@ static int find_api_symbols(void) 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 @@ static int find_api_symbols(void) dll = LoadLibrary("kernel32.dll"); if (dll == NULL) - return(0); + return 0; LOOKUP(GetModuleHandleA); LOOKUP(GetLastError); @@ -144,7 +144,7 @@ static int find_api_symbols(void) dll = LoadLibrary("setupapi.dll"); if (dll == NULL) - return(0); + return 0; LOOKUP(SetupDiGetClassDevsA); LOOKUP(SetupDiEnumDeviceInfo); @@ -155,7 +155,7 @@ static int find_api_symbols(void) #undef LOOKUP did_api_lookup = 1; - return(1); + return 1; } /* find_api_symbols */ @@ -340,7 +340,7 @@ static LRESULT CALLBACK RawWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP wminput_handler(wParam, lParam); else if (Msg == WM_DESTROY) - return(0); + return 0; return pDefWindowProcA(hWnd, Msg, wParam, lParam); } /* RawWndProc */ @@ -362,14 +362,14 @@ static int init_event_queue(void) 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 @@ static int init_event_queue(void) if (!pRegisterRawInputDevices(&rid, 1, sizeof (rid))) { pDeleteCriticalSection(&mutex); - return(0); + return 0; } /* if */ - return(1); + return 1; } /* init_event_queue */ @@ -568,11 +568,11 @@ static int windows_wminput_init(void) 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 @@ static int windows_wminput_init(void) available_mice = 0; } /* if */ - return(available_mice); + return available_mice; } /* windows_wminput_init */ @@ -606,9 +606,7 @@ static void windows_wminput_quit(void) 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 @@ static int check_for_disconnects(ManyMouseEvent *ev) 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 @@ static int windows_wminput_poll(ManyMouseEvent *ev) if (!found) found = check_for_disconnects(ev); - return(found); + return found; } /* windows_wminput_poll */ static const ManyMouseDriver ManyMouseDriver_interface = diff --git a/x11_xinput2.c b/x11_xinput2.c index 7337e9f..923b1ec 100644 --- a/x11_xinput2.c +++ b/x11_xinput2.c @@ -128,19 +128,19 @@ static int symlookup(void *dll, void **addr, const char *sym) { *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 @@ static int find_api_symbols(void) 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 @@ static int find_api_symbols(void) #undef LOOKUP - return(1); + return 1; } /* find_api_symbols */ @@ -208,9 +208,9 @@ static int init_mouse(MouseStruct *mouse, const XIDeviceInfo *devinfo) */ 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 @@ static int init_mouse(MouseStruct *mouse, const XIDeviceInfo *devinfo) 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 @@ static int x11_xinput2_init_internal(void) 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 @@ static int x11_xinput2_init_internal(void) 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 @@ static int x11_xinput2_init_internal(void) * 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 @@ static int x11_xinput2_init_internal(void) } /* for */ pXIFreeDeviceInfo(device_list); - return(available_mice); + return available_mice; } /* x11_xinput2_init_internal */ @@ -320,7 +320,7 @@ static int x11_xinput2_init(void) int retval = x11_xinput2_init_internal(); if (retval < 0) xinput2_cleanup(); - return(retval); + return retval; } /* x11_xinput2_init */ @@ -332,9 +332,7 @@ static void x11_xinput2_quit(void) 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 */