comparison 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
comparison
equal deleted inserted replaced
63:f4b792afa74e 64:c668c5c3ceae
1 changequote(`[', `]')dnl 1 changequote(`[', `]')dnl
2 include([foreach.m4])dnl 2 include([foreach.m4])dnl
3 divert([-1]) 3 divert([-1])
4 4
5 define([COUNT],[pushdef([COUNT_N])define([COUNT_N],0)dnl 5 define([UNQUOTE], [$*])
6 foreach([x],[($1)],[define([COUNT_N],incr(COUNT_N))])COUNT_N[]dnl
7 popdef([COUNT_N])[]])
8 6
9 define([STOP_FIELDS],[dnl 7 define([QUOTE], [[[$*]]])
10 ifelse(COUNT($2),0,,[dnl
11 [ int n_$1_stops;
12 grad_stop_t *$1_stop;
13 ]])dnl
14 ])
15 8
16 define([IMPORT],[define([$1],[$2$1(][$][@)])]) 9 define([COUNT],[ifelse([$*],[],0,[$#])])
17 10
18 define([D_COLOR_STOP],[{$2,$3,$4,$5,$6},]) 11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])])
12
13 define([D_COLOR_STOP],[
14 {$6,$2,$3,$4,$5}])
19 15
20 define([D_ADD_LINEAR_PAINT],[dnl 16 define([D_ADD_LINEAR_PAINT],[dnl
21 ifelse(COUNT([$6]),0,,[dnl 17 ifelse(COUNT($6),0,,[dnl
22 static int n_$1_stops = COUNT([$6]); 18 static const int n_$1_stops = COUNT($6);
23 static grad_stop_t $1_stops[[]] = {$6}; 19 static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)};
24 ])dnl 20 ])dnl
25 ]) 21 ])
26 22
27 define([D_ADD_RADIAL_PAINT],[dnl 23 define([D_ADD_RADIAL_PAINT],[dnl
28 ifelse(COUNT([$5]),0,,[dnl 24 ifelse(COUNT($5),0,,[dnl
29 static int n_$1_stops = COUNT([$5]); 25 static const int n_$1_stops = COUNT($5);
26 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)};
30 ])dnl 27 ])dnl
31 ]) 28 ])
32 29
33 define([D_REF_STOPS],[]);
34
35 define([DECLARE_VARS], [divert([-1]) 30 define([DECLARE_VARS], [divert([-1])
36 IMPORT([ADD_LINEAR_PAINT], [D_]) 31 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])])
37 IMPORT([ADD_RADIAL_PAINT],[D_]) 32 DIMPORT([ADD_LINEAR_PAINT])
38 IMPORT([REF_STOPS],[D_]) 33 DIMPORT([ADD_RADIAL_PAINT])
39 IMPORT([COLOR_STOP],[D_]) 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])
40 divert[]]) 43 divert[]])
41 44
42 define([S_ADD_LINEAR_PAINT],[ 45 define([S_ADD_LINEAR_PAINT],[
43 obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5); 46 obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5);
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
44 ]) 52 ])
53
45 define([S_ADD_RADIAL_PAINT],[ 54 define([S_ADD_RADIAL_PAINT],[
46 obj->$1 = mb_radial_new(rdman, $2, $3, $4); 55 obj->$1 = mb_radial_new(rdman, $2, $3, $4);
47 ]) 56 ifelse(COUNT($5),0,,[
48 define([S_REF_STOPS],[dnl 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
49 ]) 61 ])
50 62
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],[[
81 obj->$1 = (coord_t *)malloc(sizeof(coord_t));
82 coord_init(obj->$1, obj->$2);
83 ]])
84
85 define([S_FILL_SHAPE_WITH_PAINT],[dnl
86 [ rdman_paint_fill(rdman, obj->$2, obj->$1);
87 ]])
88
89 define([S_STROKE_SHAPE_WITH_PAINT],[dnl
90 [ rdman_paint_stroke(rdman, obj->$2, obj->$1);
91 ]])
92
93 define([S_FILL_SHAPE],[dnl
94 [ obj->$1_fill = paint_color_new(rdman, $2, $3, $4, $5);
95 rdman_paint_fill(rdman, obj->$1_fill, obj->$1);
96 ]])
97
98 define([S_STROKE_SHAPE],[dnl
99 [ obj->$1_stroke = paint_color_new(rdman, $2, $3, $4, $5);
100 rdman_paint_stroke(rdman, obj->$1_stroke, obj->$1);
101 ]])
102
51 define([SETUP_VARS],[divert([-1]) 103 define([SETUP_VARS],[divert([-1])
52 IMPORT([ADD_LINEAR_PAINT],[S_]) 104 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])])
53 IMPORT([ADD_RADIAL_PAINT],[S_]) 105 SIMPORT([ADD_LINEAR_PAINT])
54 IMPORT([REF_STOPS],[S_]) 106 SIMPORT([ADD_RADIAL_PAINT])
107 SIMPORT([COLOR_STOP])
108 SIMPORT([REF_STOPS])
109 SIMPORT([ADD_PATH],)
110 SIMPORT([ADD_RECT])
111 SIMPORT([ADD_COORD])
112 SIMPORT([FILL_SHAPE])
113 SIMPORT([STROKE_SHAPE])
114 SIMPORT([FILL_SHAPE_WITH_PAINT])
115 SIMPORT([STROKE_SHAPE_WITH_PAINT])
55 divert[]]) 116 divert[]])
56 117
57 define([MADBUTTERFLY],[dnl 118 define([MADBUTTERFLY],[dnl
58 [#include <stdio.h> 119 [#include <stdio.h>
59 #include "mb_types.h" 120 #include "mb_types.h"
61 #include "shapes.h" 122 #include "shapes.h"
62 #include "paint.h" 123 #include "paint.h"
63 #include "$1.h" 124 #include "$1.h"
64 125
65 $1_t *$1_new(redraw_mant_t *rdman) { 126 $1_t *$1_new(redraw_mant_t *rdman) {
66 $1_t *obj;]DECLARE_VARS 127 $1_t *obj;
128 grad_stop_t *stops = NULL;]DECLARE_VARS
67 $2[]dnl 129 $2[]dnl
68 [ 130 [
69 obj = ($1_t *)malloc(sizeof($1_t)); 131 obj = ($1_t *)malloc(sizeof($1_t));
70 if(obj == NULL) return NULL; 132 if(obj == NULL) return NULL;
71 ]SETUP_VARS 133 ]SETUP_VARS
134 obj->root_coord = rdman->root_coord;
72 $2 135 $2
73 [ return obj; 136 [ return obj;
74 }] 137 }]
75 ]) 138 ])
76 divert[]dnl 139 divert[]dnl