From 12e246495c2f40ca289b27a552d548318f255472 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 3 Jun 2011 19:54:43 +0000 Subject: 29413: "print -S" for saving to history with lexical word split --- Src/builtin.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index fc98eb1b1..9b34ef7c0 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -99,7 +99,7 @@ static struct builtin builtins[] = #endif BUILTIN("popd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 1, BIN_POPD, "q", NULL), - BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "abcC:Df:ilmnNoOpPrRsu:z-", NULL), + BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "abcC:Df:ilmnNoOpPrRsSu:z-", NULL), BUILTIN("printf", 0, bin_print, 1, -1, BIN_PRINTF, NULL, NULL), BUILTIN("pushd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_PUSHD, "qsPL", NULL), BUILTIN("pushln", 0, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), @@ -3965,25 +3965,45 @@ bin_print(char *name, char **args, Options ops, int func) return 0; } /* -s option -- add the arguments to the history list */ - if (OPT_ISSET(ops,'s')) { + if (OPT_ISSET(ops,'s') || OPT_ISSET(ops,'S')) { int nwords = 0, nlen, iwords; char **pargs = args; queue_signals(); - ent = prepnexthistent(); while (*pargs++) nwords++; - if ((ent->nwords = nwords)) { - ent->words = (short *)zalloc(nwords*2*sizeof(short)); - nlen = iwords = 0; - for (pargs = args; *pargs; pargs++) { - ent->words[iwords++] = nlen; - nlen += strlen(*pargs); - ent->words[iwords++] = nlen; - nlen++; + if (nwords) { + if (OPT_ISSET(ops,'S')) { + int wordsize; + short *words; + if (nwords > 1) { + zwarnnam(name, "option -S takes a single argument"); + return 1; + } + words = NULL; + wordsize = 0; + histsplitwords(*args, &words, &wordsize, &nwords, 1); + ent = prepnexthistent(); + ent->words = (short *)zalloc(nwords*sizeof(short)); + memcpy(ent->words, words, nwords*sizeof(short)); + free(words); + ent->nwords = nwords/2; + } else { + ent = prepnexthistent(); + ent->words = (short *)zalloc(nwords*2*sizeof(short)); + ent->nwords = nwords; + nlen = iwords = 0; + for (pargs = args; *pargs; pargs++) { + ent->words[iwords++] = nlen; + nlen += strlen(*pargs); + ent->words[iwords++] = nlen; + nlen++; + } } - } else + } else { + ent = prepnexthistent(); ent->words = (short *)NULL; + } ent->node.nam = zjoin(args, ' ', 0); ent->stim = ent->ftim = time(NULL); ent->node.flags = 0; -- cgit v1.2.3 From af071465b1ef324f35741c681529f39b88a95f51 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 28 Aug 2011 17:06:27 +0000 Subject: 29731: fix read -AE, test that and read -Ae --- ChangeLog | 5 ++++- Src/builtin.c | 4 ++-- Test/B04read.ztst | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 58e06d4da..80de37809 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-08-28 Peter Stephenson + * 29731: Src/builtin.c, Test/B04read.ztst: fix output from `read + -AE' and test that and `read -Ae'. + * users/16289: Doc/Zsh/expn.yo, Src/exec.c, Src/jobs.c: don't delete temporary files when disowning and document this. @@ -15335,5 +15338,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5446 $ +* $Revision: 1.5447 $ ***************************************************** diff --git a/Src/builtin.c b/Src/builtin.c index 9b34ef7c0..175607644 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5549,7 +5549,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) *bptr = '\0'; #endif /* dispose of word appropriately */ - if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) { + if (OPT_ISSET(ops,'e')) { zputs(buf, stdout); putchar('\n'); } @@ -5581,7 +5581,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) : (char **)zalloc((al + 1) * sizeof(char *))); for (pp = p, n = firstnode(readll); n; incnode(n)) { - if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) { + if (OPT_ISSET(ops,'E')) { zputs((char *) getdata(n), stdout); putchar('\n'); } diff --git a/Test/B04read.ztst b/Test/B04read.ztst index ad427dc0d..25c3d4173 100644 --- a/Test/B04read.ztst +++ b/Test/B04read.ztst @@ -93,3 +93,20 @@ read foo) <<one +>two +>three +>one:two:three + + array=() + read -Ae array <<<'four five six' + print ${(j.:.)array} +0:Behaviour of -A and -e combination +>four +>five +>six +> -- cgit v1.2.3 From a6de37ec2bd96c8a5c81999c71a6303dbe5b39f6 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 29 Aug 2011 17:21:39 +0000 Subject: 29744: don't mess up non '-A' cases in read -E fix --- ChangeLog | 7 ++++++- Src/builtin.c | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') diff --git a/ChangeLog b/ChangeLog index 5c800d16b..aa410939e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-29 Peter Stephenson + + * 29744: Src/builtin.c: don't mess up non '-A' case in + 29731. + 2011-08-29 Barton E. Schaefer * users/16291: Functions/Prompts/prompt_bart_setup: revert to @@ -15349,5 +15354,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5449 $ +* $Revision: 1.5450 $ ***************************************************** diff --git a/Src/builtin.c b/Src/builtin.c index 175607644..71fc04ce1 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5549,7 +5549,14 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func)) *bptr = '\0'; #endif /* dispose of word appropriately */ - if (OPT_ISSET(ops,'e')) { + if (OPT_ISSET(ops,'e') || + /* + * When we're doing an array assignment, we'll + * handle echoing at that point. In all other + * cases (including -A with no assignment) + * we'll do it here. + */ + (OPT_ISSET(ops,'E') && !OPT_ISSET(ops,'A'))) { zputs(buf, stdout); putchar('\n'); } -- cgit v1.2.3