Skip to content

Commit

Permalink
Cleaned up some coding style to match my current mood. :)
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 26, 2011
1 parent 430f282 commit ef80e91
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 113 deletions.
6 changes: 3 additions & 3 deletions example/detect_mice.c
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char **argv)
if (available_mice <= 0)
{
printf("No mice detected!\n");
return(1);
return 1;
}
else
{
Expand All @@ -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 ... */

60 changes: 30 additions & 30 deletions example/manymousepong.c
Expand Up @@ -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);
Expand All @@ -114,7 +114,7 @@ static int initVideo(void)
if (screen == NULL)
{
SDL_Quit();
return(0);
return 0;
} /* if */

/*
Expand All @@ -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 */


Expand Down Expand Up @@ -189,7 +189,7 @@ static int initMice(void)

setSidesExists();

return(1);
return 1;
} /* initMice */


Expand Down Expand Up @@ -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 */


Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -474,7 +474,7 @@ static int updateInput(void)
if (!initVideo())
{
printf("window/fullscreen toggle failed!\n");
return(0); /* quit */
return 0; /* quit */
} /* if */

/*
Expand All @@ -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 */


Expand Down Expand Up @@ -632,27 +632,27 @@ 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 */


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 */


Expand All @@ -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 */


Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -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);
Expand All @@ -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 ... */
Expand Down
2 changes: 1 addition & 1 deletion example/mmpong.c
Expand Up @@ -311,5 +311,5 @@ int main(int argc, char *argv[])
/* Clean up the SDL library */
ManyMouse_Quit();
SDL_Quit();
return(0);
return 0;
}
6 changes: 3 additions & 3 deletions example/test_manymouse_stdio.c
Expand Up @@ -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
{
Expand Down Expand Up @@ -88,7 +88,7 @@ int main(int argc, char **argv)
}

ManyMouse_Quit();
return(0);
return 0;
}

/* end of test_manymouse_stdio.c ... */
Expand Down
16 changes: 7 additions & 9 deletions linux_evdev.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */


Expand Down Expand Up @@ -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 */


Expand All @@ -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 =
Expand Down
21 changes: 9 additions & 12 deletions macosx_hidutilities.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */


Expand All @@ -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)
Expand All @@ -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++)
Expand All @@ -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 */


Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit ef80e91

Please sign in to comment.