diff --git a/ncdump/CMakeLists.txt b/ncdump/CMakeLists.txt index 9fb5c09c03..62e313f0b2 100644 --- a/ncdump/CMakeLists.txt +++ b/ncdump/CMakeLists.txt @@ -3,7 +3,7 @@ # 2015, 2016, 2017, 2018 # University Corporation for Atmospheric Research/Unidata. -# See netcdf-c/COPYRIGHT file for more info. +# See netcdffff-c/COPYRIGHT file for more info. #IF(BUILD_SHARED_LIBS AND WIN32) # remove_definitions(-DDLL_EXPORT) # remove_definitions(-DDLL_NETCDF) @@ -23,7 +23,8 @@ set(printfqn_FILES printfqn.c ${XGETOPTSRC}) set(ncpathcvt_FILES ncpathcvt.c ${XGETOPTSRC}) set(ncfilteravail_FILES ncfilteravail.c ${XGETOPTSRC}) set(nchdf5version_FILES nchdf5version.c) - +set(echon_FILES echon.c ${XGETOPTSRC}) + ## # Turn off inclusion of particular files when using the cmake-native # option to turn on Unity Builds. @@ -42,6 +43,7 @@ add_executable(nccopy ${nccopy_FILES}) add_executable(ncvalidator ${ncvalidator_FILES}) add_executable(ncpathcvt ${ncpathcvt_FILES}) add_executable(ncfilteravail ${ncfilteravail_FILES}) +add_executable(echon ${echon_FILES}) if(USE_HDF5) add_executable(nc4print nc4print.c nc4printer.c) @@ -63,6 +65,7 @@ target_link_libraries(nccopy netcdf ${ALL_TLL_LIBS}) target_link_libraries(ncvalidator netcdf ${ALL_TLL_LIBS}) target_link_libraries(ncpathcvt netcdf ${ALL_TLL_LIBS}) target_link_libraries(ncfilteravail netcdf ${ALL_TLL_LIBS}) +#target_link_libraries(echon netcdf ${ALL_TLL_LIBS}) if(NETCDF_ENABLE_DAP) target_link_libraries(ocprint netcdf ${ALL_TLL_LIBS}) @@ -90,6 +93,7 @@ if(WIN32) setbinprops(ncvalidator) setbinprops(ncpathcvt) setbinprops(ncfilteravail) + setbinprops(echon) if(USE_HDF5) setbinprops(printfqn) diff --git a/ncdump/Makefile.am b/ncdump/Makefile.am index 0a68220d1a..14b36aca82 100644 --- a/ncdump/Makefile.am +++ b/ncdump/Makefile.am @@ -37,6 +37,10 @@ utils.h utils.c dimmap.h dimmap.c list.c list.h noinst_PROGRAMS += ncvalidator ncvalidator_SOURCES = ncvalidator.c +# An equivalent to echo that always implements -n flag +noinst_PROGRAMS += echon +echon_SOURCES = echon.c + # A non-installed utility program to convert paths; similar to cygpath noinst_PROGRAMS += ncpathcvt ncpathcvt_SOURCES = ncpathcvt.c diff --git a/ncdump/echon.c b/ncdump/echon.c new file mode 100644 index 0000000000..665229f96c --- /dev/null +++ b/ncdump/echon.c @@ -0,0 +1,94 @@ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#include +#endif + +#ifdef HAVE_GETOPT_H +#include +#endif + +#if defined(_WIN32) && ! defined(__MINGW32__) +#include "XGetopt.h" +#endif + +int +main(int argc, char** argv) +{ + int i; + int len; + char* result = NULL; + int noeol = 1; /* Default to -n vs -N */ + int escape = 1; /* Ditto */ + char* p = NULL; + char* q = NULL; + char c; + +#ifdef _WIN32 + _setmode(_fileno(stdout),_O_BINARY); +#endif + + opterr = 1; + while ((c = getopt(argc, argv,"enEN")) != EOF) { + switch(c) { + case 'e': escape = 1; break; + case 'n': noeol = 1; break; + case 'E': escape = 0; break; + case 'N': noeol = 0; break; + case '?': default: break; /* ignore */ + } + } + + /* leave non-flag args */ + argc -= optind; + argv += optind; + + /* Compute the max possible length of output */ + for(len=0,i=0;i 0) strcat(result," "); + strcat(result,argv[i]); + } + /* Optionally de-escape the result */ + if(escape) { + for(p=result,q=result;*p;) { + switch (*p) { + default: *q++ = *p; break; + case '\\': + p++; + switch(*p) { + case 'a': *q++ = '\a'; break; + case 'b': *q++ = '\b'; break; + case 'f': *q++ = '\f'; break; + case 'r': *q++ = '\r'; break; + case 'n': *q++ = '\n'; break; + case 't': *q++ = '\t'; break; + case 'v': *q++ = '\v'; break; + default: *q++ = *p; break; + } + break; + } + p++; + } + } else + *q++ = *p++; + if(!noeol) *p++ = '\n'; + *p = '\0'; + fputs(result,stdout); + fflush(stdout); + free(result); + return 0; +} diff --git a/test_common.in b/test_common.in index fb0c952c22..c6a1e9eec6 100644 --- a/test_common.in +++ b/test_common.in @@ -120,7 +120,6 @@ if test "x$SETX" = x1 ; then set -x ; fi system=`uname` if test "x${system##MINGW*}" = x; then alias pwd='pwd -W' - fi # We assume that TOPSRCDIR and TOPBUILDDIR are defined @@ -198,32 +197,18 @@ fi fi # OS/X and windows apparently have no echo -n option, so fake it -echo "@@@FP_ISMSVC=${FP_ISMSVC}" -echo "@@@FP_ISOSX=${FP_ISOSX}" -if test "x${FP_ISMSVC}" = xyes || test "x${FP_ISOSX}" = xyes ; then -#echon() { echo "$@" | tr -d '\r\n' ; } -echo "@@@case true" -echon() { -echo "$@" | tr -d '\r\n' -} -else -echo "@@@case false" -#alias echon='echo -n' echon() { -echo -n "$@" + ${abs_top_builddir}/ncdump/echon -n $@ } -fi -declare -f echon + # Test for filter availability avail() { if test yes = `${execdir}/../ncdump/ncfilteravail $1` ; then return 0 ; else echo "filter $1 not available" ; return 1; fi } - # Make sure we are in builddir (not execdir) cd $builddir - # Parallel make can cause inter-test interference (mostly because of historical naming issues). # As a protection against this, the isolate() function supports the creation of an # isolation directory in which created products are stored. diff --git a/unit_test/run_pluginpaths.sh b/unit_test/run_pluginpaths.sh index 74e4dae495..38620f71f2 100755 --- a/unit_test/run_pluginpaths.sh +++ b/unit_test/run_pluginpaths.sh @@ -3,12 +3,12 @@ # Test the programmatic API for manipulating the plugin paths. # This script is still full of cruft that needs to be removed -export SETX=1 -set -x - if test "x$srcdir" = x ; then srcdir=`pwd`; fi . ../test_common.sh +set -x +set -e + IMPLS= if test "x$FEATURE_HDF5" = xyes ; then IMPLS="$IMPLS hdf5"; fi if test "x$FEATURE_NCZARR" = xyes ; then IMPLS="$IMPLS nczarr"; fi @@ -18,11 +18,10 @@ echo "IMPLS=|$IMPLS|" #VERBOSE=1 -# Watch out because bash will convert '/' to '\\' on windows -DFALT="\/zero;\/one;\/two;\/three;\/four" -DFALTSET="\/zero;\/one;\/mod;\/two;\/three;\/four" -DFALTHDF5="\/zero;\/one;\/two;\/hdf5;\/three;\/four" -DFALTNCZARR="\/zero;\/one;\/two;\/nczarr;three;\/four;\/five" +DFALT="/zero;/one;/two;/three;/four" +DFALTSET="/zero;/one;/mod;/two;/three;/four" +DFALTHDF5="/zero;/one;/two;/hdf5;/three;/four" +DFALTNCZARR="/zero;/one;/two;/nczarr;three;/four;/five" if test "x$TESTNCZARR" = x1 ; then . "$srcdir/test_nczarr.sh" @@ -50,8 +49,8 @@ modfor() { local formatx="$1" local dfalt="$2" case "$formatx" in - hdf5) mod="${dfalt};\/modhdf5" ;; - nczarr) mod="\/modnczarr;${dfalt}" ;; + hdf5) mod="${dfalt};/modhdf5" ;; + nczarr) mod="/modnczarr;${dfalt}" ;; all) mode="${dfalt}" ;; esac } @@ -62,46 +61,35 @@ modfor() { # It is difficult to test for outside interference, so not attempted. testget() { filenamefor tmp get - # Accumulate the output to avoid use of echo - TMPGET= # print out the global state - TMPGET="testget(global): " - TMP=`${TP} -x "set:${DFALT},get:global"` - TMPGET="${TMPGET}${TMP}" + echon "testget(global): " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:global" >> ${filename}.txt ; # print out the HDF5 state - TMPGET="${TMPGET}testget(hdf5): " - TMP=`${TP} -x "set:${DFALT},get:hdf5"` + echon "testget(hdf5): " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:hdf5" >> ${filename}.txt ; # print out the NCZarr state - TMPGET="${TMPGET}testget(nczarr): " - TMP=`${TP} -x "set:${DFALT},get:nczarr"` - TMPGET="${TMPGET}${TMP}" - echo "$TMPGET" | tr -d '\r' | cat >> ${filename}.txt -} + echon "testget(nczarr): " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:nczarr" >> ${filename}.txt ; +} # Set the global state to some value and verify that it was sync'd to hdf5 and nczarr testset() { filenamefor tmp set # print out the global state, modify it and print again - TMPSET= - TMPSET="testset(global): before: " - TMP=`${TP} -x "set:${DFALT},get:global"` - TMPSET="${TMPSET}testset(global): after: " - TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:global"` - TMPSET="${TMPSET}${TMP}" + echon "testset(global): before: " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:global" >> ${filename}.txt ; + echon "testset(global): after: " >> ${filename}.txt + ${TP} -x "set:${DFALT},set:${DFALTSET},get:global" >> ${filename}.txt ; # print out the HDF5 state - TMPSET="${TMPSET}testset(hdf5): before: " - TMP=`${TP} -x "set:${DFALT},get:hdf5"` - TMPSET="${TMPSET}${TMP}" - TMPSET="${TMPSET}testset(hdf5): after: " - TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:hdf5"` - TMPSET="${TMPSET}${TMP}" + echon "testset(hdf5): before: " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:hdf5" >> ${filename}.txt ; + echon "testset(hdf5): after: " >> ${filename}.txt + ${TP} -x "set:${DFALT},set:${DFALTSET},get:hdf5" >> ${filename}.txt ; # print out the NCZarr state - TMPSET="${TMPSET}testset(nczarr): before: " - TMP=`${TP} -x "set:${DFALT},get:nczarr"` - TMPSET="${TMPSET}testset(nczarr): after: " - TMP=`${TP} -x "set:${DFALT},set:${DFALTSET},get:nczarr"` - TMPSET="${TMPSET}${TMP}" - echo "$TMPGET" | tr -d '\r' | cat >> ${filename}.txt + echon "testset(nczarr): before: " >> ${filename}.txt + ${TP} -x "set:${DFALT},get:nczarr" >> ${filename}.txt ; + echon "testset(nczarr): after: " >> ${filename}.txt + ${TP} -x "set:${DFALT},set:${DFALTSET},get:nczarr" >> ${filename}.txt ; } ######################### @@ -116,8 +104,7 @@ init() { # Verify output for a specific action verify() { -# for action in get set ; do -for action in get ; do + for action in get set ; do if diff -wBb ${srcdir}/ref_${action}.txt tmp_${action}.txt ; then echo "***PASS: $action" else