From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3598 invoked by alias); 7 Jul 2015 23:15:14 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35725 Received: (qmail 1875 invoked from network); 7 Jul 2015 23:15:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 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== X-Received: by 10.180.88.8 with SMTP id bc8mr68000064wib.19.1436310908200; Tue, 07 Jul 2015 16:15:08 -0700 (PDT) From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Make ztrftime pass more things to strftime Date: Wed, 8 Jul 2015 01:15:00 +0200 Message-Id: <1436310900-9519-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 2.4.0 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