tabbed

Simple tabbing application for X11.
git clone git://r-36.net/tabbed
Log | Files | Refs | README | LICENSE

commit effedf8607c8cd46e82fef5ed9083eda727f608d
parent 92571a0887b28bb17f40d3352a6b8f2526575298
Author: Enno Boland (tox) <tox@s01.de>
Date:   Tue,  8 Sep 2009 00:56:21 +0200

fixing run()
Diffstat:
tabbed.c | 29+++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/tabbed.c b/tabbed.c @@ -268,10 +268,10 @@ void run(void) { char buf[32], *p; fd_set rd; - int r, xfd; - unsigned int offset; + int r, xfd, maxfd; + unsigned int offset = 0; XEvent ev; - Listener *l; + Listener *l, *pl; /* main event loop, also reads status text from stdin */ XSync(dpy, False); @@ -279,29 +279,42 @@ run(void) { buf[LENGTH(buf) - 1] = '\0'; /* 0-terminator is never touched */ while(running) { FD_ZERO(&rd); + maxfd = xfd; + FD_SET(xfd, &rd); for(l = listeners; l; l = l->next) { - printf("setting %i\n", l->fd); + maxfd = MAX(maxfd, l->fd); FD_SET(l->fd, &rd); } - FD_SET(xfd, &rd); - if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { + if(select(maxfd + 1, &rd, NULL, NULL, NULL) == -1) { if(errno == EINTR) continue; die("select failed\n"); } for(l = listeners; l; l = l->next) { - printf("testing %i\n", l->fd); if(!FD_ISSET(l->fd, &rd)) continue; switch((r = read(l->fd, buf + offset, LENGTH(buf) - 1 - offset))) { case -1: + perror("tabbed: fd error"); case 0: + if(listeners == l) + listeners = l->next; + else { + for(pl = listeners; pl->next != l ; pl = pl->next); + pl->next = l->next; + } + free(l); break; default: for(p = buf + offset; r > 0; p++, r--, offset++) if(*p == '\n' || *p == '\0') { - *p = '\0'; printf("Got somthing: %s\n", buf); + *p = '\0'; + p += r - 1; /* p is buf + offset + r - 1 */ + for(r = 0; *(p - r) && *(p - r) != '\n'; r++); + offset = r; + if(r) + memmove(buf, p - r + 1, r); break; } break;