From 51b96e84cfa8be259cf42666d23c6dbd239ac44b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 29 Mar 2018 06:48:10 -0700 Subject: args: new args reversing function. * args.c (args_copy_reverse): New function. * args.h (args_copy_reverse): Declared. --- args.c | 11 +++++++++++ args.h | 1 + 2 files changed, 12 insertions(+) diff --git a/args.c b/args.c index aa2139a7..c93d8108 100644 --- a/args.c +++ b/args.c @@ -117,6 +117,17 @@ struct args *args_cat_zap_from(struct args *to, struct args *from, cnum index) return to; } +struct args *args_copy_reverse(struct args *to, struct args *from, cnum nargs) +{ + cnum i, index = 0; + + for (i = nargs - 1; i >= 0; i--) + to->arg[i] = args_get(from, &index); + + to->fill = nargs; + return to; +} + val args_copy_to_list(struct args *args) { list_collect_decl (out, ptail); diff --git a/args.h b/args.h index 76aa10a1..df244e3b 100644 --- a/args.h +++ b/args.h @@ -187,6 +187,7 @@ struct args *args_copy(struct args *to, struct args *from); struct args *args_copy_zap(struct args *to, struct args *from); struct args *args_cat_zap(struct args *to, struct args *from); struct args *args_cat_zap_from(struct args *to, struct args *from, cnum index); +struct args *args_copy_reverse(struct args *to, struct args *from, cnum nargs); val args_copy_to_list(struct args *args); void args_for_each(struct args *args, int (*fn)(val arg, int ix, mem_t *ctx), -- cgit v1.2.3