Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

bug in ztrftime(): '%e' and '%f' specifiers swapped



Hi Peter,

I just tracked down a bug in 'cvs' completion, in particular the logic
in _cvs_modified_entries, and found the problem is due to your changes
in Src/utils.c, revision 1.210:

| revision 1.210
| date: 2009/03/02 10:12:17;  author: pws;  state: Exp;  lines: +56 -15
| 26614 + 26615: history -t <fmt> plus ztrftime "-" format modifier

You have inadvertently swapped the meanings of the '%e' and '%f' format
specifiers.  This patch should do the trick:

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.225
diff -u -r1.225 utils.c
--- Src/utils.c	5 Jun 2009 11:15:53 -0000	1.225
+++ Src/utils.c	26 Jun 2009 20:18:41 -0000
@@ -2489,10 +2489,10 @@
 		    *buf++ = '0' + tm->tm_mday / 10;
 		*buf++ = '0' + tm->tm_mday % 10;
 		break;
-	    case 'e':
+	    case 'f':
 		strip = 1;
 		/* FALLTHROUGH */
-	    case 'f':
+	    case 'e':
 		if (tm->tm_mday > 9)
 		    *buf++ = '0' + tm->tm_mday / 10;
 		else if (!strip)

However, I find this equivalent patch to be more readable:

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.225
diff -u -r1.225 utils.c
--- Src/utils.c	5 Jun 2009 11:15:53 -0000	1.225
+++ Src/utils.c	26 Jun 2009 20:32:52 -0000
@@ -2490,9 +2490,8 @@
 		*buf++ = '0' + tm->tm_mday % 10;
 		break;
 	    case 'e':
-		strip = 1;
-		/* FALLTHROUGH */
 	    case 'f':
+		strip = strip || (fmt[-1] == 'f');
 		if (tm->tm_mday > 9)
 		    *buf++ = '0' + tm->tm_mday / 10;
 		else if (!strip)
@@ -2500,10 +2499,9 @@
 		*buf++ = '0' + tm->tm_mday % 10;
 		break;
 	    case 'K':
-		strip = 1;
-		/* FALLTHROUGH */
 	    case 'H':
 	    case 'k':
+		strip = strip || (fmt[-1] == 'K');
 		if (tm->tm_hour > 9)
 		    *buf++ = '0' + tm->tm_hour / 10;
 		else if (!strip) {
@@ -2515,9 +2513,8 @@
 		*buf++ = '0' + tm->tm_hour % 10;
 		break;
 	    case 'L':
-		strip = 1;
-		/* FALLTHROUGH */
 	    case 'l':
+		strip = strip || (fmt[-1] == 'L');
 		hr12 = tm->tm_hour % 12;
 		if (hr12 == 0)
 		    hr12 = 12;

Note: I didn't test either of those as I will not be able to build
until I update my autoconf.

Btw, are the zsh extension format specifiers documented?

thanks,
greg



Messages sorted by: Reverse Date, Date, Thread, Author