diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 10 | ||||
-rw-r--r-- | test/Makefile.in | 10 | ||||
-rw-r--r-- | test/fts.awk | 121 |
4 files changed, 142 insertions, 4 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index c012513a..2b1ac648 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2012-08-08 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (fts): New test. + * fts.awk: New file. + 2012-07-30 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (assignconst): Use AWKPATH to get results that will diff --git a/test/Makefile.am b/test/Makefile.am index 270cc2fc..3a8e48ca 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -275,6 +275,7 @@ EXTRA_DIST = \ fstabplus.awk \ fstabplus.in \ fstabplus.ok \ + fts.awk \ funlen.awk \ funlen.in \ funlen.ok \ @@ -895,7 +896,7 @@ LOCALE_CHARSET_TESTS = \ mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc SHLIB_TESTS = \ - assignconst fnmatch filefuncs fork fork2 ordchr ordchr2 \ + assignconst fnmatch filefuncs fork fork2 fts ordchr ordchr2 \ readdir readfile rwarray testext time # List of the tests which should be run with --lint option: @@ -1612,6 +1613,11 @@ readdir: @$(AWK) -f $(srcdir)/readdir.awk . > $@.out2 @-$(CMP) $@.out1 $@.out2 && rm -f $@.out[12] +fts: + @echo $@ + @$(AWK) -f $(srcdir)/fts.awk + @-$(CMP) $@.out1 $@.out2 && rm -f $@.out[12] + # Targets generated for other tests: include Maketests @@ -1620,7 +1626,7 @@ $(srcdir)/Maketests: $(srcdir)/Makefile.am $(srcdir)/Gentests $(AWK) -f $(srcdir)/Gentests "$(srcdir)/Makefile.am" $$files > $(srcdir)/Maketests clean: - rm -fr _* core core.* fmtspcl.ok junk out1 out2 out3 strftime.ok test1 test2 seq *~ readfile.ok fork.tmp.* testext.awk + rm -fr _* core core.* fmtspcl.ok junk out1 out2 out3 strftime.ok test1 test2 seq *~ readfile.ok fork.tmp.* testext.awk fts.out1 fts.out2 # An attempt to print something that can be grepped for in build logs pass-fail: diff --git a/test/Makefile.in b/test/Makefile.in index 4b6d5439..0ba7c5c5 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -488,6 +488,7 @@ EXTRA_DIST = \ fstabplus.awk \ fstabplus.in \ fstabplus.ok \ + fts.awk \ funlen.awk \ funlen.in \ funlen.ok \ @@ -1104,7 +1105,7 @@ LOCALE_CHARSET_TESTS = \ mbprintf1 mbprintf2 mbprintf3 rebt8b2 rtlenmb sort1 sprintfc SHLIB_TESTS = \ - assignconst fnmatch filefuncs fork fork2 ordchr ordchr2 \ + assignconst fnmatch filefuncs fork fork2 fts ordchr ordchr2 \ readdir readfile rwarray testext time @@ -1994,6 +1995,11 @@ readdir: @ls -fli | sed 1d | $(AWK) -f $(srcdir)/readdir0.awk > $@.out1 @$(AWK) -f $(srcdir)/readdir.awk . > $@.out2 @-$(CMP) $@.out1 $@.out2 && rm -f $@.out[12] + +fts: + @echo $@ + @$(AWK) -f $(srcdir)/fts.awk + @-$(CMP) $@.out1 $@.out2 && rm -f $@.out[12] Gt-dummy: # file Maketests, generated from Makefile.am by the Gentests program addcomma: @@ -3239,7 +3245,7 @@ $(srcdir)/Maketests: $(srcdir)/Makefile.am $(srcdir)/Gentests $(AWK) -f $(srcdir)/Gentests "$(srcdir)/Makefile.am" $$files > $(srcdir)/Maketests clean: - rm -fr _* core core.* fmtspcl.ok junk out1 out2 out3 strftime.ok test1 test2 seq *~ readfile.ok fork.tmp.* testext.awk + rm -fr _* core core.* fmtspcl.ok junk out1 out2 out3 strftime.ok test1 test2 seq *~ readfile.ok fork.tmp.* testext.awk fts.out1 fts.out2 # An attempt to print something that can be grepped for in build logs pass-fail: diff --git a/test/fts.awk b/test/fts.awk new file mode 100644 index 00000000..b90adfb5 --- /dev/null +++ b/test/fts.awk @@ -0,0 +1,121 @@ +@load "filefuncs" + +BEGIN { + Level = 0 + + system("rm -fr d1 d2") + system("mkdir d1 d2 ; touch d1/f1 d1/f2 d2/f1 d2/f2") + pathlist[1] = "d1" + pathlist[2] = "d2" + flags = FTS_PHYSICAL + fts(pathlist, flags, data) + + output = "fts.out1" + traverse(data) + close(output) + + ftswalk(pathlist, data2) + output = "fts.out2" + traverse(data2) + close(output) + + system("rm -fr d1 d2") +} + +function indent( i) +{ + for (i = 1; i <= Level; i++) + printf("\t") > output +} + +function sort_traverse(data, sorted, i) +{ + asorti(data, sorted) + for (i = 1; i in sorted; i++) { + indent() + printf("%s --> %s\n", sorted[i], data[sorted[i]]) > output + } +} + +function traverse(data, i) +{ + for (i in data) { + if (isarray(data[i])) { + indent() + printf("%s:\n", i) > output + + Level++ + if (("mtime" in data[i]) && ! isarray(data[i][mtime])) { + sort_traverse(data[i]) + } else { + traverse(data[i]) + } + Level-- + } else { + indent() + printf("%s --> %s\n", i, data[i]) > output + } + } +} + + +function ftswalk(pathlist, data, i, toppath) +{ + delete data + for (i = 1; i in pathlist; i++) { + toppath = pathlist[i] + data[toppath]["junk"]++ # create array + delete data[toppath]["junk"] + process(pathlist[i], data) + } +} + +# enter process with pathname, array for that path already created but +# empty + +function process(pathname, data_array, + stat_data, i, direntry, command, shortname) # locals +{ + stat(pathname, stat_data) + if (stat_data["type"] == "file") { + shortname = strrstr(pathname, "/") + data_array["path"] = pathname + for (i in stat_data) { + if (i == "name") + data_array["stat"][i] = shortname + else + data_array["stat"][i] = stat_data[i] + } + + return + } + + # stuff for a directory + + data_array[pathname]["."]["path"] = pathname + for (i in stat_data) + data_array[pathname]["."]["stat"][i] = stat_data[i] + + command = ("ls -f " pathname) + while ((command | getline direntry) > 0) { + if (direntry == "." || direntry == "..") + continue + data_array[pathname][direntry]["junk"]++ + delete data_array[pathname][direntry]["junk"] + process(pathname "/" direntry, + data_array[pathname][direntry]) + } + close(command) +} + +function strrstr(string, delim, ind) +{ + if ((ind = index(string, delim)) == 0) + return string + + do { + string = substr(string, ind + 1) + } while ((ind = index(string, delim)) > 0) + + return string +} |