aboutsummaryrefslogtreecommitdiff
path: root/node.c
blob: 0e87370b25e72380106aa902327f868ee7deacae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "node.h"

/*constructor*/
node* mknode(str)
char *str;
{
	node *p = malloc(sizeof(node));
	assert(p);

	p->name = strdup(str);
	p->next = NULL;

	p->var_type = -1;

	return p;
}

/* helpers */
node* list_search(root, str)
node *root;
char *str;
{
	node *p = root;
	while (p) {
		if (!strcmp(p->name, str)) {
			return p;
		}
		p = p->next;
	}
	return NULL;
}

node* list_insert(root, str) /*TODO change to accept double pointer*/
node *root;
char * str;
{
	node *p = mknode( str );
	p->next = root;
	return p;
}

void free_list(n)
node *n;
{
	node *tmp;

	for(tmp = n; tmp;) {
		n = tmp->next;
		free(tmp);
		tmp = NULL;
		tmp = n;
	}
}