Moving the platform-specific code (non-Windows) farther up in the freeglut_joystick...
[freeglut] / src / Common / freeglut_joystick.c
index 17eeb00..bf5bf95 100644 (file)
@@ -455,12 +455,60 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat );
 #endif\r
 \r
 \r
+/* External function declarations (mostly platform-specific) */\r
+extern void fgPlatformJoystickClose ( int ident );\r
+\r
 /*\r
  * The static joystick structure pointer\r
  */\r
 #define MAX_NUM_JOYSTICKS  2\r
 static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];\r
 \r
+/*\r
+ *  Platform-Specific Code\r
+ */\r
+\r
+#if TARGET_HOST_MACINTOSH\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+    ISpSuspend( );\r
+    ISpStop( );\r
+    ISpShutdown( );\r
+}\r
+#endif\r
+\r
+#if TARGET_HOST_MAC_OSX\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+    ( *( fgJoystick[ ident ]->hidDev ) )->\r
+        close( fgJoystick[ ident ]->hidDev );\r
+}\r
+#endif\r
+\r
+#if TARGET_HOST_POSIX_X11\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
+    if( fgJoystick[ident]->os )\r
+    {\r
+        if( ! fgJoystick[ ident ]->error )\r
+            close( fgJoystick[ ident ]->os->fd );\r
+#ifdef HAVE_USB_JS\r
+        if( fgJoystick[ ident ]->os->hids )\r
+            free (fgJoystick[ ident ]->os->hids);\r
+        if( fgJoystick[ ident ]->os->hid_data_buf )\r
+            free( fgJoystick[ ident ]->os->hid_data_buf );\r
+#endif\r
+        free( fgJoystick[ident]->os );\r
+       }\r
+#endif\r
+\r
+    if( ! fgJoystick[ident]->error )\r
+         close( fgJoystick[ ident ]->fd );\r
+}\r
+#endif\r
+\r
+\r
 \r
 /*\r
  * Read the raw joystick data\r
@@ -1616,9 +1664,7 @@ void fgInitialiseJoysticks ( void )
     }\r
 }\r
 \r
-/*\r
- *\r
- */\r
+\r
 void fgJoystickClose( void )\r
 {\r
     int ident ;\r
@@ -1626,41 +1672,7 @@ void fgJoystickClose( void )
     {\r
         if( fgJoystick[ ident ] )\r
         {\r
-\r
-#if TARGET_HOST_MACINTOSH\r
-            ISpSuspend( );\r
-            ISpStop( );\r
-            ISpShutdown( );\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-            ( *( fgJoystick[ ident ]->hidDev ) )->\r
-                close( fgJoystick[ ident ]->hidDev );\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-            /* Do nothing special */\r
-#endif\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
-            if( fgJoystick[ident]->os )\r
-            {\r
-                if( ! fgJoystick[ ident ]->error )\r
-                    close( fgJoystick[ ident ]->os->fd );\r
-#ifdef HAVE_USB_JS\r
-                if( fgJoystick[ ident ]->os->hids )\r
-                    free (fgJoystick[ ident ]->os->hids);\r
-                if( fgJoystick[ ident ]->os->hid_data_buf )\r
-                    free( fgJoystick[ ident ]->os->hid_data_buf );\r
-#endif\r
-                free( fgJoystick[ident]->os );\r
-            }\r
-#endif\r
-\r
-            if( ! fgJoystick[ident]->error )\r
-                close( fgJoystick[ ident ]->fd );\r
-#endif\r
+                       fgPlatformJoystickClose ( ident );\r
 \r
             free( fgJoystick[ ident ] );\r
             fgJoystick[ ident ] = NULL;\r