* Fix strftime (prompts) before 5.2?
@ 2015-11-22 17:27 Bart Schaefer
2015-11-22 17:43 ` PATCH: ztrftime: more workarounds for broken strftime interface Mikael Magnusson
2015-11-22 18:06 ` Fix strftime (prompts) before 5.2? Peter Stephenson
0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-11-22 17:27 UTC (permalink / raw)
To: zsh-workers
Do we want to try to fix users/20859 ? It shouldn't be that hard for
someone in an environment where it fails (I'm having trouble creating
one).
^ permalink raw reply [flat|nested] 4+ messages in thread
* PATCH: ztrftime: more workarounds for broken strftime interface
2015-11-22 17:27 Fix strftime (prompts) before 5.2? Bart Schaefer
@ 2015-11-22 17:43 ` Mikael Magnusson
2015-11-22 18:06 ` Fix strftime (prompts) before 5.2? Peter Stephenson
1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2015-11-22 17:43 UTC (permalink / raw)
To: zsh-workers
On Sun, Nov 22, 2015 at 6:27 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> Do we want to try to fix users/20859 ? It shouldn't be that hard for
> someone in an environment where it fails (I'm having trouble creating
> one).
The problem is that the strftime() function is defined by an idiot. There
is no way to differentiate the success of a zero-length result and any
error. If there is any error then the return result is undefined so we
cannot use it.
I guess we could append some fixed string always, and then discard this
string, for example an x character.
This somehow works and doesn't break the tests, nor my prompt.
---
Src/utils.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/Src/utils.c b/Src/utils.c
index c19cca8..f42b25b 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3154,8 +3154,9 @@ strftimehandling:
{
int size = fmt - fmtstart;
char *tmp, *last;
- tmp = zhalloc(size + 1);
+ tmp = zhalloc(size + 2);
strncpy(tmp, fmtstart, size);
+ tmp[size] = 'x';
last = fmt-1;
if (*last == Meta) {
/*
@@ -3168,7 +3169,7 @@ strftimehandling:
*/
*last = *++fmt ^ 32;
}
- tmp[size] = '\0';
+ tmp[size+1] = '\0';
*buf = '\1';
if (!strftime(buf, bufsize + 2, tmp, tm))
{
@@ -3178,7 +3179,7 @@ strftimehandling:
}
return 0;
}
- decr = strlen(buf);
+ decr = strlen(buf) - 1;
buf += decr;
bufsize -= decr - 2;
}
--
2.6.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fix strftime (prompts) before 5.2?
2015-11-22 17:27 Fix strftime (prompts) before 5.2? Bart Schaefer
2015-11-22 17:43 ` PATCH: ztrftime: more workarounds for broken strftime interface Mikael Magnusson
@ 2015-11-22 18:06 ` Peter Stephenson
2015-11-22 18:38 ` Bart Schaefer
1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-11-22 18:06 UTC (permalink / raw)
To: Bart Schaefer, zsh-workers
On Sun, 22 Nov 2015 09:27:11 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Do we want to try to fix users/20859 ? It shouldn't be that hard for
> someone in an environment where it fails (I'm having trouble creating
> one).
Putting it all together, the reported failing case is:
% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S%P}")
Son Nov 22
5:36% (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S}")
Son Nov 22 05:37:02
and that's indeed the feature --- no time if %P is present.
The date component is irrelevant (except that it shosw strftime isn't
completely screwed), so it just reduces to the second %D substitution in
that locale. Not specific to Switzerland or in fact to German; happens
in de_DE.UTF-8 and fr_CH.UTF-8, too. Suspected metafication, but it
wasn't.
This suggests the test for a successful expansion isn't safe after all,
but probably there aren't too many expansions like %p and %P.
pws
diff --git a/Src/utils.c b/Src/utils.c
index 0afa8c9..4640970 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3143,6 +3143,7 @@ strftimehandling:
* in the accounting in bufsize (but nowhere else).
*/
{
+ char origchar = fmt[-1];
int size = fmt - fmtstart;
char *tmp, *last;
tmp = zhalloc(size + 1);
@@ -3163,11 +3164,17 @@ strftimehandling:
*buf = '\1';
if (!strftime(buf, bufsize + 2, tmp, tm))
{
- if (*buf) {
- buf[0] = '\0';
- return -1;
+ /*
+ * Some locales don't have strings for
+ * AM/PM, so empty output is valid.
+ */
+ if (*buf || (origchar != 'p' && origchar != 'P')) {
+ if (*buf) {
+ buf[0] = '\0';
+ return -1;
+ }
+ return 0;
}
- return 0;
}
decr = strlen(buf);
buf += decr;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fix strftime (prompts) before 5.2?
2015-11-22 18:06 ` Fix strftime (prompts) before 5.2? Peter Stephenson
@ 2015-11-22 18:38 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2015-11-22 18:38 UTC (permalink / raw)
To: zsh-workers
On Nov 22, 6:06pm, Peter Stephenson wrote:
}
} Putting it all together, the reported failing case is:
}
} % (LC_ALL=de_CH.UTF-8; print -P "%D{%a %b %d} %D{%I:%M:%S%P}")
} Son Nov 22
Maybe it's time (ahem) for something like this? (Equivalent patch would
be needed in elite, elite2, fade, and fire themes.)
The difference is " %p" in most langinfo vs. "%P" in the current themes.
diff --git a/Functions/Prompts/prompt_bigfade_setup b/Functions/Prompts/prompt_bigfade_setup
index 2d95f31..918ac82 100644
--- a/Functions/Prompts/prompt_bigfade_setup
+++ b/Functions/Prompts/prompt_bigfade_setup
@@ -31,7 +31,10 @@ prompt_bigfade_setup () {
autoload -Uz prompt_special_chars
prompt_special_chars
- PS1="%B%F{$fadebar}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$userhost}%K{$fadebar}%n@%m%b%k%f%F{$fadebar}%K{black}$schars[260]$schars[261]$schars[262]$schars[333]%b%f%k%F{$fadebar}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$date}%K{black} %D{%a %b %d} %D{%I:%M:%S%P}$prompt_newline%B%F{$cwd}%K{black}%d>%b%f%k "
+ zmodload zsh/langinfo 2>/dev/null
+ local T_FMT=${${langinfo:+${langinfo[T_FMT_AMPM]}}:-%I:%M:%S%P}
+
+ PS1="%B%F{$fadebar}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$userhost}%K{$fadebar}%n@%m%b%k%f%F{$fadebar}%K{black}$schars[260]$schars[261]$schars[262]$schars[333]%b%f%k%F{$fadebar}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$date}%K{black} %D{%a %b %d} %D{$T_FMT}$prompt_newline%B%F{$cwd}%K{black}%d>%b%f%k "
PS2="%B%F{$fadebar}$schars[333]$schars[262]$schars[261]$schars[260]%b%F{$fadebar}%K{black}$schars[260]$schars[261]$schars[262]$schars[333]%F{$fadebar}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%B%F{$fadebar}>%b%f%k "
prompt_opts=(cr subst percent)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-22 18:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-22 17:27 Fix strftime (prompts) before 5.2? Bart Schaefer
2015-11-22 17:43 ` PATCH: ztrftime: more workarounds for broken strftime interface Mikael Magnusson
2015-11-22 18:06 ` Fix strftime (prompts) before 5.2? Peter Stephenson
2015-11-22 18:38 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).