diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-11-10 10:41:12 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-11-10 10:42:12 +0200 |
commit | 3299cf1ccb1c596969fcfd91253e10d5482eacf9 (patch) | |
tree | 871608720ac6050713cb2fecf5d3dcfd86aee938 /tests | |
parent | b1258b6d6e9e0482b37e86977ffc779e14c75b9f (diff) | |
download | grecs-3299cf1ccb1c596969fcfd91253e10d5482eacf9.tar.gz grecs-3299cf1ccb1c596969fcfd91253e10d5482eacf9.tar.bz2 |
Pull fixes to wordsplit from mailutils
This includes the following commits pushed between
2015-09-19 and 2017-10-10:
090c7b9a Allow ws_getvar to set value to NULL and
return MU_WRDSE_OK.
The value is processed as if it were "", i.e.
MU_WRDSE_UNDEF is returned.
64313fdf Fix MU_WRDSF_INCREMENTAL | MU_WRDSF_NOSPLIT
46d7640f Add wordsplit_append function
151eb4b9 Fix nested expansions and command expansions
occurring after variable expansions.
ad3cc340 Replace void wordsplit_getwords with
int wordsplit_get_words.
* include/wordsplit.h (wordsplit_get_words): New function.
(wordsplit_getwords): Mark as deprecated.
(wordsplit_append): New function.
* src/wordsplit.c (wordsplit_append): New function. MU 46d7640f.
(expvar): Treat NULL value as "". MU 090c7b9a.
(expcmd): Allow command and variable expansions in subsplit.
(exptab): Change ordering of expansions so that command expansion
occurs first. This fixes nested expansions and command expansions
occurring after variable expansions. MU 151eb4b9.
(wordsplit_process_list): Update wsp->ws_endp in nosplit mode. This
fixes wordsplit MU_WRDSF_INCREMENTAL | MU_WRDSF_NOSPLIT. MU 64313fdf.
(wordsplit_get_words): New function. MU ad3cc340.
* tests/wordsplit.at: Test the above changes.
* tests/wsp.c: Accept extra arguments to append using wordsplit_append.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wordsplit.at | 69 | ||||
-rw-r--r-- | tests/wsp.c | 21 |
2 files changed, 82 insertions, 8 deletions
diff --git a/tests/wordsplit.at b/tests/wordsplit.at index 895a392..49d47e9 100644 --- a/tests/wordsplit.at +++ b/tests/wordsplit.at @@ -637,6 +637,14 @@ NF: 1 [input exhausted ]) +TESTWSP([incremental nosplit],[],[incremental nosplit], +[incremental "input test" line +], +[NF: 1 +0: "incremental \"input test\" line" +], +[input exhausted +]) dnl Something that doesn't fit into TESTWSP @@ -717,15 +725,16 @@ mkdir dir > dir/file DIR=dir wsp -nocmd -novar<<'EOT' -begin $(find $DIR) end +begin $DIR $(find $DIR) end EOT ], [0], -[NF: 4 +[NF: 5 0: begin 1: dir -2: dir/file -3: end +2: dir +3: dir/file +4: end ]) AT_CLEANUP @@ -735,8 +744,8 @@ AT_CHECK([ mkdir dir > dir/file -DIR=dir wsp -nocmd -novar<<'EOT' -"begin($(find $DIR))end" +DIR=dir BEGIN=begin wsp -nocmd -novar<<'EOT' +"${BEGIN}($(find $DIR))end" EOT ], [0], @@ -744,7 +753,27 @@ EOT 0: "begin(dir dir/file)end" ]) AT_CLEANUP - + +AT_SETUP([nested commands]) +AT_KEYWORDS([wordsplit wsp wsp-cmd]) +AT_CHECK([ +AT_DATA([input],[foo +bar +baz +]) +SUFFIX=put wsp -nocmd -novar <<'EOT' +$(echo output $(cat in$SUFFIX)) +EOT +], +[0], +[NF: 4 +0: output +1: foo +2: bar +3: baz +]) +AT_CLEANUP + AT_SETUP([pathname expansion]) AT_KEYWORDS([wordsplit wsp wsp-path wsp-path-1]) AT_CHECK([ @@ -820,6 +849,32 @@ EOT ]) AT_CLEANUP +TESTWSP([append],[],[-- extra arguments follow], +[some words and], +[NF: 6 +0: some +1: words +2: and +3: extra +4: arguments +5: follow +]) + +TESTWSP([append + dooffs + env],[], +[dooffs 2 preface words V=2 -- extra arguments follow], +[some words and var=$V], +[NF: 7 (2) +(0): preface +(1): words +2: some +3: words +4: and +5: var=2 +6: extra +7: arguments +8: follow +]) + m4_popdef([TESTWSP]) m4_popdef([wspnum]) m4_popdef([wspid]) diff --git a/tests/wsp.c b/tests/wsp.c index e8eb9c6..84efc13 100644 --- a/tests/wsp.c +++ b/tests/wsp.c @@ -91,7 +91,7 @@ help () { size_t i; - printf ("usage: %s [options] [VAR=VALUE...]\n", progname); + printf ("usage: %s [options] [VAR=VALUE...] [-- EXTRA...]\n", progname); printf ("options are:\n"); printf (" [-]trimnl\n"); printf (" [-]plaintext\n"); @@ -334,6 +334,8 @@ main (int argc, char **argv) size_t fenvidx = 0; size_t fenvmax = sizeof (fenvbase) / sizeof (fenvbase[0]); int use_env = env_sys; + int appendc = 0; + char **appendv = NULL; progname = argv[0]; @@ -346,6 +348,12 @@ main (int argc, char **argv) if (opt[0] == '-') { + if (opt[1] == '-' && opt[2] == 0) + { + appendc = argc - i - 1; + appendv = argv + i + 1; + break; + } negate = 1; opt++; } @@ -604,6 +612,17 @@ main (int argc, char **argv) offarg = 0; } + if (appendc) + { + rc = wordsplit_append (&ws, appendc, appendv); + if (rc) + { + if (!(wsflags & WRDSF_SHOWERR)) + wordsplit_perror (&ws); + continue; + } + } + wsflags |= WRDSF_REUSE | (ws.ws_flags & WRDSF_ENV); printf ("NF: %lu", (unsigned long) ws.ws_wordc); if (wsflags & WRDSF_DOOFFS) |