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;
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;
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}