aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/ChangeLog11
-rw-r--r--extension/filefuncs.3am7
-rw-r--r--extension/filefuncs.c12
3 files changed, 27 insertions, 3 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 69127623..a1ad5efa 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,
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)