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

Re: PATCH: ztrftime: Pass everything unhandled to the system strftime()



On Mon, Jul 27, 2015 at 1:56 PM, Jun T. <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
> I wrote:
>> Is it possible to pass the entire format string to strftime()
>> if HAVE_STRFTIME is defined?
>
> but this was not a good idea. On cygwin, V09datetime.ztst fails as
>
> *** 1,2 ****
> ! 6_6_3_3
>   000000
> --- 1,2 ----
> !
>   000000
> Test ./V09datetime.ztst failed: output differs from expected as shown above for:
>   strftime %-m_%f_%K_%L 1181100000
>   strftime %6. 0
> Was testing: zsh extensions
> ./V09datetime.ztst: test failed.
>
> strftime(3) on cygwin is from newlib (not gnu libc) and does not support
> any of gnu extensions including the %- modifier. But man zshmisc says:
>
>     The GNU extension that a `-' between the % and the format  char-
>     acter  causes  a leading zero or space to be stripped is handled
>     directly by the shell for the format characters d, f, H,  k,  l,
>     m, M, S and y; any other format characters are provided to strf-
>     time() with any leading `-', present, so the handling is  system
>     dependent.  Further GNU extensions are not supported at present.

Oops, but it's nice that writing the tests paid off :). ACK on the
patch from me.

> so %-m etc. needs be supported also on cygwin? The simplest fix would be
> to move the #ifndef HAVE_STRFTIME back to the original position:
>
> diff --git a/Src/utils.c b/Src/utils.c
> index f7aaaed..236661a 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -3006,7 +3006,6 @@ morefmt:
>
>                 *buf++ = '0' + (hr12 % 10);
>                 break;
> -#ifndef HAVE_STRFTIME
>             case 'd':
>                 if (tm->tm_mday > 9 || !strip)
>                     *buf++ = '0' + tm->tm_mday / 10;
> @@ -3032,6 +3031,7 @@ morefmt:
>                     *buf++ = '0' + (tm->tm_year / 10) % 10;
>                 *buf++ = '0' + tm->tm_year % 10;
>                 break;
> +#ifndef HAVE_STRFTIME
>             case 'Y':
>             {
>                 int year, digits, testyear;
>
>
>
> BTW, the last part of the above man page
> "Further GNU extensions are not supported at present."
> needs be updated?

I guess it could say something along the lines of
"Further GNU (or other) extensions are not supported, but will work if
the system libc supports them."
?

-- 
Mikael Magnusson



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