Mercurial > MadButterfly
annotate tools/mb_c_source.m4 @ 67:3f2872a1a2fe
clear objects in *_free() for generated code
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 13 Aug 2008 08:05:50 +0800 |
parents | 309f1eefbec0 |
children | 018546012798 |
rev | line source |
---|---|
63 | 1 changequote(`[', `]')dnl |
2 include([foreach.m4])dnl | |
3 divert([-1]) | |
4 | |
64 | 5 define([UNQUOTE], [$*]) |
6 | |
7 define([QUOTE], [[[$*]]]) | |
63 | 8 |
64 | 9 define([COUNT],[ifelse([$*],[],0,[$#])]) |
63 | 10 |
64 | 11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) |
63 | 12 |
64 | 13 define([D_COLOR_STOP],[ |
14 {$6,$2,$3,$4,$5}]) | |
63 | 15 |
16 define([D_ADD_LINEAR_PAINT],[dnl | |
64 | 17 ifelse(COUNT($6),0,,[dnl |
18 static const int n_$1_stops = COUNT($6); | |
19 static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)}; | |
63 | 20 ])dnl |
21 ]) | |
22 | |
23 define([D_ADD_RADIAL_PAINT],[dnl | |
64 | 24 ifelse(COUNT($5),0,,[dnl |
25 static const int n_$1_stops = COUNT($5); | |
26 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; | |
63 | 27 ])dnl |
28 ]) | |
29 | |
30 define([DECLARE_VARS], [divert([-1]) | |
64 | 31 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) |
32 DIMPORT([ADD_LINEAR_PAINT]) | |
33 DIMPORT([ADD_RADIAL_PAINT]) | |
34 DIMPORT([COLOR_STOP]) | |
35 define([REF_STOPS],) | |
36 define([ADD_PATH],) | |
37 define([ADD_RECT]) | |
38 define([ADD_COORD]) | |
39 define([FILL_SHAPE]) | |
40 define([STROKE_SHAPE]) | |
41 define([FILL_SHAPE_WITH_PAINT]) | |
42 define([STROKE_SHAPE_WITH_PAINT]) | |
63 | 43 divert[]]) |
44 | |
45 define([S_ADD_LINEAR_PAINT],[ | |
46 obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5); | |
64 | 47 ifelse(COUNT($6),0,,[dnl |
48 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); | |
49 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); | |
50 paint_linear_stops(obj->$1, n_$1_stops, stops); | |
51 ])dnl | |
63 | 52 ]) |
64 | 53 |
63 | 54 define([S_ADD_RADIAL_PAINT],[ |
55 obj->$1 = mb_radial_new(rdman, $2, $3, $4); | |
64 | 56 ifelse(COUNT($5),0,,[ |
57 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); | |
58 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); | |
59 paint_radial_stops(obj->$1, n_$1_stops, stops); | |
60 ])dnl | |
63 | 61 ]) |
62 | |
64 | 63 define([S_COLOR_STOP],[]) |
64 define([S_REF_STOPS],[dnl | |
65 [ stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$2_stops); | |
66 memcpy(stops, $2_stops, sizeof(grad_stop_t) * n_$2_stops); | |
67 paint_radial_stops(obj->$1, n_$2_stops, stops); | |
68 ]]) | |
69 | |
70 define([S_ADD_RECT],[[ | |
71 obj->$1 = sh_rect_new($2, $3, $4, $5, 0, 0); | |
72 rdman_add_shape(rdman, obj->$1, obj->$6); | |
73 ]]) | |
74 | |
75 define([S_ADD_PATH],[[ | |
76 obj->$1 = sh_path_new("$2"); | |
77 rdman_add_shape(rdman, obj->$1, obj->$3); | |
78 ]]) | |
79 | |
80 define([S_ADD_COORD],[[ | |
66
309f1eefbec0
create new coords from redraw_man
Thinker K.F. Li <thinker@branda.to>
parents:
64
diff
changeset
|
81 obj->$1 = rdman_coord_new(rdman, obj->$2); |
64 | 82 ]]) |
83 | |
84 define([S_FILL_SHAPE_WITH_PAINT],[dnl | |
85 [ rdman_paint_fill(rdman, obj->$2, obj->$1); | |
86 ]]) | |
87 | |
88 define([S_STROKE_SHAPE_WITH_PAINT],[dnl | |
89 [ rdman_paint_stroke(rdman, obj->$2, obj->$1); | |
90 ]]) | |
91 | |
92 define([S_FILL_SHAPE],[dnl | |
93 [ obj->$1_fill = paint_color_new(rdman, $2, $3, $4, $5); | |
94 rdman_paint_fill(rdman, obj->$1_fill, obj->$1); | |
95 ]]) | |
96 | |
97 define([S_STROKE_SHAPE],[dnl | |
98 [ obj->$1_stroke = paint_color_new(rdman, $2, $3, $4, $5); | |
99 rdman_paint_stroke(rdman, obj->$1_stroke, obj->$1); | |
100 ]]) | |
101 | |
63 | 102 define([SETUP_VARS],[divert([-1]) |
64 | 103 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) |
104 SIMPORT([ADD_LINEAR_PAINT]) | |
105 SIMPORT([ADD_RADIAL_PAINT]) | |
106 SIMPORT([COLOR_STOP]) | |
107 SIMPORT([REF_STOPS]) | |
108 SIMPORT([ADD_PATH],) | |
109 SIMPORT([ADD_RECT]) | |
110 SIMPORT([ADD_COORD]) | |
111 SIMPORT([FILL_SHAPE]) | |
112 SIMPORT([STROKE_SHAPE]) | |
113 SIMPORT([FILL_SHAPE_WITH_PAINT]) | |
114 SIMPORT([STROKE_SHAPE_WITH_PAINT]) | |
63 | 115 divert[]]) |
116 | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
117 define([F_ADD_LINEAR_PAINT],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
118 stops = paint_linear_stops(obj->$1, 0, NULL); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
119 free(stops); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
120 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
121 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
122 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
123 define([F_ADD_RADIAL_PAINT],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
124 stops = paint_radial_stops(obj->$1, 0, NULL); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
125 free(stops); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
126 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
127 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
128 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
129 define([F_ADD_PATH],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
130 sh_path_free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
131 ]]); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
132 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
133 define([F_ADD_RECT],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
134 sh_rect_free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
135 ]]); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
136 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
137 define([F_FILL_SHAPE],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
138 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
139 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
140 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
141 define([F_STROKE_SHAPE],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
142 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
143 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
144 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
145 define([CLEAR_VARS],[divert([-1]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
146 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
147 FIMPORT([ADD_LINEAR_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
148 FIMPORT([ADD_RADIAL_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
149 define([COLOR_STOP]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
150 define([REF_STOPS]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
151 FIMPORT([ADD_PATH],) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
152 FIMPORT([ADD_RECT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
153 define([ADD_COORD]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
154 FIMPORT([FILL_SHAPE]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
155 FIMPORT([STROKE_SHAPE]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
156 define([FILL_SHAPE_WITH_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
157 define([STROKE_SHAPE_WITH_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
158 divert[]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
159 |
63 | 160 define([MADBUTTERFLY],[dnl |
161 [#include <stdio.h> | |
162 #include "mb_types.h" | |
163 #include "redraw_man.h" | |
164 #include "shapes.h" | |
165 #include "paint.h" | |
166 #include "$1.h" | |
167 | |
168 $1_t *$1_new(redraw_mant_t *rdman) { | |
64 | 169 $1_t *obj; |
170 grad_stop_t *stops = NULL;]DECLARE_VARS | |
63 | 171 $2[]dnl |
172 [ | |
173 obj = ($1_t *)malloc(sizeof($1_t)); | |
174 if(obj == NULL) return NULL; | |
175 ]SETUP_VARS | |
64 | 176 obj->root_coord = rdman->root_coord; |
63 | 177 $2 |
178 [ return obj; | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
179 } |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
180 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
181 void $1_free($1_t *obj) { |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
182 grad_stop_t *stops; |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
183 ]CLEAR_VARS[]$2[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
184 free(obj); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
185 } |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
186 ]dnl |
63 | 187 ]) |
188 divert[]dnl |