Fix the ctl interface from prev commit; fix several off-by-one errors.

This commit is contained in:
Kris Maglione 2006-06-18 19:04:16 -04:00
parent 84ee4cc281
commit 19cf5edacd
4 changed files with 31 additions and 21 deletions

View File

@ -308,7 +308,8 @@ idx_of_area(Area *a)
{ {
Area *t; Area *t;
int i = 0; 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; return t ? i : -1;
} }

View File

@ -690,11 +690,12 @@ send_client(Frame *f, char *arg)
Client *c; Client *c;
Frame *tf; Frame *tf;
View *v; View *v;
int i = idx_of_area(a), int i, j;
j = idx_of_frame(f);
a = f->area; a = f->area;
v = a->view; v = a->view;
c = f->client; c = f->client;
i = idx_of_area(a);
j = idx_of_frame(f);
if((i == -1) || (j == -1)) if((i == -1) || (j == -1))
return 0; return 0;

View File

@ -290,6 +290,7 @@ lookup_file(FileId *parent, char *name)
last = &file->next; last = &file->next;
file->id = 0; file->id = 0;
file->ref = parent->ref; file->ref = parent->ref;
file->index = parent->index;
file->tab = *dir; file->tab = *dir;
file->tab.name = strdup(file->tab.name); file->tab.name = strdup(file->tab.name);
@ -543,6 +544,7 @@ fs_clunk(Req *r) {
update_views(); update_views();
break; break;
case FsFKeys: case FsFKeys:
def.keys[def.keyssz] = '\0';
update_keys(); update_keys();
break; break;
case FsFCtags: case FsFCtags:
@ -572,7 +574,7 @@ write_to_buf(Req *r, void *buf, unsigned int *len, unsigned int max) {
*len = offset + count; *len = offset + count;
if(max == 0) { if(max == 0) {
*(void **)buf = realloc(*(void **)buf, *len); *(void **)buf = realloc(*(void **)buf, *len + 1);
cext_assert(*(void **)buf); cext_assert(*(void **)buf);
buf = *(void **)buf; buf = *(void **)buf;
} }
@ -589,7 +591,7 @@ data_to_cstring(Req *r) {
if(r->ifcall.data[i] == '\n') if(r->ifcall.data[i] == '\n')
break; break;
if(i == r->ifcall.count) 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); cext_assert(r->ifcall.data);
r->ifcall.data[i] = '\0'; r->ifcall.data[i] = '\0';
} }
@ -664,6 +666,8 @@ fs_write(Req *r) {
return respond(r, nil); return respond(r, nil);
case FsFTctl: case FsFTctl:
data_to_cstring(r); data_to_cstring(r);
if(r->ifcall.count == 0)
return respond(r, nil);
if(!message_view(f->view, r->ifcall.data)) if(!message_view(f->view, r->ifcall.data))
return respond(r, Ebadvalue); return respond(r, Ebadvalue);
@ -671,6 +675,8 @@ fs_write(Req *r) {
return respond(r, nil); return respond(r, nil);
case FsFRctl: case FsFRctl:
data_to_cstring(r); data_to_cstring(r);
if(r->ifcall.count == 0)
return respond(r, nil);
/* XXX: This needs to be moved to client_message(char *) */ /* XXX: This needs to be moved to client_message(char *) */
if(!strncmp(r->ifcall.data, "quit", 5)) if(!strncmp(r->ifcall.data, "quit", 5))
@ -735,15 +741,16 @@ fs_remove(Req *r) {
void void
write_event(char *buf) { write_event(char *buf) {
Req **r; Req *aux;
unsigned int len = strlen(buf); unsigned int len;
if(!len) if(!(len = strlen(buf)))
return; 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 */ /* XXX: It would be nice if strdup wasn't necessary here */
(*r)->ofcall.data = strdup(buf); pending_event_reads->ofcall.data = strdup(buf);
(*r)->ofcall.count = len; pending_event_reads->ofcall.count = len;
respond(*r, nil); respond(pending_event_reads, nil);
} }
} }

View File

@ -373,19 +373,20 @@ int
message_view(View *v, char *message) { message_view(View *v, char *message) {
unsigned int i, n; unsigned int i, n;
Frame *f; Frame *f;
Area *a; Client *c;
if(!strncmp(message, "send ", 5)) { if(!strncmp(message, "send ", 5)) {
message += 5; message += 5;
if(2 != sscanf(message, "%d %n", &i, &n)) if(1 != sscanf(message, "%d %n", &i, &n))
return 0; return 0;
for(a=v->area; a; a=a->next) for(c=client; i && c; c=c->next, i--);
for(f=a->frame; f; f=f->anext) if(!c)
if(f->client->id == i) return 0;
goto found_client; for(f=c->frame; f; f=f->cnext)
found_client: if(f->area->view == v)
break;
if(!f) if(!f)
return 0; return 0;
return send_client(f, &message[5]); return send_client(f, &message[n]);
} }
return 0; return 0;
} }