diff options
Diffstat (limited to 'src/snarf.m4')
-rw-r--r-- | src/snarf.m4 | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/src/snarf.m4 b/src/snarf.m4 index 6d419326..7ceb4af1 100644 --- a/src/snarf.m4 +++ b/src/snarf.m4 | |||
@@ -79,25 +79,49 @@ m4_define([<__mf_c_getarg>],m4_dnl | |||
79 | [<m4_ifelse($1,STRING,get_string_arg,$1,NUMBER,get_numeric_arg, ERROR )>]) | 79 | [<m4_ifelse($1,STRING,get_string_arg,$1,NUMBER,get_numeric_arg, ERROR )>]) |
80 | 80 | ||
81 | /* mf_c_argdcl(TYPE NAME) -- translate Mailfromd declaration "TYPE NAME" | 81 | /* mf_c_argdcl(TYPE NAME) -- translate Mailfromd declaration "TYPE NAME" |
82 | * into the corresponding C one, followed by an equals sign, a typecast, | 82 | * into the corresponding C one: |
83 | * and the name of corresponding get_.*_arg function | 83 | * |
84 | * e.g.: | 84 | * mf_c_argdcl(STRING str) => char *str |
85 | * mf_c_argdcl(STRING str) => char *str = (char*) get_string_arg | ||
86 | */ | 85 | */ |
87 | m4_define([<mf_c_argdcl>],m4_dnl | 86 | m4_define([<mf_c_argdcl>],m4_dnl |
88 | [<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2 = ([<__mf_c_type(\1)>]) [<__mf_c_getarg(\1)>])>]) | 87 | [<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2)>]) |
88 | |||
89 | /* mf_c_arginit(TYPE NAME, NUM) -- translate Mailfromd declaration "TYPE NAME" | ||
90 | * into the corresponding C initialization: | ||
91 | * | ||
92 | * mf_c_argdcl(STRING str) => get_string_arg(env, NUM, &str) | ||
93 | */ | ||
94 | m4_define([<mf_c_arginit>],m4_dnl | ||
95 | [<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_getarg(\1)(env, $2, &\2)>])>]) | ||
96 | |||
97 | /* __mf_c_argdcl_list(NARG, LIST) -- translate Mailfromd declaration list | ||
98 | * into a set of corresponding C variable declarations. | ||
99 | * For more details, see mf_c_arglist below. | ||
100 | */ | ||
101 | m4_define([<__mf_c_argdcl_list>],m4_dnl | ||
102 | [<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl | ||
103 | __mf_c_argdcl_list($1, m4_shift(m4_shift($@)))>], | ||
104 | [<mf_c_argdcl($2); | ||
105 | __mf_c_argdcl_list(m4_incr($1), m4_shift(m4_shift($@)))>])>]) | ||
106 | |||
107 | /* __mf_c_arginit_list(NARG, LIST) -- translate Mailfromd declaration list | ||
108 | * into a set of corresponding C variable initializations. | ||
109 | * For more details, see mf_c_arglist below. | ||
110 | */ | ||
111 | m4_define([<__mf_c_arginit_list>],m4_dnl | ||
112 | [<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl | ||
113 | __mf_c_arginit_list($1, m4_shift(m4_shift($@)))>], | ||
114 | [<mf_c_arginit($2, m4_eval($1)); | ||
115 | __mf_c_arginit_list(m4_incr($1), m4_shift(m4_shift($@)))>])>]) | ||
89 | 116 | ||
90 | /* __mf_c_arglist(NARG, LIST) -- translate Mailfromd declaration list | 117 | /* __mf_c_arglist(NARG, LIST) -- translate Mailfromd declaration list |
91 | * into a set of corresponding C variable declarations with initializations. | 118 | * into a set of corresponding C variable declarations and initializations. |
92 | * Arguments: | 119 | * Arguments: |
93 | * NARG -- ordinal number of the first variable in LIST | 120 | * NARG -- ordinal number of the first variable in LIST |
94 | * LIST -- comma-separated list of Mailfromd declarations | 121 | * LIST -- comma-separated list of Mailfromd declarations |
95 | */ | 122 | */ |
96 | m4_define([<__mf_c_arglist>],m4_dnl | 123 | m4_define([<__mf_c_arglist>],[<__mf_c_argdcl_list($@) |
97 | [<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl | 124 | __mf_c_arginit_list($@)>]) |
98 | __mf_c_arglist($1, m4_shift(m4_shift($@)))>], | ||
99 | [<mf_c_argdcl($2)(env, m4_eval($1)); | ||
100 | __mf_c_arglist(m4_incr($1), m4_shift(m4_shift($@)))>])>]) | ||
101 | 125 | ||
102 | /* mf_c_arglist(LIST) -- translate Mailfromd declaration list | 126 | /* mf_c_arglist(LIST) -- translate Mailfromd declaration list |
103 | * into a set of corresponding C variable declarations with initializations. | 127 | * into a set of corresponding C variable declarations with initializations. |
@@ -105,23 +129,29 @@ __mf_c_arglist($1, m4_shift(m4_shift($@)))>], | |||
105 | * variables. | 129 | * variables. |
106 | * E.g.: | 130 | * E.g.: |
107 | * mf_c_arglist(STRING a, NUMBER n) => | 131 | * mf_c_arglist(STRING a, NUMBER n) => |
108 | * char *a = (char*)get_string_arg(env, 0); | 132 | * char *a; |
109 | * long n = (long)get_numeric_arg(env, 1); | 133 | * long n; |
134 | * get_string_arg(env, 0, &a); | ||
135 | * get_numeric_arg(env, 1, &n); | ||
110 | * adjust_stack(env, 2); | 136 | * adjust_stack(env, 2); |
111 | * | 137 | * |
112 | * Or, if the builtin takes optional parameters: | 138 | * Or, if the builtin takes optional parameters: |
113 | * | 139 | * |
114 | * mf_c_arglist(STRING a, NUMBER n) => | 140 | * mf_c_arglist(STRING a, NUMBER n) => |
115 | * long __bi_argcnt = (long)get_numeric_arg(env, 0); | 141 | * long __bi_argcnt; |
116 | * char *a = (char*)get_string_arg(env, 1); | 142 | * char *a; |
117 | * long n = (long)get_numeric_arg(env, 2); | 143 | * long n; |
144 | * get_string_arg(env, 1, &a); | ||
145 | * get_numeric_arg(env, 2, &n); | ||
146 | * get_numeric_arg(env, 0, &__bi_argcnt); | ||
118 | * adjust_stack(env, __bi_argcnt + 1); | 147 | * adjust_stack(env, __bi_argcnt + 1); |
119 | */ | 148 | */ |
120 | m4_define([<mf_c_arglist>],m4_dnl | 149 | m4_define([<mf_c_arglist>],m4_dnl |
121 | [< | 150 | [< |
122 | m4_pushdef([<__ARG1__>], m4_ifelse(__MF_VARARGS__,1,1,[<__mf_has_optarg($@)>])) | 151 | m4_pushdef([<__ARG1__>], m4_ifelse(__MF_VARARGS__,1,1,[<__mf_has_optarg($@)>])) |
123 | m4_ifelse(__ARG1__,0,,[<long __bi_argcnt = (long)get_numeric_arg(env, 0);>]) | 152 | m4_ifelse(__ARG1__,0,,[<long __bi_argcnt;>]) |
124 | __mf_c_arglist(__ARG1__, $@) | 153 | __mf_c_arglist(__ARG1__, $@) |
154 | m4_ifelse(__ARG1__,0,,[<get_numeric_arg(env, 0, &__bi_argcnt);>]) | ||
125 | adjust_stack(env, m4_ifelse(__ARG1__,0,mf_argcount($@),__bi_argcnt + 1)); | 155 | adjust_stack(env, m4_ifelse(__ARG1__,0,mf_argcount($@),__bi_argcnt + 1)); |
126 | m4_popdef([<__ARG1__>])m4_dnl | 156 | m4_popdef([<__ARG1__>])m4_dnl |
127 | >]) | 157 | >]) |
@@ -429,13 +459,13 @@ m4_ifelse(__MF_VARARGS__,1,[<__mf_va_count>], | |||
429 | )m4_dnl | 459 | )m4_dnl |
430 | m4_define([<__mf_error_code>],1)>])>]) | 460 | m4_define([<__mf_error_code>],1)>])>]) |
431 | 461 | ||
432 | /* MF_VA_ARG(N, TYPE) -- Produce a code for returning Nth argument of the | 462 | /* MF_VA_ARG(N, TYPE, VAR) -- Produce a code for assigning to VAR the Nth |
433 | given TYPE in a vararg section. */ | 463 | argument of the given TYPE in a vararg section. */ |
434 | m4_define([<MF_VA_ARG>],[<m4_dnl | 464 | m4_define([<MF_VA_ARG>],[<m4_dnl |
435 | m4_ifdef([<__MF_VA_START_USED__>],m4_dnl | 465 | m4_ifdef([<__MF_VA_START_USED__>],m4_dnl |
436 | [<m4_pushdef([<__ARGN__>],[<$1+mf_argcount(__MF_ARGLIST__)>]) | 466 | [<m4_pushdef([<__ARGN__>],[<$1+mf_argcount(__MF_ARGLIST__)>]) |
437 | ((__bi_argcnt > __ARGN__) ?m4_dnl | 467 | ((__bi_argcnt > __ARGN__) ?m4_dnl |
438 | __mf_c_getarg($2)(env, __ARGN__ + 1) :m4_dnl | 468 | __mf_c_getarg($2)(env, __ARGN__ + 1, &$3) :m4_dnl |
439 | (MF_THROW(mfe_range, "Argument %d is not supplied", __ARGN__),m4_dnl | 469 | (MF_THROW(mfe_range, "Argument %d is not supplied", __ARGN__),m4_dnl |
440 | (__mf_c_type($2)) 0))m4_dnl | 470 | (__mf_c_type($2)) 0))m4_dnl |
441 | m4_popdef([<__ARGN__>])>], | 471 | m4_popdef([<__ARGN__>])>], |