]> Pileus Git - ~andy/lamechat/blobdiff - util.c
Strip HTML tags.
[~andy/lamechat] / util.c
diff --git a/util.c b/util.c
index f76e052eb6351233f237f5d3ca2ed0cec010ea17..b5719244721ecb936743adc4f642d1b15b80d36c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <ctype.h>
 #include <errno.h>
 #include <time.h>
 
@@ -141,6 +142,27 @@ int prefix(const char *str, const char *prefix, const char **suffix)
        return 1;
 }
 
+char *despace(char *str)
+{
+       int chr, spaces = 1;
+       char *src = str;
+       char *dst = str;
+       while ((chr = *src++)) {
+               if (isspace(chr))
+                       spaces++;
+               else
+                       spaces=0;
+               if (spaces == 0)
+                       *dst++ = chr;
+               if (spaces == 1)
+                       *dst++ = ' ';
+       }
+       if (dst > str && spaces)
+               dst--;
+       *dst = '\0';
+       return str;
+}
+
 /* Memory functions */
 void *alloc0(int size)
 {
@@ -265,7 +287,7 @@ err:
 int poll_add(poll_t *poll, int fd, cb_t cb, void *data)
 {
        struct epoll_event ctl = {
-               .events = EPOLLIN | EPOLLOUT | EPOLLERR,
+               .events = EPOLLET | EPOLLIN | EPOLLOUT | EPOLLERR,
                .data.ptr = poll,
        };
        poll->fd   = fd;
@@ -277,7 +299,8 @@ int poll_add(poll_t *poll, int fd, cb_t cb, void *data)
 int poll_ctl(poll_t *poll, int in, int out, int err)
 {
        struct epoll_event ctl = {
-               .events = (in  ? EPOLLIN  : 0)
+               .events = EPOLLET
+                       | (in  ? EPOLLIN  : 0)
                        | (out ? EPOLLOUT : 0)
                        | (err ? EPOLLERR : 0),
                .data.ptr = poll,
@@ -304,7 +327,7 @@ int poll_run(int timeout)
                if (count < 0)
                        continue;
                if (count == 0)
-                       continue;
+                       return running;
                if (!(poll = event.data.ptr))
                        continue;
                if (!(poll->cb))