~mcf/samurai

00bc95802c738b01fd24e2bb4ca9a9a8fbe50492 — Michael Forney 5 months ago 3a19208
Drop now-unused outer evalstring structure
4 files changed, 23 insertions(+), 41 deletions(-)

M env.c
M scan.c
M util.c
M util.h
M env.c => env.c +14 -19
@@ 94,18 94,16 @@ static struct string *
merge(struct evalstring *str, size_t n)
{
	struct string *result;
	struct evalstringpart *p;
	struct evalstring *p;
	char *s;

	result = mkstr(n);
	s = result->s;
	if (str) {
		for (p = str->parts; p; p = p->next) {
			if (!p->str)
				continue;
			memcpy(s, p->str->s, p->str->n);
			s += p->str->n;
		}
	for (p = str; p; p = p->next) {
		if (!p->str)
			continue;
		memcpy(s, p->str->s, p->str->n);
		s += p->str->n;
	}
	*s = '\0';



@@ 116,17 114,15 @@ struct string *
enveval(struct environment *env, struct evalstring *str)
{
	size_t n;
	struct evalstringpart *p;
	struct evalstring *p;
	struct string *res;

	n = 0;
	if (str) {
		for (p = str->parts; p; p = p->next) {
			if (p->var)
				p->str = envvar(env, p->var);
			if (p->str)
				n += p->str->n;
		}
	for (p = str; p; p = p->next) {
		if (p->var)
			p->str = envvar(env, p->var);
		if (p->str)
			n += p->str->n;
	}
	res = merge(str, n);
	delevalstr(str);


@@ 216,8 212,7 @@ struct string *
edgevar(struct edge *e, char *var, bool escape)
{
	static const void *cycle = &cycle;
	struct evalstring *str;
	struct evalstringpart *p;
	struct evalstring *str, *p;
	struct treenode *n;
	size_t len;



@@ 238,7 233,7 @@ edgevar(struct edge *e, char *var, bool escape)
	str = n->value;
	n->value = (void *)cycle;
	len = 0;
	for (p = str->parts; p; p = p->next) {
	for (p = str; p; p = p->next) {
		if (p->var)
			p->str = edgevar(e, p->var, escape);
		if (p->str)

M scan.c => scan.c +4 -10
@@ 202,9 202,9 @@ scanname(struct scanner *s)
}

static void
addstringpart(struct evalstringpart ***end, bool var)
addstringpart(struct evalstring ***end, bool var)
{
	struct evalstringpart *p;
	struct evalstring *p;

	p = xmalloc(sizeof(*p));
	p->next = NULL;


@@ 223,7 223,7 @@ addstringpart(struct evalstringpart ***end, bool var)
}

static void
escape(struct scanner *s, struct evalstringpart ***end)
escape(struct scanner *s, struct evalstring ***end)
{
	switch (s->chr) {
	case '$':


@@ 265,8 265,7 @@ escape(struct scanner *s, struct evalstringpart ***end)
struct evalstring *
scanstring(struct scanner *s, bool path)
{
	struct evalstring *str;
	struct evalstringpart *parts = NULL, **end = &parts;
	struct evalstring *str = NULL, **end = &str;

	buf.len = 0;
	for (;;) {


@@ 296,11 295,6 @@ out:
		addstringpart(&end, 0);
	if (path)
		space(s);
	if (!parts)
		return NULL;
	str = xmalloc(sizeof(*str));
	str->parts = parts;

	return str;
}


M util.c => util.c +4 -7
@@ 137,20 137,17 @@ mkstr(size_t n)
void
delevalstr(void *ptr)
{
	struct evalstring *str = ptr;
	struct evalstringpart *p, *next;
	struct evalstring *str = ptr, *p;

	if (!str)
		return;
	for (p = str->parts; p; p = next) {
		next = p->next;
	while (str) {
		p = str;
		str = str->next;
		if (p->var)
			free(p->var);
		else
			free(p->str);
		free(p);
	}
	free(str);
}

void

M util.h => util.h +1 -5
@@ 10,13 10,9 @@ struct string {

/* an unevaluated string */
struct evalstring {
	struct evalstringpart *parts;
};

struct evalstringpart {
	char *var;
	struct string *str;
	struct evalstringpart *next;
	struct evalstring *next;
};

#define LEN(a) (sizeof(a) / sizeof((a)[0]))