From 8e0253af022abe9f9225352aae1088d6621a81ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Dec 2019 18:25:08 +0000 Subject: 45138: Add zformat unit tests. --- Src/Modules/zutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 24659cb16..de5fe8034 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -913,13 +913,13 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) switch (opt) { case 'f': { - char **ap, *specs[256], *out; + char **ap, *specs[256] = {0}, *out; int olen, oused = 0; - memset(specs, 0, 256 * sizeof(char *)); - specs['%'] = "%"; specs[')'] = ")"; + + /* Parse the specs in argv. */ for (ap = args + 2; *ap; ap++) { if (!ap[0][0] || ap[0][0] == '-' || ap[0][0] == '.' || idigit(ap[0][0]) || ap[0][1] != ':') { -- cgit v1.2.3 From 525faae5498adb4b4f1c0f4657b9ef71fc31c4d6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Dec 2019 18:25:09 +0000 Subject: 45137: zformat: Allow the specifying minimum width and a dot with an empty maximum width. Before this commit, format specs such as '%5.s' would be printed literally. Now, they are treated as equivalent to '%5s'. The '.' character is not allowed to be used in specs, so there is no incompatibility. --- ChangeLog | 4 ++++ Src/Modules/zutil.c | 3 +-- Test/V13zformat.ztst | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index fe3b6951c..321216c7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-12-26 Daniel Shahaf + * 45137: Src/Modules/zutil.c, Test/V13zformat.ztst: zformat: + Allow the specifying minimum width and a dot with an empty + maximum width. + * 45138: Src/Modules/zutil.c, Test/V13zformat.ztst: Add zformat unit tests. diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index de5fe8034..7d9bf05d6 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -797,8 +797,7 @@ static char *zformat_substring(char* instr, char **specs, char **outp, if ((*s == '.' || testit) && idigit(s[1])) { for (max = 0, s++; idigit(*s); s++) max = (max * 10) + (int) STOUC(*s) - '0'; - } - else if (testit) + } else if (*s == '.' || testit) s++; if (testit && STOUC(*s)) { diff --git a/Test/V13zformat.ztst b/Test/V13zformat.ztst index d8de2bb04..982866e13 100644 --- a/Test/V13zformat.ztst +++ b/Test/V13zformat.ztst @@ -17,12 +17,14 @@ zformat_and_print_s '%s' foo zformat_and_print_s '%5s' min zformat_and_print_s '%-5s' neg + zformat_and_print_s '%5.s' empty zformat_and_print_s '%.5s' max zformat_and_print_s '%.5s' truncated 0:basic zformat test >'foo' >'min ' >' neg' +>'empty' >'max' >'trunc' -- cgit v1.2.3 From 34d69acbef44f654ea51d762ffdb02f5b1e8b9e1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 29 Apr 2020 00:30:17 +0000 Subject: 45737 (+ docs, and update the test from 45722): zstyle: When determining the weight (specificity) of a pattern, consider the number of components before anything else, as documented. --- ChangeLog | 6 ++++++ Doc/Zsh/mod_zutil.yo | 6 +++--- README | 19 +++++++++++++++++++ Src/Modules/zutil.c | 13 +++++++++++-- Test/V05styles.ztst | 2 +- 5 files changed, 40 insertions(+), 6 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index ec1e413c7..1fd8b9944 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-05-02 Daniel Shahaf + * 45737 (+ docs, and update the test from 45722): + Doc/Zsh/mod_zutil.yo, README, Src/Modules/zutil.c, + Test/V05styles.ztst: zstyle: When determining the weight + (specificity) of a pattern, consider the number of components + before anything else, as documented. + * unposted: Test/V05styles.ztst: Revert unintentional move from 45722. diff --git a/Doc/Zsh/mod_zutil.yo b/Doc/Zsh/mod_zutil.yo index c69233f9d..9c50e6122 100644 --- a/Doc/Zsh/mod_zutil.yo +++ b/Doc/Zsh/mod_zutil.yo @@ -40,8 +40,8 @@ that it looks up the tt(preferred-precipitation) style under the `tt(:weather:)var(continent)tt(:)var(day-of-the-week)tt(:)var(phase-of-the-moon))' context. According to this, you might set the following in your tt(zshrc): -example(zstyle ':weather:*:Sunday:*' preferred-precipitation snow -zstyle ':weather:europe:*' preferred-precipitation rain) +example(zstyle ':weather:europe:*' preferred-precipitation rain +zstyle ':weather:*:Sunday:*' preferred-precipitation snow) Then the plugin would run under the hood a command such as @@ -52,7 +52,7 @@ On Sundays tt($REPLY) would be set to `tt(snow)'; in Europe it would be set to `tt(rain)'; and on Sundays in Europe it would be set to `tt(snow)' again, because the patterns `tt(:weather:europe:*)' and `tt(:weather:*:Sunday:*)' both match the var(context) argument to tt(zstyle -s), are equally specific, and the -latter was defined first. +latter is more specific (because it has more colon-separated components). em(Usage) diff --git a/README b/README index b87f660bf..8ae615153 100644 --- a/README +++ b/README @@ -64,6 +64,25 @@ The sh-compatible function definition syntax, "f() { ... }", is unchanged. The time-out (-t) value given to zsh/system's `zsystem flock` command is now limited to 2^30-1 seconds (= a little over 34 years). +zstyle: For background, recall that the zstyle builtin associates styles with +values for particular contexts, and when a context (such as ':foo:bar:baz') is +matched by multiple patterns (such as ':foo:*' and ':foo:bar:*'), the style's +value for the more specific of the patterns is used. In zsh 5.8 and earlier +the determination of which pattern is "more specific" used semantics slightly +different to those the documentation promised. The implementation was changed +to match the documentation. The upshot of this is that if you set a single +style in multiple contexts, zsh 5.9 may use the values set for a pattern other +than the one zsh 5.8 used. For example, if you do + zstyle ':foo:bar:*' style value1 + zstyle ':foo:*:baz:*' style value2 +and the style is looked up under a context that both patterns match (e.g., +:foo:bar:baz:qux), zsh 5.9 will use value2 -- which is consistent with the +documentation of both 5.8 and 5.9 -- but zsh 5.8 will use value1. If this +affects you, make the implied colons in the first pattern explicit, as in: + zstyle ':foo:bar:*:*' style value1 + zstyle ':foo:*:baz:*' style value2 +This will use value1 in both 5.8 and 5.9. + Incompatibilities between 5.7.1 and 5.8 --------------------------------------- diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 7d9bf05d6..5c96d06c1 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -96,7 +96,7 @@ struct stypat { Stypat next; char *pat; /* pattern string */ Patprog prog; /* compiled pattern */ - int weight; /* how specific is the pattern? */ + zulong weight; /* how specific is the pattern? */ Eprog eval; /* eval-on-retrieve? */ char **vals; }; @@ -293,7 +293,9 @@ newzstyletable(int size, char const *name) static int setstypat(Style s, char *pat, Patprog prog, char **vals, int eval) { - int weight, tmp, first; + zulong weight; + int tmp; + int first; char *str; Stypat p, q, qq; Eprog eprog = NULL; @@ -348,6 +350,12 @@ setstypat(Style s, char *pat, Patprog prog, char **vals, int eval) * - A component that's a literal string scores 2 points. * - The score of a pattern is the sum of the score of its components. * + * The result of this calculation is stored in the low bits of 'weight'. + * The high bits of 'weight' are used to store the number of ':'-separated + * components. This provides a lexicographic comparison: first compare + * the number of components, and if that's equal, compare the specificity + * of the components. + * * This corresponds to the notion of 'more specific' in the zshmodules(1) * documentation of zstyle. */ @@ -367,6 +375,7 @@ setstypat(Style s, char *pat, Patprog prog, char **vals, int eval) if (*str == ':') { /* Yet another component. */ + weight += ZLONG_CONST(1) << (CHAR_BIT * sizeof(weight) / 2); first = 1; weight += tmp; diff --git a/Test/V05styles.ztst b/Test/V05styles.ztst index 9b5fc4517..048751941 100644 --- a/Test/V05styles.ztst +++ b/Test/V05styles.ztst @@ -163,4 +163,4 @@ ) 0:the example in the documentation remains correct >snow ->rain +>snow -- cgit v1.2.3 From 9120d1e841b0813f1c71d55f77c3d18fc8318187 Mon Sep 17 00:00:00 2001 From: Joshua Krusell Date: Wed, 3 Feb 2021 11:33:47 +0000 Subject: 47899: Improve error message from zparseopts. --- ChangeLog | 5 +++++ Src/Modules/zutil.c | 5 ++++- Test/V12zparseopts.ztst | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index 52ebf9513..d5725d379 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-02-03 Joshua Krusell + + * 47899: Src/Modules/zutil.c, Test/V12zparseopts.ztst: Improved + error message from zparseopts. + 2021-01-20 Jun-ichi Takimoto * 47883: Completion/Unix/Command/_awk: support gawk ver.5 diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 5c96d06c1..c8017d0c0 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -1873,7 +1873,10 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) while (*++o) { if (!(d = sopts[STOUC(*o)])) { if (fail) { - zwarnnam(nam, "bad option: %c", *o); + if (*o != '-') + zwarnnam(nam, "bad option: %c", *o); + else + zwarnnam(nam, "bad option: %s", o); return 1; } o = NULL; diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst index d7fc33f72..c41c49022 100644 --- a/Test/V12zparseopts.ztst +++ b/Test/V12zparseopts.ztst @@ -69,7 +69,7 @@ >ret: 1, optv: , argv: -a -x -z ?(anon):zparseopts:2: bad option: x >ret: 1, optv: , argv: -ax -z -?(anon):zparseopts:2: bad option: - +?(anon):zparseopts:2: bad option: -x >ret: 1, optv: , argv: -a --x -z for 1 in '-a 1 2 3' '1 2 3'; do -- cgit v1.2.3 From 3d6e5b6231f0d80873c6f83924a48df223121e72 Mon Sep 17 00:00:00 2001 From: Joshua Krusell Date: Wed, 3 Feb 2021 16:46:59 +0100 Subject: 47905: Add leading '-' to zparseopts option parsing errors --- ChangeLog | 6 ++++++ Src/Modules/zutil.c | 8 ++++---- Test/V12zparseopts.ztst | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index 4946b84c3..20f7eccf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-02-13 Oliver Kiddle + + * 47905: Joshua Krusell: Src/Modules/zutil.c, + Test/V12zparseopts.ztst: Add leading '-' to zparseopts option + parsing errors + 2021-02-11 Bart Schaefer * unposted: NEWS, README: mention the effects of 47997. diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index c8017d0c0..cecea6d51 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -1874,9 +1874,9 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) if (!(d = sopts[STOUC(*o)])) { if (fail) { if (*o != '-') - zwarnnam(nam, "bad option: %c", *o); + zwarnnam(nam, "bad option: -%c", *o); else - zwarnnam(nam, "bad option: %s", o); + zwarnnam(nam, "bad option: -%s", o); return 1; } o = NULL; @@ -1889,7 +1889,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) } else if (!(d->flags & ZOF_OPT) || (pp[1] && pp[1][0] != '-')) { if (!pp[1]) { - zwarnnam(nam, "missing argument for option: %s", + zwarnnam(nam, "missing argument for option: -%s", d->name); return 1; } @@ -1916,7 +1916,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) else if (!(d->flags & ZOF_OPT) || (pp[1] && pp[1][0] != '-')) { if (!pp[1]) { - zwarnnam(nam, "missing argument for option: %s", + zwarnnam(nam, "missing argument for option: -%s", d->name); return 1; } diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst index c41c49022..816e1d041 100644 --- a/Test/V12zparseopts.ztst +++ b/Test/V12zparseopts.ztst @@ -65,11 +65,11 @@ } $=1 done 0:zparseopts -F -?(anon):zparseopts:2: bad option: x +?(anon):zparseopts:2: bad option: -x >ret: 1, optv: , argv: -a -x -z -?(anon):zparseopts:2: bad option: x ->ret: 1, optv: , argv: -ax -z ?(anon):zparseopts:2: bad option: -x +>ret: 1, optv: , argv: -ax -z +?(anon):zparseopts:2: bad option: --x >ret: 1, optv: , argv: -a --x -z for 1 in '-a 1 2 3' '1 2 3'; do @@ -168,5 +168,5 @@ print -r - ret: $?, optv: $optv, argv: $argv } -ab1 -c 0:missing optarg -?(anon):zparseopts:2: missing argument for option: c +?(anon):zparseopts:2: missing argument for option: -c >ret: 1, optv: , argv: -ab1 -c -- cgit v1.2.3 From 283d2f3c2761ac549a647638bb7d8fd8de3dabb4 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 9 Apr 2021 21:01:37 +0100 Subject: 48432 and enable test: fix quotiing of zstyle -L for zstyle -e --- ChangeLog | 6 ++++++ Src/Modules/zutil.c | 3 ++- Test/V05styles.ztst | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index cb4ad6833..f894cc2fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-04-09 Peter Stephenson + + * 48432 (plus test change): Src/Modules/zutil.c, + Test/V05styles.ztst: Fix quoting of zstyle -L output for + -e styles, and enable test. + 2021-04-09 Oliver Kiddle * 48378: Completion/Zsh/Command/_compadd: complete compadd diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index cecea6d51..691ba6c2f 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -200,7 +200,8 @@ printstylenode(HashNode hn, int printflags) else { printf("zstyle %s", (p->eval ? "-e " : "")); quotedzputs(p->pat, stdout); - printf(" %s", s->node.nam); + putchar(' '); + quotedzputs(s->node.nam, stdout); } for (v = p->vals; *v; v++) { putchar(' '); diff --git a/Test/V05styles.ztst b/Test/V05styles.ztst index e4bdfece3..61d2cdb0a 100644 --- a/Test/V05styles.ztst +++ b/Test/V05styles.ztst @@ -171,5 +171,5 @@ a=( ${(M)a:#*con*text*ke*y*val*u*e} ) print -r -- "$a" ) --f:zstyle -L escapes the key (regression: workers/48424) +0:zstyle -L escapes the key (regression: workers/48424) >zstyle $'con\C-@text' $'ke\C-@y' $'val\C-@u' e -- cgit v1.2.3 From dfb7ac94bb4c28472d759a61ea3c2dab30cf9cd3 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 12 Nov 2021 20:33:52 +0100 Subject: 49561: add zformat -F option, similar to -f but ternary expressions check for existence instead of doing math evaluation --- ChangeLog | 8 +++++++ Completion/Base/Core/_description | 2 +- Completion/Base/Core/_message | 2 +- Doc/Zsh/mod_zutil.yo | 11 +++++++-- Src/Modules/zutil.c | 48 ++++++++++++++++++++++++++------------- Test/V13zformat.ztst | 24 ++++++++++++++++++++ 6 files changed, 75 insertions(+), 20 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index 5865cb727..65c0dfa8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-11-12 Oliver Kiddle + + * 49561: Src/Modules/zutil.c, Doc/Zsh/mod_zutil.yo, + Completion/Base/Core/_description, Completion/Base/Core/_message, + Test/V13zformat.ztst: Add zformat -F option, similar to -f but + ternary expressions check for existence instead of doing math + evaluation. Make use it with the format style. + 2021-11-07 Oliver Kiddle * 49544: Src/Modules/watch.c: only tie watch/WATCH if both come diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description index bdb4007a6..5b54484c7 100644 --- a/Completion/Base/Core/_description +++ b/Completion/Base/Core/_description @@ -78,7 +78,7 @@ shift 2 if [[ -z "$1" && $# -eq 1 ]]; then format= elif [[ -n "$format" ]]; then - zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" + zformat -F format "$format" "d:$1" "${(@)argv[2,-1]}" fi if [[ -n "$gname" ]]; then diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message index 4d5645eaf..dbeed4a88 100644 --- a/Completion/Base/Core/_message +++ b/Completion/Base/Core/_message @@ -39,7 +39,7 @@ else fi if [[ -n "$format$raw" ]]; then - [[ -z "$raw" ]] && zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" + [[ -z "$raw" ]] && zformat -F format "$format" "d:$1" "${(@)argv[2,-1]}" builtin compadd "$gopt[@]" -x "$format" _comp_mesg=yes fi diff --git a/Doc/Zsh/mod_zutil.yo b/Doc/Zsh/mod_zutil.yo index 41d3dfdb0..3cf9e5028 100644 --- a/Doc/Zsh/mod_zutil.yo +++ b/Doc/Zsh/mod_zutil.yo @@ -150,8 +150,9 @@ enditem() ) findex(zformat) xitem(tt(zformat -f) var(param) var(format) var(spec) ...) +xitem(tt(zformat -F) var(param) var(format) var(spec) ...) item(tt(zformat -a) var(array) var(sep) var(spec) ...)( -This builtin provides two different forms of formatting. The first form +This builtin provides different forms of formatting. The first form is selected with the tt(-f) option. In this case the var(format) string will be modified by replacing sequences starting with a percent sign in it with strings from the var(spec)s. Each var(spec) should be @@ -195,7 +196,13 @@ outputs "The answer is 'yes'." to tt(REPLY) since the value for the format specifier tt(c) is 3, agreeing with the digit argument to the ternary expression. -The second form, using the tt(-a) option, can be used for aligning +With tt(-F) instead of tt(-f), ternary expressions choose between the +`true' or `false' text on the basis of whether the format specifier is +present and non-empty. A test number indicates a minimum width for the +value given in the format specifier. Negative numbers reverse this, +so the test is for whether the value exceeds a maximum width. + +The form, using the tt(-a) option, can be used for aligning strings. Here, the var(spec)s are of the form `var(left)tt(:)var(right)' where `var(left)' and `var(right)' are arbitrary strings. These strings are modified by replacing the colons diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 691ba6c2f..2f17c03f1 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -776,10 +776,12 @@ bin_zstyle(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) * ousedp (*outp)[*ousedp] is where to write next * olenp *olenp is the size allocated for *outp * endchar Terminator character in addition to `\0' (may be '\0') + * presence -F: Ternary expressions test emptyness instead * skip If 1, don't output, just parse. */ static char *zformat_substring(char* instr, char **specs, char **outp, - int *ousedp, int *olenp, int endchar, int skip) + int *ousedp, int *olenp, int endchar, + int presence, int skip) { char *s; @@ -813,20 +815,29 @@ static char *zformat_substring(char* instr, char **specs, char **outp, if (testit && STOUC(*s)) { int actval, testval, endcharl; - /* - * One one number is useful for ternary expressions. - * Remember to put the sign back. - */ + /* Only one number is useful for ternary expressions. */ testval = (min >= 0) ? min : (max >= 0) ? max : 0; - if (right) - testval *= -1; - if (specs[STOUC(*s)]) - actval = (int)mathevali(specs[STOUC(*s)]); - else - actval = 0; - /* zero means values are equal, i.e. true */ - actval -= testval; + if (specs[STOUC(*s)] && *specs[STOUC(*s)]) { + if (presence) { + if (testval) +#ifdef MULTIBYTE_SUPPORT + if (isset(MULTIBYTE)) + actval = MB_METASTRWIDTH(specs[STOUC(*s)]); + else +#endif + actval = strlen(specs[STOUC(*s)]); + else + actval = 1; + actval = right ? (testval < actval) : (testval >= actval); + } else { + if (right) /* put the sign back */ + testval *= -1; + /* zero means values are equal, i.e. true */ + actval = (int)mathevali(specs[STOUC(*s)]) - testval; + } + } else + actval = presence ? !right : testval; /* careful about premature end of string */ if (!(endcharl = *++s)) @@ -837,10 +848,10 @@ static char *zformat_substring(char* instr, char **specs, char **outp, * vice versa... unless we are already skipping. */ if (!(s = zformat_substring(s+1, specs, outp, ousedp, - olenp, endcharl, skip || actval))) + olenp, endcharl, presence, skip || actval))) return NULL; if (!(s = zformat_substring(s+1, specs, outp, ousedp, - olenp, ')', skip || !actval))) + olenp, ')', presence, skip || !actval))) return NULL; } else if (skip) { continue; @@ -912,6 +923,7 @@ static int bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) { char opt; + int presence = 0; if (args[0][0] != '-' || !(opt = args[0][1]) || args[0][2]) { zwarnnam(nam, "invalid argument: %s", args[0]); @@ -920,6 +932,9 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) args++; switch (opt) { + case 'F': + presence = 1; + /* fall-through */ case 'f': { char **ap, *specs[256] = {0}, *out; @@ -939,7 +954,8 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) } out = (char *) zhalloc(olen = 128); - zformat_substring(args[1], specs, &out, &oused, &olen, '\0', 0); + zformat_substring(args[1], specs, &out, &oused, &olen, '\0', + presence, 0); out[oused] = '\0'; setsparam(args[0], ztrdup(out)); diff --git a/Test/V13zformat.ztst b/Test/V13zformat.ztst index 982866e13..035a0a495 100644 --- a/Test/V13zformat.ztst +++ b/Test/V13zformat.ztst @@ -58,6 +58,30 @@ 0:nested conditionals test >yes + () { + zformat -f 1 '%(w.zero.fail) %(x.fail.present) %(y.empty.fail) %(z.missing.fail)' w:0 x:1 y: + zformat -F 2 '%(w.zero.fail) %(x.present.fail) %(y.fail.empty) %(z.fail.missing)' w:0 x:1 y: + echo $1 + echo $2 + } +0:conditionals with empty and missing values +>zero present empty missing +>zero present empty missing + + () { + local l + for l in 0 1 2 3; do + zformat -F 1 "%$l(a.a.A)%$l(b.b.B)%$l(c.c.C)%$l(d.d.D)" a: b:1 c:12 d:123 + zformat -F 2 "%-$l(a.a.A)%-$l(b.b.B)%-$l(c.c.C)%-$l(d.d.D)" a: b:1 c:12 d:123 + print - $1 $2 + done + } +0:minimum and maximum widths +>Abcd aBCD +>ABcd abCD +>ABCd abcD +>ABCD abcd + zformat -a argv . foo:lorem ipsum:bar bazbaz '\\esc\:ape' print -rl -- "$@" 0:basic -a test -- cgit v1.2.3