Fixed issue with nv creation

This commit is contained in:
Devine Lu Linvega 2020-09-16 19:30:41 -07:00
parent b58b9ae372
commit 44ec0c4122
3 changed files with 41 additions and 4 deletions

18
NOTES Normal file
View File

@ -0,0 +1,18 @@
Benchmark
answer(&parade, "create a teapot");
answer(&parade, "become the teapot");
answer(&parade, "enter the ghost");
answer(&parade, "leave");
answer(&parade, "take the ghost");
answer(&parade, "drop the ghost");
answer(&parade, "warp in the teapot");
answer(&parade, "transform into a bat");
answer(&parade, "note the bat is dark.");
answer(&parade, "program create a teapot");
answer(&parade, "warp to the library");
answer(&parade, "become the ghost");
answer(&parade, "use the bat");

View File

@ -1,11 +1,9 @@
#!/bin/bash
clang-format -i main.c
clang-format -i comm.c
# Linux
cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -o main main.c
cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -o comm comm.c
# Plan9
# pcc main.c -o main

25
main.c
View File

@ -151,7 +151,7 @@ addvessel(Parade* p, Vessel* v, char* name)
{
Vessel* nv = &p->vessels[p->len];
nv->id = p->len;
nv->owner = v ? v->parent : nv;
nv->owner = v ? v : nv;
nv->parent = v ? v->parent : nv;
sstr(name, nv->name, 0, imin(slen(name), NAMELEN - 1));
p->len++;
@ -281,7 +281,7 @@ warpvessel(Parade* p, char* val)
if(!v)
printf("You cannot warp to the %s.\n", val);
else {
v->parent = v;
guest->parent = v;
printf("You warped to the %s%c.\n", v->name, rune(v));
}
}
@ -389,6 +389,23 @@ act(Parade* p, char* cmd, char* val)
}
}
int
save(Parade* p)
{
int i;
char body[1024];
for(i = 0; i < p->len; ++i) {
printf("%-4d %-4d %-4d %-16s %s | %s\n",
p->vessels[i].id,
p->vessels[i].owner->id,
p->vessels[i].parent->id,
p->vessels[i].name,
p->vessels[i].note,
p->vessels[i].prog);
}
return 1;
}
int
answer(Parade* p, char* input)
{
@ -396,6 +413,10 @@ answer(Parade* p, char* input)
char action[NAMELEN], value[TEXTLEN];
if(scmp(input, "quit"))
return 0;
if(scmp(input, "save"))
return save(p);
if(cpos(input, '|') >= 0)
return 1;
if(split >= 0) {
sstr(input, action, 0, split);
sstr(input, value, split + 1, imin(slen(input) - split, TEXTLEN - 1));