1 /*
2  * TransFig: Facility for Translating Fig code
3  * Copyright (c) 1991 by Micah Beck
4  * Parts Copyright (c) 1985-1988 by Supoj Sutanthavibul
5  * Parts Copyright (c) 1989-2002 by Brian V. Smith
6  *
7  * Any party obtaining a copy of these files is granted, free of charge, a
8  * full and unrestricted irrevocable, world-wide, paid up, royalty-free,
9  * nonexclusive right and license to deal in this software and
10  * documentation files (the "Software"), including without limitation the
11  * rights to use, copy, modify, merge, publish and/or distribute copies of
12  * the Software, and to permit persons who receive copies from any such
13  * party to do so, with the only requirement being that this copyright
14  * notice remain intact.
15  *
16  */
17 
18 #include "fig2dev.h"
19 #include "object.h"
20 #include "free.h"
21 
22 void
free_arc(list)23 free_arc(list)
24 F_arc	**list;
25 {
26 	F_arc	*a, *arc;
27 
28 	for (a = *list; a != NULL;) {
29 	    arc = a;
30 	    a = a->next;
31 	    if (arc->for_arrow) free((char*)arc->for_arrow);
32 	    if (arc->back_arrow) free((char*)arc->back_arrow);
33 	    free((char*)arc);
34 	    }
35 	*list = NULL;
36 	}
37 
38 void
free_compound(list)39 free_compound(list)
40 F_compound	**list;
41 {
42 	F_compound	*c, *compound;
43 
44 	for (c = *list; c != NULL;) {
45 	    compound = c;
46 	    c = c->next;
47 	    free_arc(&compound->arcs);
48 	    free_compound(&compound->compounds);
49 	    free_ellipse(&compound->ellipses);
50 	    free_line(&compound->lines);
51 	    free_spline(&compound->splines);
52 	    free_text(&compound->texts);
53 	    free((char*)compound);
54 	    }
55 	*list = NULL;
56 	}
57 
58 void
free_ellipse(list)59 free_ellipse(list)
60 F_ellipse	**list;
61 {
62 	F_ellipse	*e, *ellipse;
63 
64 	for (e = *list; e != NULL;) {
65 	    ellipse = e;
66 	    e = e->next;
67 	    free((char*)ellipse);
68 	    }
69 	*list = NULL;
70 	}
71 
72 void
free_line(list)73 free_line(list)
74 F_line	**list;
75 {
76 	F_line	*l, *line;
77 
78 	for (l = *list; l != NULL;) {
79 	    line = l;
80 	    l = l->next;
81 	    free_linestorage(line);
82 	    }
83 	*list = NULL;
84 	}
85 
86 void
free_text(list)87 free_text(list)
88 F_text	**list;
89 {
90 	F_text	*t, *text;
91 
92 	for (t = *list; t != NULL;) {
93 	    text = t;
94 	    t = t->next;
95 	    free(text->cstring);
96 	    free((char*)text);
97 	    }
98 	*list = NULL;
99 	}
100 
101 void
free_spline(list)102 free_spline(list)
103 F_spline	**list;
104 {
105 	F_spline	*s, *spline;
106 
107 	for (s = *list; s != NULL;) {
108 	    spline = s;
109 	    s = s->next;
110 	    free_splinestorage(spline);
111 	    }
112 	*list = NULL;
113 	}
114 
115 void
free_splinestorage(s)116 free_splinestorage(s)
117 F_spline      *s;
118 {
119         F_point		*p, *q;
120         F_control	*a, *b;
121 
122         for (p = s->points; p != NULL; p = q) {
123             q = p->next;
124             free((char*)p);
125             }
126         for (a = s->controls; a != NULL; a = b) {
127             b = a->next;
128             free((char*)a);
129             }
130 	if (s->for_arrow) free((char*)s->for_arrow);
131 	if (s->back_arrow) free((char*)s->back_arrow);
132         free((char*)s);
133         }
134 
135 void
free_linestorage(l)136 free_linestorage(l)
137 F_line	*l;
138 {
139 	F_point	*p, *q;
140 
141 	for (p = l->points; p != NULL; p = q) {
142 	    q = p->next;
143 	    free((char*)p);
144 	    }
145 	if (l->for_arrow) free((char*)l->for_arrow);
146 	if (l->back_arrow) free((char*)l->back_arrow);
147 	free((char*)l);
148 	}
149