Index: wine/misc/comm.c
===================================================================
RCS file: /home/wine/wine/misc/comm.c,v
retrieving revision 1.55
diff -u -w -r1.55 comm.c
--- wine/misc/comm.c	2000/09/18 01:41:07	1.55
+++ wine/misc/comm.c	2000/09/18 15:15:48
@@ -2552,13 +2552,136 @@
 }
 /***********************************************************************
  *           WaitCommEvent   (KERNEL32.719)
+ *
+ * Blocks until something interesting happens on the com port associated
+ * with hFile. Interesting things are defined by an event mask, pointed
+ * to by "eventmask". These can be combinations of:
+ *  EV_RXCHAR     a new character is received.
+ *  EV_TXEMPTY    The transmit buffer became empty.
+ *  EV_BRK        A break condition was detected on the input.
+ *  EV_CTS        The CTS line changed status.
+ *  EV_DSR        The DSR line changed status.
+ *  EV_RING       The RNG line changed status.
+ *  EV_ERR        An error was detected on the input (parity or framing)
+ *
+ * RETURNS
+ *
+ *  FALSE   If there was an error, and no waiting was done.
+ *  TRUE    When the requested condition was detected.
+ *
+ * BUGS
+ *
+ *  Doesn't handle asynchronous I/O yet. (using the overlapped structure)
+ *  Doesn't support EV_RXFLAG,  EV_RLSD and some others.
  */
-BOOL WINAPI WaitCommEvent(HANDLE hFile,LPDWORD eventmask ,LPOVERLAPPED overlapped)
+
+BOOL WINAPI WaitCommEvent(
+                HANDLE hFile,            /* file handle of the comm port */
+                LPDWORD eventmask,       /* bitmask of interesting events */
+                LPOVERLAPPED overlapped  /* asynchronous operation structure */
+) {
+#define TIOCMIWAIT_RNG   TIOCM_RNG
+#define TIOCMIWAIT_DSR   TIOCM_DSR
+#define TIOCMIWAIT_DCD   TIOCM_CD
+#define TIOCMIWAIT_CTS   TIOCM_CTS
+#define TIOCMIWAIT_RX    0x1000
+#define TIOCMIWAIT_BRK   0x2000
+#define TIOCMIWAIT_TX    0x4000
+#define TIOCMIWAIT_ERR   0x8000
+
+#define TIOCMIWAIT_RETFLAGS 0x800000/* timers in microseconds */
+
+    int fd, tiomask, r;
+    DWORD ev;
+
+    TRACE("(%d %p %p %lx )\n",hFile, eventmask,overlapped, *eventmask);
+
+    if(overlapped)
 {
-	FIXME("(%d %p %p )\n",hFile, eventmask,overlapped);
-	return TRUE;
+        FIXME("can't handle the overlapped structure yet.\n");
+    }
+
+    fd=FILE_GetUnixHandle( hFile, GENERIC_READ );
+    if(0>fd) 
+    {
+        TRACE("File descriptor was bad.\n");
+        return FALSE;
 }
 
+    if(0==GetCommMask(hFile, &ev))
+    {
+        close(fd);
+        TRACE("GetCommMask failed\n");
+        return FALSE;
+    }
+
+#ifdef HAVE_TIOCMIWAIT_MODS
+
+    /*
+    ** A technically nice way of implementing this function:
+    ** use an ioctl to request that the kernel block until
+    ** the appropriate condition is satistfied. Only problem
+    ** is that this required a patch to the kernel source :-(
+    */
+
+    /* translate from windows to linux event mask */
+    tiomask = 0;
+    if(ev & EV_RXCHAR)
+        tiomask |= TIOCMIWAIT_RX;
+    if(ev & EV_TXEMPTY)
+        tiomask |= TIOCMIWAIT_TX;
+    if(ev & EV_BREAK)
+        tiomask |= TIOCMIWAIT_BRK;
+    if(ev & EV_CTS)
+        tiomask |= TIOCMIWAIT_CTS;
+    if(ev & EV_DSR)
+        tiomask |= TIOCMIWAIT_DSR;
+    if(ev & EV_RING)
+        tiomask |= TIOCMIWAIT_RNG;
+    if(ev & EV_ERR)
+        tiomask |= TIOCMIWAIT_ERR;
+
+    /* MJM - extended TIOCMIWAIT to handle more wait conditions */
+    TRACE("waiting tiomask %x\n",tiomask);
+    r = ioctl(fd, TIOCMIWAIT, tiomask);
+    if(r<0)
+    {
+        /* TODO: set an error code */
+        TRACE("wait failed tiomask %x\n",tiomask);
+        return FALSE;
+    }
+
+    if(eventmask)
+    {
+        /* translate from linux to windows event mask */
+        *eventmask = 0;
+        if(tiomask & TIOCMIWAIT_RX)
+            *eventmask |= EV_RXCHAR;
+        if(tiomask & TIOCMIWAIT_TX)
+            *eventmask |= EV_TXEMPTY;
+        if(tiomask & TIOCMIWAIT_BRK)
+            *eventmask |= EV_BREAK;
+        if(tiomask & TIOCMIWAIT_CTS)
+            *eventmask |= EV_CTS;
+        if(tiomask & TIOCMIWAIT_DSR)
+            *eventmask = EV_DSR;
+        if(tiomask & TIOCMIWAIT_RNG)
+            *eventmask = EV_RING;
+        if(tiomask & TIOCMIWAIT_ERR)
+            *eventmask = EV_ERR;
+    }
+    TRACE("exit eventmask %lx\n",*eventmask);
+#else /* HAVE_TIOCMIWAIT_MOD */
+
+    ERR("This can work if you upgrade your kernel's serial driver\n");
+    *eventmask = 0;
+
+#endif
+
+    close(fd);
+
+    return TRUE;
+}
 /***********************************************************************
  *           GetCommProperties   (KERNEL32.286)
  *
