zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Make ztrftime pass more things to strftime
@ 2015-07-07 23:15 Mikael Magnusson
  2015-07-07 23:21 ` Mikael Magnusson
  2015-07-08 10:39 ` Peter Stephenson
  0 siblings, 2 replies; 25+ messages in thread
From: Mikael Magnusson @ 2015-07-07 23:15 UTC (permalink / raw)
  To: zsh-workers

I poked at this for an hour, and this is the first version that passes
make check and doesn't segfault randomly, so it is not very well tested,
to say the least. Opinions on the approach?

---
 Src/utils.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/Src/utils.c b/Src/utils.c
index aea89c3..0e079c9 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2887,7 +2887,7 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
     int hr12;
 #ifdef HAVE_STRFTIME
     int decr;
-    char tmp[4];
+    char *fmtstart;
 #else
     static char *astr[] =
     {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
@@ -2903,7 +2903,11 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
 	    int strip;
 	    int digs = 3;
 
+#ifdef HAVE_STRFTIME
+	    fmtstart =
+#endif
 	    fmt++;
+
 	    if (*fmt == '-') {
 		strip = 1;
 		fmt++;
@@ -2928,6 +2932,7 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
 	     */
 	    if (ztrftimebuf(&bufsize, 2))
 		return -1;
+morefmt:
 	    switch (*fmt++) {
 	    case '.':
 		if (ztrftimebuf(&bufsize, digs))
@@ -3052,13 +3057,24 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
 		if (fmt[-1] != '%')
 		    *buf++ = fmt[-1];
 #else
+	    case 'E':
+	    case 'O':
+	    case '^':
+	    case '#':
+	    case '_':
+	    case '0' ... '9':
+		goto morefmt;
 	    default:
 		/*
 		 * Remember we've already allowed for two characters
 		 * in the accounting in bufsize (but nowhere else).
 		 */
+		{
+		int size = fmt - fmtstart;
+		char *tmp = zhalloc(size + 1);
+		strncpy(tmp, fmtstart, size);
+		tmp[size] = '\0';
 		*buf = '\1';
-		sprintf(tmp, strip ? "%%-%c" : "%%%c", fmt[-1]);
 		if (!strftime(buf, bufsize + 2, tmp, tm))
 		{
 		    if (*buf) {
@@ -3070,6 +3086,7 @@ ztrftime(char *buf, int bufsize, char *fmt, struct tm *tm, long usec)
 		decr = strlen(buf);
 		buf += decr;
 		bufsize -= decr - 2;
+		}
 #endif
 		break;
 	    }
-- 
2.4.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-09-01 21:16 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07 23:15 PATCH: Make ztrftime pass more things to strftime Mikael Magnusson
2015-07-07 23:21 ` Mikael Magnusson
2015-07-08 10:53   ` Peter Stephenson
2015-07-09  5:16     ` Mikael Magnusson
2015-07-09  8:41       ` Peter Stephenson
2015-07-09  9:58         ` PATCH: ztrftime: Pass everything unhandled to the system strftime() Mikael Magnusson
2015-07-09 10:17           ` Peter Stephenson
2015-07-10 13:37             ` Peter Stephenson
2015-07-10 16:18               ` Skipping tests (was Re: PATCH: ztrftime: Pass everything ...) Bart Schaefer
2015-07-10 16:23                 ` Peter Stephenson
2015-07-10 18:31               ` PATCH: ztrftime: Pass everything unhandled to the system strftime() Daniel Shahaf
2015-07-10 23:54                 ` ZTST_skip (was Re: PATCH: ztrftime ...) Bart Schaefer
2015-07-09 15:52           ` PATCH: ztrftime: Pass everything unhandled to the system strftime() Jun T.
2015-07-10 14:53           ` Jun T.
2015-07-10 18:23             ` Mikael Magnusson
2015-07-27 11:56           ` Jun T.
2015-07-27 13:31             ` Mikael Magnusson
2015-07-27 16:50               ` Jun T.
2015-07-27 17:01               ` Jun T.
2015-09-01 13:53           ` Oliver Kiddle
2015-09-01 14:07             ` Peter Stephenson
2015-09-01 21:16             ` PATCH: Avoid gcc case syntax Mikael Magnusson
2015-07-08 14:03   ` PATCH: Make ztrftime pass more things to strftime Jun T.
2015-07-09  4:36     ` Mikael Magnusson
2015-07-08 10:39 ` Peter Stephenson

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).