Setting the line endings and keywords on a bunch of new text files
[freeglut] / src / mswin / freeglut_input_devices_mswin.c
index f92eadc..fb70d33 100644 (file)
-/*\r
- * freeglut_input_devices_mswin.c\r
- *\r
- * The Windows-specific mouse cursor related stuff.\r
- *\r
- * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.\r
- * Written by John F. Fay, <fayjf@sourceforge.net>\r
- * Creation date: Sat Jan 21, 2012\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-#include <GL/freeglut.h>\r
-#include "../Common/freeglut_internal.h"\r
-\r
-#include <sys/types.h>\r
-#include <winbase.h>\r
-\r
-typedef struct {\r
-   HANDLE fh;\r
-   COMMTIMEOUTS timeouts_save;\r
-   DCB dcb_save;\r
-} SERIALPORT;\r
-\r
-/* Serial Port Prototypes */\r
-SERIALPORT *serial_open ( const char *device );\r
-void serial_close ( SERIALPORT *port );\r
-int serial_getchar ( SERIALPORT *port );\r
-int serial_putchar ( SERIALPORT *port, unsigned char ch );\r
-void serial_flush ( SERIALPORT *port );\r
-\r
-\r
-void fgPlatformRegisterDialDevice ( const char *dial_device )\r
-{\r
-        if (!dial_device){\r
-            static char devname[256];\r
-            DWORD size=sizeof(devname);\r
-            DWORD type = REG_SZ;\r
-            HKEY key;\r
-            if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) {\r
-                if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){\r
-                    dial_device=devname;\r
-                }\r
-                RegCloseKey(key);\r
-            }\r
-        }\r
-}\r
-\r
-\r
-/*  Serial Port Functions */\r
-SERIALPORT *serial_open(const char *device){\r
-    HANDLE fh;\r
-    DCB dcb={sizeof(DCB)};\r
-    COMMTIMEOUTS timeouts;\r
-    SERIALPORT *port;\r
-\r
-    fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,\r
-      OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);\r
-    if (!fh) return NULL;\r
-\r
-    port = malloc(sizeof(SERIALPORT));\r
-    ZeroMemory(port, sizeof(SERIALPORT));\r
-    port->fh = fh;\r
-\r
-    /* save current port settings */\r
-    GetCommState(fh,&port->dcb_save);\r
-    GetCommTimeouts(fh,&port->timeouts_save);\r
-\r
-    dcb.DCBlength=sizeof(DCB);\r
-    BuildCommDCB("96,n,8,1",&dcb);\r
-    SetCommState(fh,&dcb);\r
-\r
-    ZeroMemory(&timeouts,sizeof(timeouts));\r
-    timeouts.ReadTotalTimeoutConstant=1;\r
-    timeouts.WriteTotalTimeoutConstant=1;\r
-    SetCommTimeouts(fh,&timeouts);\r
-\r
-    serial_flush(port);\r
-\r
-    return port;\r
-}\r
-\r
-void serial_close(SERIALPORT *port){\r
-    if (port){\r
-        /* restore old port settings */\r
-        SetCommState(port->fh,&port->dcb_save);\r
-        SetCommTimeouts(port->fh,&port->timeouts_save);\r
-        CloseHandle(port->fh);\r
-        free(port);\r
-    }\r
-}\r
-\r
-int serial_getchar(SERIALPORT *port){\r
-    DWORD n;\r
-    unsigned char ch;\r
-    if (!port) return EOF;\r
-    if (!ReadFile(port->fh,&ch,1,&n,NULL)) return EOF;\r
-    if (n==1) return ch;\r
-    return EOF;\r
-}\r
-\r
-int serial_putchar(SERIALPORT *port, unsigned char ch){\r
-    DWORD n;\r
-    if (!port) return 0;\r
-    return WriteFile(port->fh,&ch,1,&n,NULL);\r
-}\r
-\r
-void serial_flush ( SERIALPORT *port )\r
-{\r
-    FlushFileBuffers(port->fh);\r
-}\r
-\r
+/*
+ * freeglut_input_devices_mswin.c
+ *
+ * The Windows-specific mouse cursor related stuff.
+ *
+ * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
+ * Written by John F. Fay, <fayjf@sourceforge.net>
+ * Creation date: Sat Jan 21, 2012
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <GL/freeglut.h>
+#include "../Common/freeglut_internal.h"
+
+#include <sys/types.h>
+#include <winbase.h>
+
+typedef struct {
+   HANDLE fh;
+   COMMTIMEOUTS timeouts_save;
+   DCB dcb_save;
+} SERIALPORT;
+
+/* Serial Port Prototypes */
+SERIALPORT *serial_open ( const char *device );
+void serial_close ( SERIALPORT *port );
+int serial_getchar ( SERIALPORT *port );
+int serial_putchar ( SERIALPORT *port, unsigned char ch );
+void serial_flush ( SERIALPORT *port );
+
+
+void fgPlatformRegisterDialDevice ( const char *dial_device )
+{
+        if (!dial_device){
+            static char devname[256];
+            DWORD size=sizeof(devname);
+            DWORD type = REG_SZ;
+            HKEY key;
+            if (RegOpenKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\FreeGLUT",&key)==ERROR_SUCCESS) {
+                if (RegQueryValueExA(key,"DialboxSerialPort",NULL,&type,(LPBYTE)devname,&size)==ERROR_SUCCESS){
+                    dial_device=devname;
+                }
+                RegCloseKey(key);
+            }
+        }
+}
+
+
+/*  Serial Port Functions */
+SERIALPORT *serial_open(const char *device){
+    HANDLE fh;
+    DCB dcb={sizeof(DCB)};
+    COMMTIMEOUTS timeouts;
+    SERIALPORT *port;
+
+    fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,
+      OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+    if (!fh) return NULL;
+
+    port = malloc(sizeof(SERIALPORT));
+    ZeroMemory(port, sizeof(SERIALPORT));
+    port->fh = fh;
+
+    /* save current port settings */
+    GetCommState(fh,&port->dcb_save);
+    GetCommTimeouts(fh,&port->timeouts_save);
+
+    dcb.DCBlength=sizeof(DCB);
+    BuildCommDCB("96,n,8,1",&dcb);
+    SetCommState(fh,&dcb);
+
+    ZeroMemory(&timeouts,sizeof(timeouts));
+    timeouts.ReadTotalTimeoutConstant=1;
+    timeouts.WriteTotalTimeoutConstant=1;
+    SetCommTimeouts(fh,&timeouts);
+
+    serial_flush(port);
+
+    return port;
+}
+
+void serial_close(SERIALPORT *port){
+    if (port){
+        /* restore old port settings */
+        SetCommState(port->fh,&port->dcb_save);
+        SetCommTimeouts(port->fh,&port->timeouts_save);
+        CloseHandle(port->fh);
+        free(port);
+    }
+}
+
+int serial_getchar(SERIALPORT *port){
+    DWORD n;
+    unsigned char ch;
+    if (!port) return EOF;
+    if (!ReadFile(port->fh,&ch,1,&n,NULL)) return EOF;
+    if (n==1) return ch;
+    return EOF;
+}
+
+int serial_putchar(SERIALPORT *port, unsigned char ch){
+    DWORD n;
+    if (!port) return 0;
+    return WriteFile(port->fh,&ch,1,&n,NULL);
+}
+
+void serial_flush ( SERIALPORT *port )
+{
+    FlushFileBuffers(port->fh);
+}
+