comparison tools/mb_c_source.m4 @ 63:f4b792afa74e

m4 translator
author Thinker K.F. Li <thinker@branda.to>
date Tue, 12 Aug 2008 14:21:09 +0800
parents
children c668c5c3ceae
comparison
equal deleted inserted replaced
62:7d976d925431 63:f4b792afa74e
1 changequote(`[', `]')dnl
2 include([foreach.m4])dnl
3 divert([-1])
4
5 define([COUNT],[pushdef([COUNT_N])define([COUNT_N],0)dnl
6 foreach([x],[($1)],[define([COUNT_N],incr(COUNT_N))])COUNT_N[]dnl
7 popdef([COUNT_N])[]])
8
9 define([STOP_FIELDS],[dnl
10 ifelse(COUNT($2),0,,[dnl
11 [ int n_$1_stops;
12 grad_stop_t *$1_stop;
13 ]])dnl
14 ])
15
16 define([IMPORT],[define([$1],[$2$1(][$][@)])])
17
18 define([D_COLOR_STOP],[{$2,$3,$4,$5,$6},])
19
20 define([D_ADD_LINEAR_PAINT],[dnl
21 ifelse(COUNT([$6]),0,,[dnl
22 static int n_$1_stops = COUNT([$6]);
23 static grad_stop_t $1_stops[[]] = {$6};
24 ])dnl
25 ])
26
27 define([D_ADD_RADIAL_PAINT],[dnl
28 ifelse(COUNT([$5]),0,,[dnl
29 static int n_$1_stops = COUNT([$5]);
30 ])dnl
31 ])
32
33 define([D_REF_STOPS],[]);
34
35 define([DECLARE_VARS], [divert([-1])
36 IMPORT([ADD_LINEAR_PAINT], [D_])
37 IMPORT([ADD_RADIAL_PAINT],[D_])
38 IMPORT([REF_STOPS],[D_])
39 IMPORT([COLOR_STOP],[D_])
40 divert[]])
41
42 define([S_ADD_LINEAR_PAINT],[
43 obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5);
44 ])
45 define([S_ADD_RADIAL_PAINT],[
46 obj->$1 = mb_radial_new(rdman, $2, $3, $4);
47 ])
48 define([S_REF_STOPS],[dnl
49 ])
50
51 define([SETUP_VARS],[divert([-1])
52 IMPORT([ADD_LINEAR_PAINT],[S_])
53 IMPORT([ADD_RADIAL_PAINT],[S_])
54 IMPORT([REF_STOPS],[S_])
55 divert[]])
56
57 define([MADBUTTERFLY],[dnl
58 [#include <stdio.h>
59 #include "mb_types.h"
60 #include "redraw_man.h"
61 #include "shapes.h"
62 #include "paint.h"
63 #include "$1.h"
64
65 $1_t *$1_new(redraw_mant_t *rdman) {
66 $1_t *obj;]DECLARE_VARS
67 $2[]dnl
68 [
69 obj = ($1_t *)malloc(sizeof($1_t));
70 if(obj == NULL) return NULL;
71 ]SETUP_VARS
72 $2
73 [ return obj;
74 }]
75 ])
76 divert[]dnl