From f2b6d100d8958a9c811c950f113a0ce38a25d484 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 6 Dec 2016 22:06:26 +0200 Subject: Add min_required and max_expected arg counts to API. --- extension/filefuncs.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index a074de53..02b40534 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -160,9 +160,6 @@ do_chdir(int nargs, awk_value_t *result) assert(result != NULL); - if (do_lint && nargs != 1) - lintwarn(ext_id, _("chdir: called with incorrect number of arguments, expecting 1")); - if (get_argument(0, AWK_STRING, & newdir)) { ret = chdir(newdir.str_value.str); if (ret < 0) @@ -472,12 +469,6 @@ do_stat(int nargs, awk_value_t *result) assert(result != NULL); - if (nargs != 2 && nargs != 3) { - if (do_lint) - lintwarn(ext_id, _("stat: called with wrong number of arguments")); - return make_number(-1, result); - } - /* file is first arg, array to hold results is second */ if ( ! get_argument(0, AWK_STRING, & file_param) || ! get_argument(1, AWK_ARRAY, & array_param)) { @@ -522,12 +513,6 @@ do_statvfs(int nargs, awk_value_t *result) assert(result != NULL); - if (nargs != 2) { - if (do_lint) - lintwarn(ext_id, _("statvfs: called with wrong number of arguments")); - return make_number(-1, result); - } - /* file is first arg, array to hold results is second */ if ( ! get_argument(0, AWK_STRING, & file_param) || ! get_argument(1, AWK_ARRAY, & array_param)) { @@ -845,7 +830,7 @@ do_fts(int nargs, awk_value_t *result) assert(result != NULL); fts_errors = 0; /* ensure a fresh start */ - if (do_lint && nargs != 3) + if (nargs > 3) lintwarn(ext_id, _("fts: called with incorrect number of arguments, expecting 3")); if (! get_argument(0, AWK_ARRAY, & pathlist)) { @@ -928,13 +913,13 @@ out: #endif /* ! __MINGW32__ */ static awk_ext_func_t func_table[] = { - { "chdir", do_chdir, 1 }, - { "stat", do_stat, 3 }, + { "chdir", do_chdir, 1, 1 }, + { "stat", do_stat, 2, 3 }, #ifndef __MINGW32__ - { "fts", do_fts, 3 }, + { "fts", do_fts, 3, 3 }, #endif #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - { "statvfs", do_statvfs, 2 }, + { "statvfs", do_statvfs, 2, 2 }, #endif }; -- cgit v1.2.3 From 539de0a854fb94fd6ba47e91cee55f22fcd851a3 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 12 Dec 2016 21:54:57 +0200 Subject: Improve handling of min and max args for extension functions. --- extension/filefuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 02b40534..de293bee 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -914,7 +914,7 @@ out: static awk_ext_func_t func_table[] = { { "chdir", do_chdir, 1, 1 }, - { "stat", do_stat, 2, 3 }, + { "stat", do_stat, 3, 2 }, #ifndef __MINGW32__ { "fts", do_fts, 3, 3 }, #endif -- cgit v1.2.3 From 0855ef4db6d8e0d1d57776eb273c9de321bfd6cf Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 14 Dec 2016 21:25:20 +0200 Subject: Fix lint stuff, arg checking. Add a data pointer. Pass finfo to functions. --- extension/filefuncs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index de293bee..696a8599 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -153,7 +153,7 @@ int plugin_is_GPL_compatible; /* do_chdir --- provide dynamically loaded chdir() function for gawk */ static awk_value_t * -do_chdir(int nargs, awk_value_t *result) +do_chdir(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t newdir; int ret = -1; @@ -458,7 +458,7 @@ fill_stat_array(const char *name, awk_array_t array, struct stat *sbuf) /* do_stat --- provide a stat() function for gawk */ static awk_value_t * -do_stat(int nargs, awk_value_t *result) +do_stat(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t file_param, array_param; char *name; @@ -503,7 +503,7 @@ do_stat(int nargs, awk_value_t *result) /* do_statvfs --- provide a statvfs() function for gawk */ static awk_value_t * -do_statvfs(int nargs, awk_value_t *result) +do_statvfs(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t file_param, array_param; char *name; @@ -599,7 +599,7 @@ init_filefuncs(void) */ static awk_value_t * -do_fts(int nargs, awk_value_t *result) +do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused) { fatal(ext_id, _("fts is not supported on this system")); @@ -814,7 +814,7 @@ process(FTS *heirarchy, awk_array_t destarray, int seedot) */ static awk_value_t * -do_fts(int nargs, awk_value_t *result) +do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused) { awk_value_t pathlist, flagval, dest; awk_flat_array_t *path_array = NULL; @@ -913,13 +913,13 @@ out: #endif /* ! __MINGW32__ */ static awk_ext_func_t func_table[] = { - { "chdir", do_chdir, 1, 1 }, - { "stat", do_stat, 3, 2 }, + { "chdir", do_chdir, 1, 1, awk_false, NULL }, + { "stat", do_stat, 2, 3, awk_false, NULL }, #ifndef __MINGW32__ - { "fts", do_fts, 3, 3 }, + { "fts", do_fts, 3, 3, awk_false, NULL }, #endif #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - { "statvfs", do_statvfs, 2, 2 }, + { "statvfs", do_statvfs, 2, 2, awk_false, NULL }, #endif }; -- cgit v1.2.3 From 570758ee453fb42451f52a451e75d0a51c732cde Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 16 Dec 2016 14:02:26 +0200 Subject: Further improvements to min/max args code and doc. --- extension/filefuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extension/filefuncs.c') diff --git a/extension/filefuncs.c b/extension/filefuncs.c index 696a8599..394de504 100644 --- a/extension/filefuncs.c +++ b/extension/filefuncs.c @@ -914,7 +914,7 @@ out: static awk_ext_func_t func_table[] = { { "chdir", do_chdir, 1, 1, awk_false, NULL }, - { "stat", do_stat, 2, 3, awk_false, NULL }, + { "stat", do_stat, 3, 2, awk_false, NULL }, #ifndef __MINGW32__ { "fts", do_fts, 3, 3, awk_false, NULL }, #endif -- cgit v1.2.3