Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: ztrftime: Handle all non-zsh format chars with strftime if present (v2)
- X-seq: zsh-workers 35738
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: ztrftime: Handle all non-zsh format chars with strftime if present (v2)
- Date: Wed, 8 Jul 2015 17:06:15 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=M6/lJWAlNFHluHl6JPYPgVyuumz1Y9Kr79xkQniPWfM=; b=FmdrGBnEAL4j54H22QNSR750mPeHikQccXDUYN8bTrRRs0QnjwTU9nCtzlTTHj5T41 mHmh/VFd2c0Gojcs7re/xfVXRqwSq8hJPoKMInPZbbO77Mx1EdhVSKcmS1ddwCvwm/FJ RtbA2vY53APzel71eXcbwSq0r582Aq4BdLhPs4TW8UAGIP50gfiUFNJIxDOud6n8tMBE pu1avw+iMlcPhEZ4CV7XqHwIjSrPhwSMcQCsW2LUef99So/wGm1ryX/ePCkdPbyx0mcs vVMdglVcCWwtpYHicnSobQ0C9VXplHhCPcE+dts587NN9wWfgYbZljJ6IRM3WTffeaAf jOLw==
- In-reply-to: <1436366383-23389-1-git-send-email-mikachu@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1436366383-23389-1-git-send-email-mikachu@gmail.com>
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))
@@ -2948,10 +2953,10 @@ morefmt:
sprintf(buf, "%0*ld", digs, usec);
buf += digs;
break;
- case 'd':
- if (tm->tm_mday > 9 || !strip)
- *buf++ = '0' + tm->tm_mday / 10;
- *buf++ = '0' + tm->tm_mday % 10;
+ case '\0':
+ /* Guard against premature end of string */
+ *buf++ = '%';
+ fmt--;
break;
case 'f':
strip = 1;
@@ -2992,6 +2997,12 @@ morefmt:
*buf++ = '0' + (hr12 % 10);
break;
+#ifndef HAVE_STRFTIME
+ case 'd':
+ if (tm->tm_mday > 9 || !strip)
+ *buf++ = '0' + tm->tm_mday / 10;
+ *buf++ = '0' + tm->tm_mday % 10;
+ break;
case 'm':
if (tm->tm_mon > 8 || !strip)
*buf++ = '0' + (tm->tm_mon + 1) / 10;
@@ -3012,12 +3023,6 @@ morefmt:
*buf++ = '0' + (tm->tm_year / 10) % 10;
*buf++ = '0' + tm->tm_year % 10;
break;
- case '\0':
- /* Guard against premature end of string */
- *buf++ = '%';
- fmt--;
- break;
-#ifndef HAVE_STRFTIME
case 'Y':
{
/*
@@ -3065,6 +3070,7 @@ morefmt:
case '-':
case '0' ... '9':
goto morefmt;
+strftimehandling:
default:
/*
* Remember we've already allowed for two characters
--
2.4.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author