fix read/write to scope

This commit is contained in:
Iris Lightshard 2021-07-28 23:19:17 -06:00
parent 41c96c5127
commit b457e6ea2f
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

9
xrxs.c
View file

@ -160,6 +160,7 @@ void write_scope(Req* r) {
s_putc(scope, *c++); s_putc(scope, *c++);
} }
s_terminate(scope); s_terminate(scope);
fprintf(stderr, scope->base);
if (u != nil && u->realm != nil && u->realm->universe != nil) { if (u != nil && u->realm != nil && u->realm->universe != nil) {
u->scope = malloc(r->ifcall.count); u->scope = malloc(r->ifcall.count);
@ -182,6 +183,7 @@ void xrxs_write(Req* r) {
break; break;
case SCOPE: case SCOPE:
write_scope(r); write_scope(r);
break;
default: default:
respond(r, nil); respond(r, nil);
break; break;
@ -398,13 +400,14 @@ void read_scope(Req* r) {
Universe* universe; Universe* universe;
Atom* a; Atom* a;
char key[16] = {0}; char key[16] = {0};
char* c = u->scope; char* c;
if (u == nil || u->scope == nil || u->realm == nil) { if (u == nil || u->scope == nil || u->realm == nil) {
respond(r, nil); respond(r, nil);
return; return;
} }
c = u->scope;
universe = u->realm->universe; universe = u->realm->universe;
if (universe == nil) { if (universe == nil) {
respond(r, ENOUNI); respond(r, ENOUNI);
@ -421,6 +424,8 @@ void read_scope(Req* r) {
s_putc(data, '\n'); s_putc(data, '\n');
} }
*key = '\0'; *key = '\0';
if (*c == '\0')
break;
c++; c++;
} }
@ -435,6 +440,7 @@ void read_random(Req* r) {
srand(rand()); srand(rand());
sprintf(buf, "%d\n", rand() % 100); sprintf(buf, "%d\n", rand() % 100);
readstr(r, buf); readstr(r, buf);
respond(r, nil);
} }
void read_grandom(Req* r) { void read_grandom(Req* r) {
@ -478,6 +484,7 @@ void read_grandom(Req* r) {
sprintf(buf, "%d\n", u->random); sprintf(buf, "%d\n", u->random);
u->random = -1; u->random = -1;
readstr(r, buf); readstr(r, buf);
respond(r, nil);
} }
void xrxs_read(Req* r) { void xrxs_read(Req* r) {