From 19cf5edacdae2856b5f4aae5f12c7b636baf29f2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 18 Jun 2006 19:04:16 -0400 Subject: [PATCH] Fix the ctl interface from prev commit; fix several off-by-one errors. --- cmd/wm/area.c | 3 ++- cmd/wm/client.c | 5 +++-- cmd/wm/fs2.c | 25 ++++++++++++++++--------- cmd/wm/view.c | 19 ++++++++++--------- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cmd/wm/area.c b/cmd/wm/area.c index b70d6dec..d8553361 100644 --- a/cmd/wm/area.c +++ b/cmd/wm/area.c @@ -308,7 +308,8 @@ idx_of_area(Area *a) { Area *t; int i = 0; - for(t=a->view->area; t && t != a; t=t->next, i++); + for(t=a->view->area; t && t != a; t=t->next) + i++; return t ? i : -1; } diff --git a/cmd/wm/client.c b/cmd/wm/client.c index a9157de9..0826b649 100644 --- a/cmd/wm/client.c +++ b/cmd/wm/client.c @@ -690,11 +690,12 @@ send_client(Frame *f, char *arg) Client *c; Frame *tf; View *v; - int i = idx_of_area(a), - j = idx_of_frame(f); + int i, j; a = f->area; v = a->view; c = f->client; + i = idx_of_area(a); + j = idx_of_frame(f); if((i == -1) || (j == -1)) return 0; diff --git a/cmd/wm/fs2.c b/cmd/wm/fs2.c index 67e06608..e1c825c4 100644 --- a/cmd/wm/fs2.c +++ b/cmd/wm/fs2.c @@ -290,6 +290,7 @@ lookup_file(FileId *parent, char *name) last = &file->next; file->id = 0; file->ref = parent->ref; + file->index = parent->index; file->tab = *dir; file->tab.name = strdup(file->tab.name); @@ -543,6 +544,7 @@ fs_clunk(Req *r) { update_views(); break; case FsFKeys: + def.keys[def.keyssz] = '\0'; update_keys(); break; case FsFCtags: @@ -572,7 +574,7 @@ write_to_buf(Req *r, void *buf, unsigned int *len, unsigned int max) { *len = offset + count; if(max == 0) { - *(void **)buf = realloc(*(void **)buf, *len); + *(void **)buf = realloc(*(void **)buf, *len + 1); cext_assert(*(void **)buf); buf = *(void **)buf; } @@ -589,7 +591,7 @@ data_to_cstring(Req *r) { if(r->ifcall.data[i] == '\n') break; if(i == r->ifcall.count) - r->ifcall.data = realloc(r->ifcall.data, ++i); + r->ifcall.data = realloc(r->ifcall.data, i + 1); cext_assert(r->ifcall.data); r->ifcall.data[i] = '\0'; } @@ -664,6 +666,8 @@ fs_write(Req *r) { return respond(r, nil); case FsFTctl: data_to_cstring(r); + if(r->ifcall.count == 0) + return respond(r, nil); if(!message_view(f->view, r->ifcall.data)) return respond(r, Ebadvalue); @@ -671,6 +675,8 @@ fs_write(Req *r) { return respond(r, nil); case FsFRctl: data_to_cstring(r); + if(r->ifcall.count == 0) + return respond(r, nil); /* XXX: This needs to be moved to client_message(char *) */ if(!strncmp(r->ifcall.data, "quit", 5)) @@ -735,15 +741,16 @@ fs_remove(Req *r) { void write_event(char *buf) { - Req **r; - unsigned int len = strlen(buf); - if(!len) + Req *aux; + unsigned int len; + if(!(len = strlen(buf))) return; - for(r=&pending_event_reads; *r; *r=(*r)->aux) { + for(; pending_event_reads; pending_event_reads=aux) { + aux = pending_event_reads->aux; /* XXX: It would be nice if strdup wasn't necessary here */ - (*r)->ofcall.data = strdup(buf); - (*r)->ofcall.count = len; - respond(*r, nil); + pending_event_reads->ofcall.data = strdup(buf); + pending_event_reads->ofcall.count = len; + respond(pending_event_reads, nil); } } diff --git a/cmd/wm/view.c b/cmd/wm/view.c index 51d26559..7fd265e1 100644 --- a/cmd/wm/view.c +++ b/cmd/wm/view.c @@ -373,19 +373,20 @@ int message_view(View *v, char *message) { unsigned int i, n; Frame *f; - Area *a; - if(!strncmp(message, "send", 5)) { + Client *c; + if(!strncmp(message, "send ", 5)) { message += 5; - if(2 != sscanf(message, "%d %n", &i, &n)) + if(1 != sscanf(message, "%d %n", &i, &n)) return 0; - for(a=v->area; a; a=a->next) - for(f=a->frame; f; f=f->anext) - if(f->client->id == i) - goto found_client; - found_client: + for(c=client; i && c; c=c->next, i--); + if(!c) + return 0; + for(f=c->frame; f; f=f->cnext) + if(f->area->view == v) + break; if(!f) return 0; - return send_client(f, &message[5]); + return send_client(f, &message[n]); } return 0; }