aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/ChangeLog23
-rw-r--r--extension/filefuncs.3am7
-rw-r--r--extension/filefuncs.c12
-rw-r--r--extension/inplace.c44
-rw-r--r--extension/testext.c28
5 files changed, 88 insertions, 26 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 69127623..35b82970 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -56,6 +56,10 @@
* intdiv.c (do_intdiv): Print a warning about loss of precision if
MPFR arguments are received when not compiled with MPFR support.
+2018-02-11 Arnold D. Robbins <arnold@skeeve.com>
+
+ * filefuncs.3am: Fix some typos.
+
2018-02-08 Andrew J. Schorr <aschorr@telemetry-investments.com>
* configure.ac (pkgextensiondir): This must be set to
@@ -71,6 +75,13 @@
revtwoway.3am, rwarray.3am, time.3am: Add vim modeline at the
bottom to set the file type for syntax coloring.
+2018-02-02 Arnold D. Robbins <arnold@skeeve.com>
+
+ * filefuncs.c (FTS_SKIP): New constant.
+ (process): Additional arg skipset. When true (based on if
+ FTS_SKIP was passed) and at level 0, use fts_set to set
+ FTS_SKIP on the directory.
+
2018-01-11 Arnold D. Robbins <arnold@skeeve.com>
* compile, config.guess, config.rpath, config.sub,
@@ -192,6 +203,18 @@
* Makefile.am: Update copyright year.
+2017-07-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * inplace.c: Move functions into "inplace" namespace and simplify
+ the names. Update all error messages accordingly.
+
+2017-07-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * testext.c (init_test_ext): Add installation of a variable and a
+ function in a namespace, and test using them.
+ (do_test_function): New function.
+ (ns_test_func): New function entry for it.
+
2017-06-27 Arnold D. Robbins <arnold@skeeve.com>
* Makfile.am (intdiv_la_LIBADD): Add LIBMPFR for Cygwin.
diff --git a/extension/filefuncs.3am b/extension/filefuncs.3am
index 36acf649..571fdea9 100644
--- a/extension/filefuncs.3am
+++ b/extension/filefuncs.3am
@@ -230,6 +230,9 @@ This option causes entries for ``..'' to also be included.
.TP
.B FTS_XDEV
During a traversal, do not cross onto a different mounted filesystem.
+.TP
+.B FTS_SKIP
+When set, causes top level directories to not be descended into.
.RE
.TP
.B filedata
@@ -321,6 +324,10 @@ the changed values are passed to
.SH BUGS
There are many more file-related functions for which AWK
interfaces would be desirable.
+.PP
+It's not clear why I thought adding
+.B FTS_SKIP
+was a good idea.
.SH EXAMPLE
See
.B test/fts.awk
diff --git a/extension/filefuncs.c b/extension/filefuncs.c
index 1cf37453..1ea25dbc 100644
--- a/extension/filefuncs.c
+++ b/extension/filefuncs.c
@@ -575,6 +575,7 @@ init_filefuncs(void)
ENTRY(FTS_PHYSICAL),
ENTRY(FTS_SEEDOT),
ENTRY(FTS_XDEV),
+ ENTRY(FTS_SKIP),
{ NULL, 0 }
};
@@ -690,7 +691,7 @@ fill_default_elements(awk_array_t element_array, const FTSENT *const fentry, awk
/* process --- process the hierarchy */
static void
-process(FTS *hierarchy, awk_array_t destarray, int seedot)
+process(FTS *hierarchy, awk_array_t destarray, int seedot, int skipset)
{
FTSENT *fentry;
awk_value_t index, value;
@@ -705,7 +706,12 @@ process(FTS *hierarchy, awk_array_t destarray, int seedot)
switch (fentry->fts_info) {
case FTS_D:
/* directory */
+
+ if (skipset && fentry->fts_level == 0)
+ fts_set(hierarchy, fentry, FTS_SKIP);
+
/* create array to hold entries */
+ /* this will be empty if doing FTS_SKIP */
newdir_array = create_array();
if (newdir_array == NULL) {
warning(ext_id, _("fts-process: could not create array"));
@@ -826,7 +832,7 @@ do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused)
int ret = -1;
static const int mask = (
FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR | FTS_PHYSICAL
- | FTS_SEEDOT | FTS_XDEV);
+ | FTS_SEEDOT | FTS_XDEV | FTS_SKIP);
assert(result != NULL);
fts_errors = 0; /* ensure a fresh start */
@@ -894,7 +900,7 @@ do_fts(int nargs, awk_value_t *result, struct awk_ext_func *unused)
/* let's do it! */
if ((hierarchy = fts_open(pathvector, flags, NULL)) != NULL) {
- process(hierarchy, dest.array_cookie, (flags & FTS_SEEDOT) != 0);
+ process(hierarchy, dest.array_cookie, (flags & FTS_SEEDOT) != 0, (flags & FTS_SKIP) != 0);
fts_close(hierarchy);
if (fts_errors == 0)
diff --git a/extension/inplace.c b/extension/inplace.c
index 516edc97..d2a04118 100644
--- a/extension/inplace.c
+++ b/extension/inplace.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2013-2015, 2018, the Free Software Foundation, Inc.
+ * Copyright (C) 2013-2015, 2017, 2018, the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -128,13 +128,13 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
fflush(stdout);
if (state.tname)
- fatal(ext_id, _("inplace_begin: in-place editing already active"));
+ fatal(ext_id, _("inplace::begin: in-place editing already active"));
if (nargs != 2)
- fatal(ext_id, _("inplace_begin: expects 2 arguments but called with %d"), nargs);
+ fatal(ext_id, _("inplace::begin: expects 2 arguments but called with %d"), nargs);
if (! get_argument(0, AWK_STRING, &filename))
- fatal(ext_id, _("inplace_begin: cannot retrieve 1st argument as a string filename"));
+ fatal(ext_id, _("inplace::begin: cannot retrieve 1st argument as a string filename"));
/*
* N.B. In the current implementation, the 2nd suffix arg is not used
@@ -142,21 +142,21 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
*/
if (invalid_filename(&filename.str_value)) {
- warning(ext_id, _("inplace_begin: disabling in-place editing for invalid FILENAME `%s'"),
+ warning(ext_id, _("inplace::begin: disabling in-place editing for invalid FILENAME `%s'"),
filename.str_value.str);
unset_ERRNO();
return make_number(-1, result);
}
if (stat(filename.str_value.str, & sbuf) < 0) {
- warning(ext_id, _("inplace_begin: Cannot stat `%s' (%s)"),
+ warning(ext_id, _("inplace::begin: Cannot stat `%s' (%s)"),
filename.str_value.str, strerror(errno));
update_ERRNO_int(errno);
return make_number(-1, result);
}
if (! S_ISREG(sbuf.st_mode)) {
- warning(ext_id, _("inplace_begin: `%s' is not a regular file"),
+ warning(ext_id, _("inplace::begin: `%s' is not a regular file"),
filename.str_value.str);
unset_ERRNO();
return make_number(-1, result);
@@ -167,7 +167,7 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
sprintf(state.tname, "%s.gawk.XXXXXX", filename.str_value.str);
if ((fd = mkstemp(state.tname)) < 0)
- fatal(ext_id, _("inplace_begin: mkstemp(`%s') failed (%s)"),
+ fatal(ext_id, _("inplace::begin: mkstemp(`%s') failed (%s)"),
state.tname, strerror(errno));
/* N.B. chown/chmod should be more portable than fchown/fchmod */
@@ -179,20 +179,20 @@ do_inplace_begin(int nargs, awk_value_t *result, struct awk_ext_func *unused)
}
if (chmod(state.tname, sbuf.st_mode) < 0)
- fatal(ext_id, _("inplace_begin: chmod failed (%s)"),
+ fatal(ext_id, _("inplace::begin: chmod failed (%s)"),
strerror(errno));
fflush(stdout);
/* N.B. fgetpos fails when stdout is a tty */
state.posrc = fgetpos(stdout, &state.pos);
if ((state.default_stdout = dup(STDOUT_FILENO)) < 0)
- fatal(ext_id, _("inplace_begin: dup(stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: dup(stdout) failed (%s)"),
strerror(errno));
if (dup2(fd, STDOUT_FILENO) < 0)
- fatal(ext_id, _("inplace_begin: dup2(%d, stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: dup2(%d, stdout) failed (%s)"),
fd, strerror(errno));
if (close(fd) < 0)
- fatal(ext_id, _("inplace_begin: close(%d) failed (%s)"),
+ fatal(ext_id, _("inplace::begin: close(%d) failed (%s)"),
fd, strerror(errno));
rewind(stdout);
return make_number(0, result);
@@ -208,30 +208,30 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
assert(result != NULL);
if (nargs != 2)
- fatal(ext_id, _("inplace_end: expects 2 arguments but called with %d"), nargs);
+ fatal(ext_id, _("inplace::end: expects 2 arguments but called with %d"), nargs);
if (! get_argument(0, AWK_STRING, &filename))
- fatal(ext_id, _("inplace_end: cannot retrieve 1st argument as a string filename"));
+ fatal(ext_id, _("inplace::end: cannot retrieve 1st argument as a string filename"));
if (! get_argument(1, AWK_STRING, &suffix))
suffix.str_value.str = NULL;
if (! state.tname) {
if (! invalid_filename(&filename.str_value))
- warning(ext_id, _("inplace_end: in-place editing not active"));
+ warning(ext_id, _("inplace::end: in-place editing not active"));
return make_number(0, result);
}
fflush(stdout);
if (dup2(state.default_stdout, STDOUT_FILENO) < 0)
- fatal(ext_id, _("inplace_end: dup2(%d, stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::end: dup2(%d, stdout) failed (%s)"),
state.default_stdout, strerror(errno));
if (close(state.default_stdout) < 0)
- fatal(ext_id, _("inplace_end: close(%d) failed (%s)"),
+ fatal(ext_id, _("inplace::end: close(%d) failed (%s)"),
state.default_stdout, strerror(errno));
state.default_stdout = -1;
if (state.posrc == 0 && fsetpos(stdout, &state.pos) < 0)
- fatal(ext_id, _("inplace_end: fsetpos(stdout) failed (%s)"),
+ fatal(ext_id, _("inplace::end: fsetpos(stdout) failed (%s)"),
strerror(errno));
if (suffix.str_value.str && suffix.str_value.str[0]) {
@@ -254,7 +254,7 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
#endif
if (rename(state.tname, filename.str_value.str) < 0)
- fatal(ext_id, _("inplace_end: rename(`%s', `%s') failed (%s)"),
+ fatal(ext_id, _("inplace::end: rename(`%s', `%s') failed (%s)"),
state.tname, filename.str_value.str, strerror(errno));
gawk_free(state.tname);
state.tname = NULL;
@@ -262,8 +262,8 @@ do_inplace_end(int nargs, awk_value_t *result, struct awk_ext_func *unused)
}
static awk_ext_func_t func_table[] = {
- { "inplace_begin", do_inplace_begin, 2, 2, awk_false, NULL },
- { "inplace_end", do_inplace_end, 2, 2, awk_false, NULL },
+ { "begin", do_inplace_begin, 2, 2, awk_false, NULL },
+ { "end", do_inplace_end, 2, 2, awk_false, NULL },
};
static awk_bool_t init_inplace(void)
@@ -276,4 +276,4 @@ static awk_bool_t (*init_func)(void) = init_inplace;
/* define the dl_load function using the boilerplate macro */
-dl_load_func(func_table, inplace, "")
+dl_load_func(func_table, inplace, "inplace")
diff --git a/extension/testext.c b/extension/testext.c
index 6629296a..b911ec93 100644
--- a/extension/testext.c
+++ b/extension/testext.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2012, 2013, 2014, 2015, 2018
+ * Copyright (C) 2012, 2013, 2014, 2015, 2017, 2018
* the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
@@ -1034,6 +1034,17 @@ static void at_exit2(void *data, int exit_status)
printf(" exit_status = %d\n", exit_status);
}
+/* do_test_function --- test function for test namespace */
+
+static awk_value_t *
+do_test_function(int nargs, awk_value_t *result, struct awk_ext_func *unused)
+{
+ printf("test::test_function() called.\n");
+ fflush(stdout);
+
+ return make_number(0.0, result);
+}
+
static awk_ext_func_t func_table[] = {
{ "dump_array_and_delete", dump_array_and_delete, 2, 2, awk_false, NULL },
{ "try_modify_environ", try_modify_environ, 0, 0, awk_false, NULL },
@@ -1051,6 +1062,10 @@ static awk_ext_func_t func_table[] = {
{ "get_file", do_get_file, 4, 4, awk_false, NULL },
};
+static awk_ext_func_t ns_test_func = {
+ "test_function", do_test_function, 0, 0, awk_false, NULL
+};
+
/* init_testext --- additional initialization function */
static awk_bool_t init_testext(void)
@@ -1058,6 +1073,7 @@ static awk_bool_t init_testext(void)
awk_value_t value;
static const char message[] = "hello, world"; /* of course */
static const char message2[] = "i am a scalar";
+ static const char message3[] = "in namespace test";
/* This is used by the getfile test */
if (sym_lookup("TESTEXT_QUIET", AWK_NUMBER, & value))
@@ -1075,6 +1091,9 @@ BEGIN {
for (i in new_array)
printf("new_array[\"%s\"] = \"%s\"\n", i, new_array[i])
print ""
+ printf("test::testval = %s\n", test::testval)
+ test::test_function()
+ print ""
}
*/
@@ -1092,6 +1111,13 @@ BEGIN {
create_new_array();
+ if (! sym_update_ns("test", "testval",
+ make_const_string(message3, strlen(message3), & value)))
+ printf("testext: sym_update_ns(\"test\", \"testval\") failed!\n");
+
+ if (! add_ext_func("test", & ns_test_func))
+ printf("testext: add_ext_func(\"test\", ns_test_func) failed!\n");
+
return awk_true;
}