[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] time-fmt-escapes
From: |
isabella parakiss |
Subject: |
[PATCH] time-fmt-escapes |
Date: |
Tue, 17 Mar 2015 20:56:19 +0100 |
>From 2157400e3de983c358b580bb8cd22b337cd87eae Mon Sep 17 00:00:00 2001
From: izabera <izaberina@gmail.com>
Date: Tue, 17 Mar 2015 20:30:11 +0100
Subject: [PATCH] time-fmt-escapes
---
builtins/printf.def | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/builtins/printf.def b/builtins/printf.def
index 9b9d390..cc87aae 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -450,7 +450,22 @@ printf_builtin (list)
fmt++; /* skip over left paren */
for (t = timefmt, n = 1; *fmt; )
{
- if (*fmt == '(')
+ /* Allow backslash escapes in time formats */
+ if (*fmt == '\\')
+ {
+ fmt++;
+#if defined (HANDLE_MULTIBYTE)
+ memset (mbch, '\0', sizeof (mbch));
+ fmt += tescape (fmt, mbch, &mblen, (int *)NULL);
+ for (mbind = 0; mbind < mblen; mbind++)
+ *t++ = mbch[mbind];
+#else
+ fmt += tescape (fmt, &nextch, (int *)NULL, (int *)NULL);
+ *t++ = nextch;
+#endif
+ continue;
+ }
+ else if (*fmt == '(')
n++;
else if (*fmt == ')')
n--;
--
2.3.3
Currently it's not possible to print mismatched ( ) in printf "%(format)T".
This patch allows one to use octal and hex escapes.
$ printf "%(It's %H:%M here :\x29 and today is %A :\x29)T\n" -1
It's 20:53 here :) and today is Tuesday :)
I hope it's ok.
---
xoxo iza
- [PATCH] time-fmt-escapes,
isabella parakiss <=