summaryrefslogtreecommitdiffabout
path: root/src/snarf.m4
Side-by-side diff
Diffstat (limited to 'src/snarf.m4') (more/less context) (ignore whitespace changes)
-rw-r--r--src/snarf.m470
1 files changed, 50 insertions, 20 deletions
diff --git a/src/snarf.m4 b/src/snarf.m4
index 6d41932..7ceb4af 100644
--- a/src/snarf.m4
+++ b/src/snarf.m4
@@ -79,25 +79,49 @@ m4_define([<__mf_c_getarg>],m4_dnl
[<m4_ifelse($1,STRING,get_string_arg,$1,NUMBER,get_numeric_arg, ERROR )>])
/* mf_c_argdcl(TYPE NAME) -- translate Mailfromd declaration "TYPE NAME"
- * into the corresponding C one, followed by an equals sign, a typecast,
- * and the name of corresponding get_.*_arg function
- * e.g.:
- * mf_c_argdcl(STRING str) => char *str = (char*) get_string_arg
+ * into the corresponding C one:
+ *
+ * mf_c_argdcl(STRING str) => char *str
*/
m4_define([<mf_c_argdcl>],m4_dnl
-[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2 = ([<__mf_c_type(\1)>]) [<__mf_c_getarg(\1)>])>])
+[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_type(\1)>] \2)>])
+
+/* mf_c_arginit(TYPE NAME, NUM) -- translate Mailfromd declaration "TYPE NAME"
+ * into the corresponding C initialization:
+ *
+ * mf_c_argdcl(STRING str) => get_string_arg(env, NUM, &str)
+ */
+m4_define([<mf_c_arginit>],m4_dnl
+[<m4_regexp([<$1>],[<\(\w+\)\W+\(\w+\)>],[<__mf_c_getarg(\1)(env, $2, &\2)>])>])
+
+/* __mf_c_argdcl_list(NARG, LIST) -- translate Mailfromd declaration list
+ * into a set of corresponding C variable declarations.
+ * For more details, see mf_c_arglist below.
+ */
+m4_define([<__mf_c_argdcl_list>],m4_dnl
+[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
+__mf_c_argdcl_list($1, m4_shift(m4_shift($@)))>],
+[<mf_c_argdcl($2);
+ __mf_c_argdcl_list(m4_incr($1), m4_shift(m4_shift($@)))>])>])
+
+/* __mf_c_arginit_list(NARG, LIST) -- translate Mailfromd declaration list
+ * into a set of corresponding C variable initializations.
+ * For more details, see mf_c_arglist below.
+ */
+m4_define([<__mf_c_arginit_list>],m4_dnl
+[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
+__mf_c_arginit_list($1, m4_shift(m4_shift($@)))>],
+[<mf_c_arginit($2, m4_eval($1));
+ __mf_c_arginit_list(m4_incr($1), m4_shift(m4_shift($@)))>])>])
/* __mf_c_arglist(NARG, LIST) -- translate Mailfromd declaration list
- * into a set of corresponding C variable declarations with initializations.
+ * into a set of corresponding C variable declarations and initializations.
* Arguments:
* NARG -- ordinal number of the first variable in LIST
* LIST -- comma-separated list of Mailfromd declarations
*/
-m4_define([<__mf_c_arglist>],m4_dnl
-[<m4_ifelse($2, , ,$2,[<OPTIONAL>],[<m4_dnl
-__mf_c_arglist($1, m4_shift(m4_shift($@)))>],
-[<mf_c_argdcl($2)(env, m4_eval($1));
- __mf_c_arglist(m4_incr($1), m4_shift(m4_shift($@)))>])>])
+m4_define([<__mf_c_arglist>],[<__mf_c_argdcl_list($@)
+__mf_c_arginit_list($@)>])
/* mf_c_arglist(LIST) -- translate Mailfromd declaration list
* into a set of corresponding C variable declarations with initializations.
@@ -105,23 +129,29 @@ __mf_c_arglist($1, m4_shift(m4_shift($@)))>],
* variables.
* E.g.:
* mf_c_arglist(STRING a, NUMBER n) =>
- * char *a = (char*)get_string_arg(env, 0);
- * long n = (long)get_numeric_arg(env, 1);
+ * char *a;
+ * long n;
+ * get_string_arg(env, 0, &a);
+ * get_numeric_arg(env, 1, &n);
* adjust_stack(env, 2);
*
* Or, if the builtin takes optional parameters:
*
* mf_c_arglist(STRING a, NUMBER n) =>
- * long __bi_argcnt = (long)get_numeric_arg(env, 0);
- * char *a = (char*)get_string_arg(env, 1);
- * long n = (long)get_numeric_arg(env, 2);
+ * long __bi_argcnt;
+ * char *a;
+ * long n;
+ * get_string_arg(env, 1, &a);
+ * get_numeric_arg(env, 2, &n);
+ * get_numeric_arg(env, 0, &__bi_argcnt);
* adjust_stack(env, __bi_argcnt + 1);
*/
m4_define([<mf_c_arglist>],m4_dnl
[<
m4_pushdef([<__ARG1__>], m4_ifelse(__MF_VARARGS__,1,1,[<__mf_has_optarg($@)>]))
-m4_ifelse(__ARG1__,0,,[<long __bi_argcnt = (long)get_numeric_arg(env, 0);>])
+m4_ifelse(__ARG1__,0,,[<long __bi_argcnt;>])
__mf_c_arglist(__ARG1__, $@)
+m4_ifelse(__ARG1__,0,,[<get_numeric_arg(env, 0, &__bi_argcnt);>])
adjust_stack(env, m4_ifelse(__ARG1__,0,mf_argcount($@),__bi_argcnt + 1));
m4_popdef([<__ARG1__>])m4_dnl
>])
@@ -429,13 +459,13 @@ m4_ifelse(__MF_VARARGS__,1,[<__mf_va_count>],
)m4_dnl
m4_define([<__mf_error_code>],1)>])>])
-/* MF_VA_ARG(N, TYPE) -- Produce a code for returning Nth argument of the
- given TYPE in a vararg section. */
+/* MF_VA_ARG(N, TYPE, VAR) -- Produce a code for assigning to VAR the Nth
+ argument of the given TYPE in a vararg section. */
m4_define([<MF_VA_ARG>],[<m4_dnl
m4_ifdef([<__MF_VA_START_USED__>],m4_dnl
[<m4_pushdef([<__ARGN__>],[<$1+mf_argcount(__MF_ARGLIST__)>])
((__bi_argcnt > __ARGN__) ?m4_dnl
- __mf_c_getarg($2)(env, __ARGN__ + 1) :m4_dnl
+ __mf_c_getarg($2)(env, __ARGN__ + 1, &$3) :m4_dnl
(MF_THROW(mfe_range, "Argument %d is not supplied", __ARGN__),m4_dnl
(__mf_c_type($2)) 0))m4_dnl
m4_popdef([<__ARGN__>])>],

Return to:

Send suggestions and report system problems to the System administrator.