This commit is contained in:
Devine Lu Linvega 2020-09-09 19:01:27 -07:00
parent 8473ed7589
commit 40b93afad5
1 changed files with 26 additions and 12 deletions

38
main.c
View File

@ -1,6 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define NAMELEN 32
#define TEXTLEN 512
@ -108,21 +107,34 @@ sfin(char* src[], int len, char* val)
return -1;
}
void
mcpy(void* dest, void* src, int n)
{
int i;
char *a = (char*)src, *b = (char*)dest;
for(i = 0; i < n; i++)
b[i] = a[i];
}
void
sstr(char* src, char* dest, int from, int to)
{
memcpy(dest, src + from, to);
mcpy(dest, src + from, to);
dest[to] = '\0';
}
/* Parade */
char*
attribute(char* src)
clst(char* s, int c)
{
return strrchr(src, ' ') + 1;
int i;
for(i = slen(s); i >= 0; --i)
if(s[i] == c)
return (char*)s + i;
return NULL;
}
/* Parade */
int
isvisible(Vessel* g, Vessel* v)
{
@ -152,7 +164,7 @@ Vessel*
findvisible(Parade* p, Vessel* v, char* name)
{
int i;
char* n = strrchr(name, ' ') + 1;
char* n = clst(name, ' ') + 1;
for(i = 0; i < p->len; ++i) {
if(!isvisible(v, &p->vessels[i]))
continue;
@ -166,7 +178,7 @@ Vessel*
findinventory(Parade* p, Vessel* v, char* name)
{
int i;
char* n = strrchr(name, ' ') + 1;
char* n = clst(name, ' ') + 1;
for(i = 0; i < p->len; ++i) {
if(&p->vessels[i] == v)
continue;
@ -183,7 +195,7 @@ Vessel*
findany(Parade* p, char* name)
{
int i;
char* n = strrchr(name, ' ') + 1;
char* n = clst(name, ' ') + 1;
for(i = 0; i < p->len; ++i)
if(scmp(p->vessels[i].name, n))
return &p->vessels[i];
@ -199,7 +211,7 @@ createvessel(Parade* p, char* val)
if(findany(p, val) && slen(val) > 3)
printf("You cannot create %s.\n", val);
else {
v = addvessel(p, guest, strrchr(val, ' ') + 1);
v = addvessel(p, guest, clst(val, ' ') + 1);
printf("You created a %s.\n", v->name);
}
}
@ -303,7 +315,8 @@ notevessel(char* val)
if(guest->parent->lock)
printf("You cannot add a note to the %s.\n", guest->parent->name);
else {
sstr(val, guest->parent->note, 0, imin(slen(guest->parent->note), TEXTLEN - 1));
sstr(val, guest->parent->note, 0,
imin(slen(guest->parent->note), TEXTLEN - 1));
printf("You added a note to the %s.\n", guest->parent->name);
}
}
@ -314,7 +327,8 @@ programvessel(char* val)
if(guest->parent->lock)
printf("You cannot program the %s.\n", guest->parent->name);
else {
sstr(val, guest->parent->prog, 0, imin(slen(guest->parent->prog), TEXTLEN - 1));
sstr(val, guest->parent->prog, 0,
imin(slen(guest->parent->prog), TEXTLEN - 1));
printf("You programmed the %s.\n", guest->parent->name);
}
}