annotate tools/mb_c_source.m4 @ 64:c668c5c3ceae

M4 macro for C binding.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 13 Aug 2008 02:07:40 +0800
parents f4b792afa74e
children 309f1eefbec0
rev   line source
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 changequote(`[', `]')dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 include([foreach.m4])dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 divert([-1])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
5 define([UNQUOTE], [$*])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
6
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
7 define([QUOTE], [[[$*]]])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
9 define([COUNT],[ifelse([$*],[],0,[$#])])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
13 define([D_COLOR_STOP],[
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
14 {$6,$2,$3,$4,$5}])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 define([D_ADD_LINEAR_PAINT],[dnl
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
17 ifelse(COUNT($6),0,,[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
18 static const int n_$1_stops = COUNT($6);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
19 static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)};
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 ])dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 ])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 define([D_ADD_RADIAL_PAINT],[dnl
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
24 ifelse(COUNT($5),0,,[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
25 static const int n_$1_stops = COUNT($5);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
26 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)};
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 ])dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 ])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 define([DECLARE_VARS], [divert([-1])
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
31 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
32 DIMPORT([ADD_LINEAR_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
33 DIMPORT([ADD_RADIAL_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
34 DIMPORT([COLOR_STOP])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
35 define([REF_STOPS],)
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
36 define([ADD_PATH],)
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
37 define([ADD_RECT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
38 define([ADD_COORD])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
39 define([FILL_SHAPE])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
40 define([STROKE_SHAPE])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
41 define([FILL_SHAPE_WITH_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
42 define([STROKE_SHAPE_WITH_PAINT])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 divert[]])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 define([S_ADD_LINEAR_PAINT],[
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5);
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
47 ifelse(COUNT($6),0,,[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
48 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
49 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
50 paint_linear_stops(obj->$1, n_$1_stops, stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
51 ])dnl
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 ])
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
53
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 define([S_ADD_RADIAL_PAINT],[
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 obj->$1 = mb_radial_new(rdman, $2, $3, $4);
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
56 ifelse(COUNT($5),0,,[
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
57 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
58 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
59 paint_radial_stops(obj->$1, n_$1_stops, stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
60 ])dnl
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 ])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
63 define([S_COLOR_STOP],[])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
64 define([S_REF_STOPS],[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
65 [ stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$2_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
66 memcpy(stops, $2_stops, sizeof(grad_stop_t) * n_$2_stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
67 paint_radial_stops(obj->$1, n_$2_stops, stops);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
68 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
69
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
70 define([S_ADD_RECT],[[
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
71 obj->$1 = sh_rect_new($2, $3, $4, $5, 0, 0);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
72 rdman_add_shape(rdman, obj->$1, obj->$6);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
73 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
74
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
75 define([S_ADD_PATH],[[
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
76 obj->$1 = sh_path_new("$2");
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
77 rdman_add_shape(rdman, obj->$1, obj->$3);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
78 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
79
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
80 define([S_ADD_COORD],[[
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
81 obj->$1 = (coord_t *)malloc(sizeof(coord_t));
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
82 coord_init(obj->$1, obj->$2);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
83 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
84
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
85 define([S_FILL_SHAPE_WITH_PAINT],[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
86 [ rdman_paint_fill(rdman, obj->$2, obj->$1);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
87 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
88
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
89 define([S_STROKE_SHAPE_WITH_PAINT],[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
90 [ rdman_paint_stroke(rdman, obj->$2, obj->$1);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
91 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
92
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
93 define([S_FILL_SHAPE],[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
94 [ obj->$1_fill = paint_color_new(rdman, $2, $3, $4, $5);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
95 rdman_paint_fill(rdman, obj->$1_fill, obj->$1);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
96 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
97
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
98 define([S_STROKE_SHAPE],[dnl
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
99 [ obj->$1_stroke = paint_color_new(rdman, $2, $3, $4, $5);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
100 rdman_paint_stroke(rdman, obj->$1_stroke, obj->$1);
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
101 ]])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
102
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 define([SETUP_VARS],[divert([-1])
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
104 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
105 SIMPORT([ADD_LINEAR_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
106 SIMPORT([ADD_RADIAL_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
107 SIMPORT([COLOR_STOP])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
108 SIMPORT([REF_STOPS])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
109 SIMPORT([ADD_PATH],)
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
110 SIMPORT([ADD_RECT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
111 SIMPORT([ADD_COORD])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
112 SIMPORT([FILL_SHAPE])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
113 SIMPORT([STROKE_SHAPE])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
114 SIMPORT([FILL_SHAPE_WITH_PAINT])
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
115 SIMPORT([STROKE_SHAPE_WITH_PAINT])
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 divert[]])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 define([MADBUTTERFLY],[dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 [#include <stdio.h>
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 #include "mb_types.h"
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 #include "redraw_man.h"
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 #include "shapes.h"
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 #include "paint.h"
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 #include "$1.h"
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 $1_t *$1_new(redraw_mant_t *rdman) {
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
127 $1_t *obj;
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
128 grad_stop_t *stops = NULL;]DECLARE_VARS
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 $2[]dnl
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 [
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 obj = ($1_t *)malloc(sizeof($1_t));
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 if(obj == NULL) return NULL;
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 ]SETUP_VARS
64
c668c5c3ceae M4 macro for C binding.
Thinker K.F. Li <thinker@branda.to>
parents: 63
diff changeset
134 obj->root_coord = rdman->root_coord;
63
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 $2
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 [ return obj;
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 }]
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 ])
f4b792afa74e m4 translator
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 divert[]dnl