From 86f8e8de696404b85c334916bfe3d69bdd4291c6 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 5 Mar 2012 10:06:28 +0000 Subject: 30307 plus tweak suggsted by Wayne: use %lld for zlong when long long --- Src/utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Src/utils.c') diff --git a/Src/utils.c b/Src/utils.c index 014cb2fa2..f07d8cc31 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -275,9 +275,13 @@ zerrmsg(FILE *file, const char *fmt, va_list ap) #endif char *errmsg; - if ((unset(SHINSTDIN) || locallevel) && lineno) + if ((unset(SHINSTDIN) || locallevel) && lineno) { +#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD) + fprintf(file, "%lld: ", lineno); +#else fprintf(file, "%ld: ", (long)lineno); - else +#endif + } else fputc((unsigned char)' ', file); while (*fmt) -- cgit v1.2.3 From a76c8de44c8c1f47f4db4cef0e9b1ce2f8c52a31 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 13 Mar 2012 09:47:01 +0000 Subject: 30351 + 30352: metafy strings on import into zsh variables --- ChangeLog | 8 +++++++- Src/params.c | 34 ++++++++++++++++++---------------- Src/utils.c | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 17 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index f40bdee55..e1e163fdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-03-13 Peter Stephenson + + * 30351 changed as in 30352: Src/params.c, Src/utils.c: metafy + scalar and array parameter values as they are imported from + strings defined outside zsh. + 2012-03-07 Peter Stephenson * users/16865: Doc/Zsh/cond.yo: note that -eq and friends are @@ -16094,5 +16100,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5607 $ +* $Revision: 1.5608 $ ***************************************************** diff --git a/Src/params.c b/Src/params.c index 59d5daf2f..8a0ed5143 100644 --- a/Src/params.c +++ b/Src/params.c @@ -698,16 +698,18 @@ createparamtable(void) * So allow the user to set it in the special cases where it's * useful. */ - setsparam("TMPPREFIX", ztrdup(DEFAULT_TMPPREFIX)); - setsparam("TIMEFMT", ztrdup(DEFAULT_TIMEFMT)); - setsparam("WATCHFMT", ztrdup(default_watchfmt)); + setsparam("TMPPREFIX", ztrdup_metafy(DEFAULT_TMPPREFIX)); + setsparam("TIMEFMT", ztrdup_metafy(DEFAULT_TIMEFMT)); + setsparam("WATCHFMT", ztrdup_metafy(default_watchfmt)); hostnam = (char *)zalloc(256); gethostname(hostnam, 256); - setsparam("HOST", ztrdup(hostnam)); + setsparam("HOST", ztrdup_metafy(hostnam)); zfree(hostnam, 256); - setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username)); + setsparam("LOGNAME", + ztrdup_metafy((str = getlogin()) && *str ? + str : cached_username)); #if !defined(HAVE_PUTENV) && !defined(USE_SET_UNSET_ENV) /* Copy the environment variables we are inheriting to dynamic * @@ -778,22 +780,22 @@ createparamtable(void) if(uname(&unamebuf)) setsparam("CPUTYPE", ztrdup("unknown")); else { - machinebuf = ztrdup(unamebuf.machine); + machinebuf = ztrdup_metafy(unamebuf.machine); setsparam("CPUTYPE", machinebuf); } - + #else - setsparam("CPUTYPE", ztrdup("unknown")); + setsparam("CPUTYPE", ztrdup_metafy("unknown")); #endif - setsparam("MACHTYPE", ztrdup(MACHTYPE)); - setsparam("OSTYPE", ztrdup(OSTYPE)); - setsparam("TTY", ztrdup(ttystrname)); - setsparam("VENDOR", ztrdup(VENDOR)); - setsparam("ZSH_NAME", ztrdup(zsh_name)); - setsparam("ZSH_VERSION", ztrdup(ZSH_VERSION)); - setsparam("ZSH_PATCHLEVEL", ztrdup(ZSH_PATCHLEVEL)); + setsparam("MACHTYPE", ztrdup_metafy(MACHTYPE)); + setsparam("OSTYPE", ztrdup_metafy(OSTYPE)); + setsparam("TTY", ztrdup_metafy(ttystrname)); + setsparam("VENDOR", ztrdup_metafy(VENDOR)); + setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); + setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); + setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *))); - for (t = sigs; (*sigptr++ = ztrdup(*t++)); ); + for (t = sigs; (*sigptr++ = ztrdup_metafy(*t++)); ); noerrs = 0; } diff --git a/Src/utils.c b/Src/utils.c index f07d8cc31..a9b5c2c58 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4012,6 +4012,28 @@ metafy(char *buf, int len, int heap) } +/* + * Duplicate a string, metafying it as we go. + * + * Typically, this is used only for strings imported from outside + * zsh, as strings internally are either already metafied or passed + * around with an associated length. + */ +/**/ +mod_export char * +ztrdup_metafy(const char *s) +{ + /* To mimic ztrdup() behaviour */ + if (!s) + return NULL; + /* + * metafy() does lots of different things, so the pointer + * isn't const. Using it with META_DUP should be safe. + */ + return metafy((char *)s, -1, META_DUP); +} + + /* * Take a null-terminated, metafied string in s into a literal * representation by converting in place. The length is in *len -- cgit v1.2.3 From 4f142f279468a2d2d2500555e00649db9e74836f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 16 Apr 2012 11:26:09 +0000 Subject: 30413: (q-) parameter flag should quote null string (q-q) etc. should be treated as errors --- ChangeLog | 8 +++++++- Src/subst.c | 4 ++++ Src/utils.c | 19 +++++++++---------- Test/D04parameter.ztst | 7 +++++++ 4 files changed, 27 insertions(+), 11 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 188a42cca..23fd23f31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-04-16 Peter Stephenson + + * 30413: Src/params.c, Src/utils.c, Test/D04parameter.ztst: + (q-) parameter flag should quote the empty string and should + report an error with extra trailing q's. + 2012-04-15 Peter Stephenson * unposted: NEWS: incorporate the remainder of Bart's @@ -16202,5 +16208,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5631 $ +* $Revision: 1.5632 $ ***************************************************** diff --git a/Src/subst.c b/Src/subst.c index 04ef1a4fb..dac536f14 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -1828,6 +1828,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) quotemod = 1; quotetype = QT_SINGLE_OPTIONAL; } else { + if (quotetype == QT_SINGLE_OPTIONAL) { + /* extra q's after '-' not allowed */ + goto flagerr; + } quotemod++, quotetype++; } break; diff --git a/Src/utils.c b/Src/utils.c index a9b5c2c58..fb65ba815 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4735,7 +4735,7 @@ quotestring(const char *s, char **e, int instring) char *v; int alloclen; char *buf; - int sf = 0, shownull; + int sf = 0, shownull = 0; /* * quotesub is used with QT_SINGLE_OPTIONAL. * quotesub = 0: mechanism not active @@ -4750,14 +4750,12 @@ quotestring(const char *s, char **e, int instring) const char *uend; slen = strlen(s); - if (instring == QT_BACKSLASH_SHOWNULL) { - shownull = 1; - instring = QT_BACKSLASH; - } else { - shownull = 0; - } switch (instring) { + case QT_BACKSLASH_SHOWNULL: + shownull = 1; + instring = QT_BACKSLASH; + /*FALLTHROUGH*/ case QT_BACKSLASH: /* * With QT_BACKSLASH we may need to use $'\300' stuff. @@ -4765,22 +4763,23 @@ quotestring(const char *s, char **e, int instring) * storage and using heap for correct size at end. */ alloclen = slen * 7 + 1; - if (!*s && shownull) - alloclen += 2; /* for '' */ break; case QT_SINGLE_OPTIONAL: /* * Here, we may need to add single quotes. + * Always show empty strings. */ alloclen = slen * 4 + 3; - quotesub = 1; + quotesub = shownull = 1; break; default: alloclen = slen * 4 + 1; break; } + if (!*s && shownull) + alloclen += 2; /* for '' */ quotestart = v = buf = zshcalloc(alloclen); diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index cc2d6aecd..30e4ba0ab 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -385,6 +385,13 @@ >$'playing \'stupid\' "games" \\w\\i\\t\\h $quoting.' >'playing '\'stupid\'' "games" \w\i\t\h $quoting.' + x=( a '' '\b' 'c d' '$e' ) + print -r ${(q)x} + print -r ${(q-)x} +0:Another ${(q...)...} test +>a '' \\b c\ d \$e +>a '' '\b' 'c d' '$e' + print -r -- ${(q-):-foo} print -r -- ${(q-):-foo bar} print -r -- ${(q-):-"*(.)"} -- cgit v1.2.3 From cd1b5d86e0a6ac37e982c6a3b8725fd11076f14c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 1 May 2012 19:43:44 +0000 Subject: users/17046: don't count too many elements when splitting quoted parameter substitution on null parameter --- ChangeLog | 8 +++++++- Src/utils.c | 2 +- Test/D04parameter.ztst | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 2cefa9894..23713f54f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-05-01 Peter Stephenson + + * users/17046: Src/utils.c, Test/D04parameter.ztst: don't + count too many elements when splitting quoted parameter + substitution on null separator. + 2012-05-01 Mikael Magnusson * 30456: Completion/Unix/Command/_getconf: Use new array syntax. @@ -16254,5 +16260,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5644 $ +* $Revision: 1.5645 $ ***************************************************** diff --git a/Src/utils.c b/Src/utils.c index fb65ba815..9603389cc 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3114,7 +3114,7 @@ wordcount(char *s, char *sep, int mul) r = 1; sl = strlen(sep); for (; (c = findsep(&s, sep, 0)) >= 0; s += sl) - if ((c && *(s + sl)) || mul) + if ((c || mul) && (sl || *(s + sl))) r++; } else { char *t = s; diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index cdeb15bfd..01f841218 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1292,7 +1292,7 @@ >in >it - foo="line:with::missing::fields:in:it" + foo="line:with::missing::fields:in:it:" print -l "${(@s.:.)foo}" 0:Retention of empty fields in quoted splitting with "@" >line @@ -1303,6 +1303,20 @@ >fields >in >it +> + + str=abcd + print -l ${(s..)str} + print -l "${(s..)str}" +0:splitting of strings into characters +>a +>b +>c +>d +>a +>b +>c +>d array=('%' '$' 'j' '*' '$foo') print ${array[(i)*]} "${array[(i)*]}" -- cgit v1.2.3 From 9af1cd47229041fda4dc07f0ef70691a64d49908 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Wed, 27 Jun 2012 07:10:29 +0000 Subject: 30530,30533: fix problems with COLUMNS or LINES < 1, and related issues --- ChangeLog | 15 ++++++++++++++- Src/params.c | 2 +- Src/utils.c | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'Src/utils.c') diff --git a/ChangeLog b/ChangeLog index 2eb8fdf04..78f294a6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-06-26 Barton E. Schaefer + + * 30533: Src/utils.c: when processing a change in the value of + COLUMNS, do not assert the change into the tty driver winsize. + The code for this was dead the whole time IPDEF5 was broken and + this seems a bad time to make it live; besides which it is not + consistent about the handling of LINES (which is ignored when + changed by itself, but would be asserted when COLUMNS changes). + + * 30530: Src/params.c: fix long-broken IPDEF5 definition to use + the GSU struct, thus fixing problems with values of LINES or + COLUMNS less than 1. + 2012-06-21 Peter Stephenson * Danek (plus .distfiles changes): 30520: @@ -16411,5 +16424,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5674 $ +* $Revision: 1.5675 $ ***************************************************** diff --git a/Src/params.c b/Src/params.c index 966e3afcc..8649178ef 100644 --- a/Src/params.c +++ b/Src/params.c @@ -315,7 +315,7 @@ IPDEF4("LINENO", &lineno), IPDEF4("PPID", &ppid), IPDEF4("ZSH_SUBSHELL", &zsh_subshell), -#define IPDEF5(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL},BR((void *)B),GSU(varinteger_gsu),10,0,NULL,NULL,NULL,0} +#define IPDEF5(A,B,F) {{NULL,A,PM_INTEGER|PM_SPECIAL},BR((void *)B),GSU(F),10,0,NULL,NULL,NULL,0} IPDEF5("COLUMNS", &zterm_columns, zlevar_gsu), IPDEF5("LINES", &zterm_lines, zlevar_gsu), IPDEF5("OPTIND", &zoptind, varinteger_gsu), diff --git a/Src/utils.c b/Src/utils.c index 9603389cc..d35ca1dfd 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1686,7 +1686,7 @@ adjustwinsize(int from) (shttyinfo.winsize.ws_row != ttyrows || shttyinfo.winsize.ws_col != ttycols)) { /* shttyinfo.winsize is already set up correctly */ - ioctl(SHTTY, TIOCSWINSZ, (char *)&shttyinfo.winsize); + /* ioctl(SHTTY, TIOCSWINSZ, (char *)&shttyinfo.winsize); */ } #endif /* TIOCGWINSZ */ -- cgit v1.2.3