-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobj_list.c
67 lines (61 loc) · 1.17 KB
/
obj_list.c
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
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "raytracer.h"
/* ol_cons : cons object onto objectlist */
obj_list *ol_cons(object o, obj_list *os)
{
obj_list *r = malloc(sizeof(obj_list));
r->obj = o;
r->next = os;
return r;
}
/* ol_singleton: return singleton list with object */
obj_list *ol_singleton(object s)
{
obj_list *r = malloc(sizeof(obj_list));
r->obj = s;
r->next = NULL;
return r;
}
/* ol_tos : return string representation of objectlist */
char *ol_tos(obj_list *os)
{
char buf[1024];
int i;
for (i=0; i<1024; i++)
buf[i] = '\0';
strcpy(buf,"'(");
while (os) {
strcat(buf, object_tos(os->obj));
strcat(buf,"\n");
os = os->next;
}
strcat(buf,")");
return strdup(buf);
}
/* ol_show : print objectlist representation to f */
void ol_show(FILE *f, obj_list *os)
{
char *s;
fprintf(f,"'(");
while (os) {
s = object_tos(os->obj);
fprintf(f, ":%s\n", s);
os = os->next;
}
fprintf(f,")");
free(s);
}
/* ol_free : free an objectlist */
void ol_free(obj_list *ss)
{
obj_list *temp;
while(ss->next) {
temp = ss;
ss = ss->next;
free(temp);
}
free(ss);
}