From 22d5a7124a6b63f300baa8c712b76b185a0f7a0f Mon Sep 17 00:00:00 2001 From: rlar Date: Thu, 12 Nov 2015 17:55:58 +0100 Subject: [PATCH] frontend/define.c, abstraction, introduce `numargs()' --- src/frontend/define.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/frontend/define.c b/src/frontend/define.c index aa819b284..108966c87 100644 --- a/src/frontend/define.c +++ b/src/frontend/define.c @@ -30,6 +30,7 @@ static void prtree(struct udfunc *ud, FILE *fp); static void prtree1(struct pnode *pn, FILE *fp); static struct pnode *trcopy(struct pnode *tree, char *arg_names, struct pnode *args); static struct pnode *ntharg(int num, struct pnode *args); +static int numargs(struct pnode *args); static struct udfunc *udfuncs = NULL; @@ -262,16 +263,9 @@ struct pnode * ft_substdef(const char *name, struct pnode *args) { struct udfunc *udf, *wrong_udf = NULL; - struct pnode *tp; char *arg_names; - int arity = 0; - if (args) - arity = 1; - - for (tp = args; tp && tp->pn_op && (tp->pn_op->op_num == PT_OP_COMMA); tp = - tp->pn_right) - arity++; + int arity = numargs(args); for (udf = udfuncs; udf; udf = udf->ud_next) if (eq(name, udf->ud_name)) { @@ -398,6 +392,23 @@ ntharg(int num, struct pnode *args) } +static int +numargs(struct pnode *args) +{ + struct pnode *tp; + int arity = 0; + + if (args) + arity = 1; + + for (tp = args; tp && tp->pn_op && (tp->pn_op->op_num == PT_OP_COMMA); tp = + tp->pn_right) + arity++; + + return arity; +} + + void com_undefine(wordlist *wlist) {