Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: ztrftime: Handle all non-zsh format chars with strftime if present (v2)



On Wed, Jul 8, 2015 at 5:06 PM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> At this point, even I find the code slightly questionable. And this doesn't even work properly yet:
> % print -P %D\{aa%14a\}
> aa%
> % print -P %D\{aaa%14a\}
> aaa           Wed
>
> ---
>  Src/utils.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/Src/utils.c b/Src/utils.c
> index 2d53a00..c18a8de 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -2933,6 +2933,11 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
>             if (ztrftimebuf(&bufsize, 2))
>                 return -1;
>  morefmt:
> +           if (!((fmt - fmtstart == 1) || (fmt - fmtstart == 2 && strip) || *fmt == '.')) {
> +               while (*fmt && strchr("OE^#_-0123456789", *fmt++));
> +               if (*fmt++)
> +                   goto strftimehandling;
> +           }
>             switch (*fmt++) {
>             case '.':
>                 if (ztrftimebuf(&bufsize, digs))

Okay, fun thinko here, should be
-               while (*fmt && strchr("OE^#_-0123456789", *fmt++));
+               while (*fmt && strchr("OE^#_-0123456789", *fmt))
+                   fmt++;

I even had to stare at this for a minute to realize why it fixes it.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author