[uim-commit] r823 - in trunk: helper qt

ekato at freedesktop.org ekato at freedesktop.org
Tue Apr 12 04:28:18 PDT 2005


Author: ekato
Date: 2005-04-12 04:28:14 -0700 (Tue, 12 Apr 2005)
New Revision: 823

Modified:
   trunk/helper/helper-candwin-gtk.c
   trunk/qt/candwin-qt.cpp
Log:
* helper/helper-candwin-gtk.c (read_cb) : Put read(2) in while
  loop.
* qt/candwin-qt.cpp (CandidateWindow::slotStdinActivated) : Ditto.


Modified: trunk/helper/helper-candwin-gtk.c
===================================================================
--- trunk/helper/helper-candwin-gtk.c	2005-04-07 11:18:11 UTC (rev 822)
+++ trunk/helper/helper-candwin-gtk.c	2005-04-12 11:28:14 UTC (rev 823)
@@ -554,27 +554,33 @@
 read_cb(GIOChannel *channel, GIOCondition c, gpointer p)
 {
   char buf[CANDIDATE_BUFFER_SIZE];
+  char *read_buf = strdup("");
   int i = 0;
   int n;
   gchar **tmp;
   int fd = g_io_channel_unix_get_fd(channel);
 
-  n = read(fd, buf, CANDIDATE_BUFFER_SIZE - 1);
-  if (n == 0) {
-    close(fd);
-    exit(-1);
+  while (uim_helper_fd_readable(fd) > 0) {
+    n = read(fd, buf, CANDIDATE_BUFFER_SIZE - 1);
+    if (n == 0) {
+      close(fd);
+      exit(-1);
+    }
+    if (n == -1)
+      return TRUE;
+    buf[n] = '\0';
+    read_buf = realloc(read_buf, strlen(read_buf) + n + 1);
+    strcat(read_buf, buf);
   }
-  if (n == -1)
-    return TRUE;
 
-  buf[n] = '\0';
-  tmp = g_strsplit(buf, "\n\n", 0);
+  tmp = g_strsplit(read_buf, "\n\n", 0);
 
   while (tmp[i]) {
     str_parse(tmp[i]);
     i++;
   }
   g_strfreev(tmp);
+  free(read_buf);
   return TRUE;
 }
 

Modified: trunk/qt/candwin-qt.cpp
===================================================================
--- trunk/qt/candwin-qt.cpp	2005-04-07 11:18:11 UTC (rev 822)
+++ trunk/qt/candwin-qt.cpp	2005-04-12 11:28:14 UTC (rev 823)
@@ -43,6 +43,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 #include "uim/config.h"
 
@@ -247,23 +248,30 @@
 void CandidateWindow::slotStdinActivated( int fd )
 {
     char buf[ 4096 ];
+    char *read_buf = strdup( "" );
     int n;
-    n = read( fd, buf, 4096 - 1 );
-    if ( n == 0 )
-    {
-        close( fd );
-        QApplication::exit( -1 );
+
+    while (uim_helper_fd_readable( fd ) > 0) {
+        n = read( fd, buf, 4096 - 1 );
+        if ( n == 0 )
+        {
+            close( fd );
+            QApplication::exit( -1 );
+        }
+        if ( n == -1 )
+            return ;
+        buf[ n ] = '\0';
+	read_buf = (char *)realloc( read_buf, strlen( read_buf ) + n + 1 );
+	strcat( read_buf, buf );
     }
-    if ( n == -1 )
-        return ;
-    buf[ n ] = '\0';
 
-    QStringList msgList = QStringList::split( "\n\n", QString( buf ) );
+    QStringList msgList = QStringList::split( "\n\n", QString( read_buf ) );
 
     QStringList::Iterator it = msgList.begin();
     const QStringList::Iterator end = msgList.end();
     for ( ; it != end; ++it )
         strParse( ( *it ) );
+    free( read_buf );
 }
 
 void CandidateWindow::strParse( const QString& str )



More information about the Uim-commit mailing list