Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Make ztrftime pass more things to strftime
- X-seq: zsh-workers 35725
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Make ztrftime pass more things to strftime
- Date: Wed, 8 Jul 2015 01:15:00 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=loyr5yIXVDbq85ltIuj9cBc5D4bEf9YdJmvvDvpkb2A=; b=GsH6tepgVZbml3sbJnHVDkeEXKY8jzFY7rp336ASWArF3A1B4EweIRywEnLKrNYtVu pODGpvfZmchTDDL/qBQFsRSau0guvxaanS1JWp4SNWARHfyb1uf0w7GImOphu72PJZbR JU02P1ySPCPMbRatfI8KMz/3o1uPf9DCL/Je4NLIRSWaiOlHhKEyirLm6V4CWvc0lHvO GAMbYAtQ1nSixt1qRNHCZatgp+UasyEY1LzVGJCs2KTSG8tSwusIEcsPnl/PJpehmS6o wmhUHxVGkZJJKKr1zvoAVZMrDCc90EjRS+OAiSAz/yI3c7RNtMLk3amJ6SnBzByswJos HFMQ==
- 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
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author