zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: ztrftime: Handle all non-zsh format chars with strftime if present (v2)
Date: Wed,  8 Jul 2015 17:06:15 +0200	[thread overview]
Message-ID: <1436367975-2945-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <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


  reply	other threads:[~2015-07-08 15:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4FE37754-AA20-405E-8925-6C4F9E0043AE@kba.biglobe.ne.jp>
2015-07-08 14:39 ` PATCH: ztrftime: Handle all non-zsh format chars with strftime if present Mikael Magnusson
2015-07-08 15:06   ` Mikael Magnusson [this message]
2015-07-09  4:31     ` PATCH: ztrftime: Handle all non-zsh format chars with strftime if present (v2) Mikael Magnusson
2015-07-09  5:43       ` Bart Schaefer
2015-07-09  7:00         ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436367975-2945-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).